Corrupted PDF

Hi,

I am currently working for a client who has two Aspose (Aspose.Words and Aspose.PDF).

  • Aspose.Words is used to edit and convert Word documents to PDF.
  • Aspose.PDF is used to concatenate PDFs.

The first part works perfectly. I have a problem with the second part where the result is still a corrupted PDF file. The PDF opens in the browsers but not in Acrobat Reader (Error 14).

Here is my code :
MemoryStream finalDoc = new MemoryStream();
Aspose.Pdf.Document initPdf = new Aspose.Pdf.Document(firstPdf);
Aspose.Pdf.Document apprPdf = new Aspose.Pdf.Document(secondPdf);
initPdf.Pages.Add(apprPdf .Pages);
initPdf .Save(finalDoc);
return finalDoc;

PS: I only use memory stream.

Here is an example of a corrupted PDF : TESTforDEMOR100 (42).pdf (14.6 KB)

Thank you in advance.

@ppgaillet

We have tried to open your PDF document in Adobe Reader and it did not raise any error. However, it had only one page. We need some more information from your side in order to replicate the issue and address it accordingly.

Please try to save the edited/updated/modified Word file into PDF (at some local path) using Aspose.Words and share it with us. Also, share the other PDF file which you are merging with it. We will test the scenario in our environment and address it accordingly.

Please make sure that you are using the below code snippet in order to convert Word into PDF:

Aspose.Words.Document doc = new Aspose.Words.Document(dataDir + "input.docx");
doc.Save(dataDir + "output.pdf", Aspose.Words.SaveFormat.Pdf);

Hi,

Thanks for your response.
Here is the first PDF TESTforDEMOR1.pdf (14.2 KB)
Here is the second PDF TESTforDEMOR2.pdf (30.5 KB)

I have no problem opening these documents.
Here are the concatenated PDF TESTforDEMOFinal.pdf (44.3 KB)
I can’t open this last document using Acrobat Reader (Error 14). But i can open it using Chrome…

Here is the code i use to convert the Word to PDF :
MemoryStream newPages = new MemoryStream();
approvalsDocument.Save(newPages, SaveFormat.Pdf);

And finally here is the code i use to concatenate the two PDF:
Aspose.Pdf.Document initialPdf = new Aspose.Pdf.Document(document); //import pdf in aspose.pdf document
Aspose.Pdf.Document newPagesDoc = new Aspose.Pdf.Document(newPages); //import pdf in aspose.pdf document
initialPdf.Pages.Add(newPagesDoc.Pages);
initialPdf.Save(finalDoc);

I have to work with MemoryStream.

@ppgaillet

We tested the scenario in our environment and did not notice any issue in the concatenated documents.

merged.pdf (44.3 KB)

Please try setting the stream position to zero before loading it into Document():

newPages .Seek(0, SeekOrigin.Begin);

In case issue still persists, please share a sample application with us which is able to reproduce the error. We will again test the scenario in our environment and address it accordingly.

Hello,

I have found a solution to this problem. It was a problem with the size of the mediaboxes. Here is the code i used :

for (int i = 1; i <= initialPdf.Pages.Count; i++)
        {
            double urx = Math.Floor(initialPdf.Pages[i].MediaBox.URX);
            double ury = Math.Floor(initialPdf.Pages[i].MediaBox.URY);
            Aspose.Pdf.Rectangle newBoxx = new Aspose.Pdf.Rectangle(0, 0, urx, ury);
            initialPdf.Pages[i].MediaBox = newBoxx;
        }

However i have a new problem prevents me from opening my pdf in acrobat reader. It’s a font reading error.
Here is the first PDF : FirstPart.pdf (51.4 KB)
Here is the second : SecondPart.pdf (40.5 KB)
Here is my result : Result.pdf (91.5 KB)
This is the problem in Acrobat Reader : FontError.JPG (31.7 KB)
The textthat uses unfound font is not displayed…
The fonts are well present in NitroPdf : FontErrorNitro.JPG (31.5 KB)

I have no problem opening the file with Chrome…

I’ve tried everything… the checkbox “use local font in acrobat reader”, i have checked that the fonts are present on my computer, …

Do you have the same problem ?

Thank you in advance.

Hi,

All problems have been solved by upgrading to .net core 3.1.

@ppgaillet

It is good to know that all of your issues have been sorted out. Please keep using our API and feel free to let us know in case you face any issue.