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.

Aspose.Words Version 19.6.0
Aspose.Pdf Version 19.6.0

I am experiencing the same issue. Below is a snippet of code. I am not able to provide the PDFs due to sensitive information. I have tried placing doc.Save() in multiple places but have gotten the same result. Most PDFs are blank in Adobe Reader and an online PDF checker confirms that they are not valid PDF files. They are able to open in the browser.

using (var doc = new Document())
{
	var documentImages = ;// This gets a list of .tiff images

	for (short pageNumber = 1; pageNumber <= documentImages.Count(); pageNumber++)
	{
		var documentImage = documentImages.ElementAt(pageNumber - 1);

		var imageStream = new MemoryStream(documentImage.Image);
		imageStreams.Add(imageStream);
		doc.Pages.Add();
		doc.Pages[doc.Pages.Count].AddImage(imageStream, new Rectangle(0, 0, 595, 913));
		doc.Pages[doc.Pages.Count].Flatten();
	}

	using (var docStream = new MemoryStream())
	{
		//var optimizeOptions = new OptimizationOptions();
		//optimizeOptions.ImageCompressionOptions.CompressImages = true;
		//optimizeOptions.ImageCompressionOptions.ImageQuality = 50;

		// Optimize PDF document using OptimizationOptions
		//doc.OptimizeResources(optimizeOptions);
		// Optimize for web
		//doc.Optimize();

		doc.Save(docStream);
		// Save doc stream
	}
}

@John9

It seems like you are generating PDFs from the scratch in your code snippet. Also, please try to use the latest versions of the APIs (Aspose.PDF for .NET 21.1 and Aspose.Words for .NET 21.1) and see if issue still persists. Please share your documents in a private message if you cannot share it publicly so that we can try to replicate the issue at our end and address it accordingly. You can send a private message by clicking over username and pressing the blue message button.

Here is file that I created with stock images.43875fc3-67f3-42a9-b407-df8c8eb786fb.pdf (6.7 MB)

@John9

We changed your code a bit so that we can test the scenario in our environment:

using (var doc = new Document())
            {
                var imagefiles = Directory.GetFiles(dataDir, "*.jpg");
                for (short pageNumber = 0; pageNumber < imagefiles.Count(); pageNumber++)
                {
                    var file = imagefiles[pageNumber];

                    var imageStream = new FileStream(file, FileMode.Open);
                    doc.Pages.Add();
                    doc.Pages[doc.Pages.Count].AddImage(imageStream, new Rectangle(0, 0, 595, 913));
                    doc.Pages[doc.Pages.Count].Flatten();
                }

                //using (var docStream = new MemoryStream())
                //{
                    //var optimizeOptions = new OptimizationOptions();
                    //optimizeOptions.ImageCompressionOptions.CompressImages = true;
                    //optimizeOptions.ImageCompressionOptions.ImageQuality = 50;

                    // Optimize PDF document using OptimizationOptions
                    //doc.OptimizeResources(optimizeOptions);
                    // Optimize for web
                    //doc.Optimize();

                    //doc.Save(docStream);
                    // Save doc stream
                    doc.Save(dataDir + "images.pdf");
                //}
            }

The above code produced a PDF document with images without any issue. We were able to open and view the images inside Adobe Reader. Could you please specify the steps to reproduce the same issue you are facing. Also, please note that we tested the scenario with Aspose.PDF for .NET 21.1.

@asad.ali
The only difference I see is that I am using .tif images. I am not able to use version 21.1 right now because it says the license doesn’t cover that as a free upgrade. If you can confirm that updating the library version will fix the issue then I can investigate doing that.

@John9

With the .tif images, we were still unable to notice any issue in 21.1. Also, you can evaluate the latest version of the API to see whether it is working fine at your end by using a 30-days free temporary license. You can please let us know in case you face any issue with it.

It is not letting me get a trial license. This is the error I receive:
image.png (24.8 KB)

I went to the link and tried to update everything in my profile. At first it wouldn’t let me update the company because it said it didn’t have my last name. I updated my last name then went and updated the company information. Added everything back to the cart and I am still getting that error. Can you provide me with a temporary license to try?

@John9

Please create a topic in our Purchase forum category with the detail of problem you are facing while applying for a temporary license. You will surely be assisted there accordingly.

I got the trial license resolved and tested the new version of the library. This has fixed my issue. Is there any information you can provide on what was updated to resolve this?

@John9

Regretfully, we will not be in a position to share requested information because, the issues are logged and investigated on the basis of latest available version of the API. We do not provide any kind of support if issue is not occurring in the latest version of the API. Also, the issues reported for older versions of the API are resolved in the latest/newer version. Please feel free to let us know if you have further inquiry.