Blank PDF document after merging

We are using aspose.PDF 11.5 and have a license. The first PDF document produces a blank page yet when the license is removed, the evaluation correctly displays the page. Here is the code:



Imports Aspose.Pdf

Imports System.IO



Public Class test

Inherits System.Web.UI.Page



Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim pdf_memoryStream As New MemoryStream

Dim ms As New IO.MemoryStream

Dim pdf_byteArray As Byte()



’ commenting out the license will produce the first pdf page as an evaluation page but it’s missing when there’s a license

Dim license As New Aspose.Pdf.License

license.SetLicense(“Aspose.Pdf.lic”)



pdf_memoryStream = GenerateDocument(“THIS IS THE FIRST PDF PAGE”)



ms = GenerateDocument(“THIS IS THE SECOND PDF PAGE”)

pdf_memoryStream = ConcatenatePdf(pdf_memoryStream, ms)



ms = GenerateDocument(“THIS IS THE THIRD PDF PAGE”)

pdf_memoryStream = ConcatenatePdf(pdf_memoryStream, ms)



pdf_byteArray = pdf_memoryStream.ToArray()



Response.ClearContent()

Response.ClearHeaders()

Response.ContentType = “application/pdf”

Response.OutputStream.Write(pdf_byteArray, 0, pdf_byteArray.Length)

Response.End()

End Sub



Public Shared Function ConcatenatePdf(ByVal firstMemoryStream As Stream, secondMemoryStream As Stream) As MemoryStream

Dim pdfMainDocument As New Document(firstMemoryStream)

Dim pdfDocument As New Document(secondMemoryStream)

Dim ms As New MemoryStream()



pdfMainDocument.Pages.Add(pdfDocument.Pages)

pdfMainDocument.Save(ms)

Return ms

End Function



Public Shared Function GenerateDocument(ByVal message As String) As MemoryStream

Dim pdf As Aspose.Pdf.Generator.Pdf = New Aspose.Pdf.Generator.Pdf()

Dim ms As New MemoryStream

Dim sec1 As Aspose.Pdf.Generator.Section = pdf.Sections.Add()



sec1.Paragraphs.Add(New Aspose.Pdf.Generator.Text(message))

pdf.Save(ms)

Return ms

End Function





End Class

Hi Pearl,


Thanks for using our API’s.

I have tested the scenario and as per my observations, first PDF file is being generated where first page is blank and second page contains THIS IS THE SECOND PDF PAGE but I am afraid I am getting an error InvalidPdfFileFormatException when further PDF file generation attempt is performed. Can you please share your sample project, so that we can again test the scenario in our environment. We are sorry for this inconvenience.

Thanks for replying. I am using VS 2012 on Windows 7 and have enclosed the zip file containing the entire project.

Hi Pearl,


Thanks for sharing your source project. We have tested the scenario and noticed you are using old generator(Aspose.Pdf.Generator). Please use new generator (Aspose.Pdf) for document generation, it will resolve the issue.

Furthermore please note it is recommended to use new generator, it can create a new PDF document from scratch and manipulate existing PDF document as well. New generator is more efficient and improve and please note Old generator will be obsolete in near future.

Public Shared Function GenerateDocument(ByVal message As String) As MemoryStream

Dim pdf As Aspose.Pdf.Document = New Aspose.Pdf.Document()

Dim ms As New MemoryStream

Dim sec1 As Aspose.Pdf.Page = pdf.Pages.Add()

sec1.Paragraphs.Add(New Aspose.Pdf.Text.TextFragment(message))

pdf.Save(ms)

Return ms

End Function


Please feel free to contact us for any further assistance.

Best Regards,