PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Jan 26, 2021 4:51 am

All times are UTC

Forum rules

Please read this before posting on this forum: Forum Rules

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: MigraDoc Multipage PDF
PostPosted: Thu Oct 04, 2018 12:02 pm 

Joined: Thu Oct 04, 2018 6:24 am
Posts: 1
How do I generate a multipage PDF using MigraDoc.
I come to a point where I get a single page PDF but not multipage.
Please find my code below:

Dim dtSQLImage As New DataTable
        Dim imagedt
        Dim imageData() As Byte

        Dim unicode = PdfFontEncoding.Unicode
        Dim embedding = PdfFontEncoding.Automatic

        Dim clsFrmain As New ClsFrmMainLoad

        dtSQLImage = DgFinanceImg.DataSource
        Dim pdfRenderer As PdfDocumentRenderer = New PdfDocumentRenderer(unicode, embedding)
        For j = 0 To dtSQLImage.Rows.Count - 1
            If j = DirectCast(sender, Telerik.WinControls.UI.RadGridView).CurrentRow.Index Then
                imageData = (dtSQLImage.Rows(j)(0))


                    imageFilename = MigraDocFilenameFromByteArray(imageData)
                    document = New MigraDoc.DocumentObjectModel.Document
                    Dim pageSetup As MigraDoc.DocumentObjectModel.PageSetup = document.DefaultPageSetup.Clone
                    ' set orientation
                    pageSetup.Orientation = MigraDoc.DocumentObjectModel.Orientation.Landscape
                    Dim section As MigraDoc.DocumentObjectModel.Section = document.AddSection

                    Dim image = section.AddImage(imageFilename)

                    '  Image.Top = ShapePosition.Top
                    ' Image.Left = ShapePosition.Left
                    ' Image.WrapFormat.Style = WrapStyle.TopBottom
                    With section
                        .PageSetup.PageHeight = image.Height  ' ImageHeight
                        .PageSetup.PageWidth = image.Width
                        .PageSetup.TopMargin = 0
                        .PageSetup.LeftMargin = 0
                        .PageSetup.BottomMargin = 0
                        .PageSetup.RightMargin = 0
                        ' .AddImage(imageFilename)
                    End With
                    ' Associate the MigraDoc document with a renderer

                    pdfRenderer.Document = document
                    ' Layout and render document to PDF
            End If

        Dim filename As String = "C:\HelloWorld.pdf"
        ' ...and start a viewer.


Reply with quote  
PostPosted: Thu Oct 04, 2018 12:16 pm 
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 323

Maybe it would help to create the document once before the loop.
You create a new document for each row, overwriting the document created for the previous row. Finally you save a PDF that only contains the data for the last row, all previous rows get lost.

Please do not ask questions in the Sample Code forum.

Ă–hmesh Volta ("() => true")
PDFsharp Team Holiday Substitute

Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 9 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group