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)