Generate PDF document

RIAS used Ask the Experts™

I am using desktop app.
The requirement is to create PDF document from memorystream (system.bytes) data extracted from SQL Server. We have a table which saves images in bytes in sql datatabase.
I need to create PDF document from the memorystream.
I have tried PDFsharp , it does give me one page PDF but struggling to get multipage from it.
I am open to any software suitable.
The code I used with PDF sharp is this :
 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))

                For i = 0 To 2

                    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.


Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Example of multiple pages document is e.g. here:

Other options also exist.
Are you able to send the requested document to a printer?  If yes then you may use any PDF printer driver which supports paging obviously.

You may try e.g. BullZIP:
Ashutosh VyasIndividual Contributor, Software Architect

I have been using iTextSharp (
Its quite intuitive to use and also has good community support around it.
Hmm... It can be acceptable for your personal testing but AGPL license and terms on the product site seem to be rather unfriendly and restrictive with unknown pricing.



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial