Free Support Forum - aspose.com

Unable to open modified PDFs in Adobe Reader

I’ve been working with modifying a PDF document with Aspose.pdf and I am able to save it properly with Response headers, but I’m having an issue with opening the saved PDF in Adobe Reader. I can open and view the modified PDF in programs like Windows Reader and Google Chrome, but if I try to open it with Adobe Reader then this message appears with a blank document:

Issue.PNG (6.6 KB)

In my code, all I do is fill in some form fields of a previously existing PDF file. The original PDF can be opened without a problem in Adobe Reader; it is only after I save it that it malfunctions.

Here is my code for saving the PDF:

private void SendPdfToSave(Aspose.Pdf.Document finishedPdf)
{
MemoryStream ms = new MemoryStream();
finishedPdf.Save(ms);
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.Charset = “UTF-8”;
Response.AddHeader(“content-length”, ms.Length.ToString());
Response.AddHeader(“content-disposition”, "attachment; filename= " +
“FinishedSample.pdf”);
Response.ContentType = “application/pdf”;
Response.BinaryWrite(ms.ToArray());
Response.End();
}

I am using Aspose.PDF for .NET 18.7 and Adobe Reader XI.
Any feedback on this would be great.

@wahehsoe

Thank you for contacting support.

Would you please mention if you are facing this problem with every PDF file you are working with or if this is file specific behavior. Kindly create a narrowed down web application that includes modification of PDF file and then saving it, along with source and generated PDF files so that we may try to reproduce and investigate it in our environment.

@Farhan.Raza

Sorry for late response.

I’ve tested my code on different PDF files, and on a few of them this issue does not appear. However, it does on the majority of them. Here is a sample PDF I found where this issue occurs after editing with Aspose.pdf (Source and Generated):

(Source):
interactiveform_enabled.pdf (89.0 KB)

(Generated):
SampleAfterEdits.pdf (103.5 KB)

Next, here is some code to show how I’m accessing and editing the PDF file:

Aspose.Pdf.Document thePdf = new Aspose.Pdf.Document(@"…/SampleBeforeEdits.pdf");
CheckboxField testfield = thePdf.Form[“HIGH SCHOOL DIPLOMA”] as CheckboxField;
testfield.Checked = true;
SendPdfToSave(thePdf); //this method is shown above in my first post

Now when I go to open the generated PDF in Adobe Reader, it still shows the IssueMessage I posted earlier. However, the checkbox I modified in my code was successfully checked. So the code works but is conflicting with something in Adobe Reader I guess. Nonetheless, this is still an issue I would like to find an answer for.

Thanks and regards,

@wahehsoe

We have worked with the data shared by you and have figured out that extended features are lost when Aspose.PDF API makes changes to source PDF file. However, you can preserve extended rights by saving incremental update of the PDF file. Please try using below code snippet in your environment and then share your kind feedback with us.

        FileStream fs = new FileStream(dataDir + "interactiveform_enabled_wahehsoe - Copy.pdf", FileMode.Open, FileAccess.ReadWrite);
        Aspose.Pdf.Document thePdf = new Aspose.Pdf.Document(fs);
        CheckboxField testfield = thePdf.Form["HIGH SCHOOL DIPLOMA"] as CheckboxField;
        testfield.Checked = true;
        //using Save() method without parameters allows incremental update
        thePdf.Save();
        SendPdfToSave(thePdf);

Please note that extended features are not supported by any browser, therefore they do not prompt any error message when the PDF file is opened with a browser. Moreover, we have attached generated PDF file for your kind reference interactiveform_enabled_18.7.pdf. Please feel free to contact us if you need any further assistance.