PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

MigraDoc Multipage PDF
http://forum.pdfsharp.com/viewtopic.php?f=2&t=3853
Page 1 of 1

Author:  Anu [ Thu Oct 04, 2018 12:02 pm ]
Post subject:  MigraDoc Multipage PDF

Hello,
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:

Code:
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
                    pdfRenderer.RenderDocument()
           
            End If
        Next

        Dim filename As String = "C:\HelloWorld.pdf"
        Me.PdfView.UnloadDocument()
        pdfRenderer.PdfDocument.Save(filename)
        ' ...and start a viewer.
        Process.Start(filename)

        Me.PdfView.LoadDocument(filename)

Author:  () => true [ Thu Oct 04, 2018 12:16 pm ]
Post subject:  Re: MigraDoc Multipage PDF

Hi!

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.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/