Incorrect file header while downloading some of the PDF documents

Dear Team,

Currently we are facing issue with Incorrect File header exception while downloading a PDF file. Actually while downloading a pdf file , we bind a watermark to all the files in the pdf.
Please provide your suggestions on how to fix this and achieve this.

Thanks & regards,
Chaitanya Kumar

@chaitunc

Could you please share a bit more details of the issue while sharing a sample code snippet through which we can try to replicate the issue at our end. We will test the scenario in our environment and address it accordingly.

Hi Team,

Please find the code snippet for the Issue , we are facing while downloading few of the pdf files.

The issue is aspose.pdf.invalidpdffileformatexception: ‘incorrect file header’ .

Take an example of saving a word document as pdf and test it for the scenario.

image001.gif (7.74 KB)

image003.jpg (181 Bytes)

(Attachment Code Snippet is missing)

This file is missing in the previous mail. Please check.

image001.gif (7.74 KB)

Code Snippet.zip (843 Bytes)

@chaitunc

We tested the scenario in our environment by converting a Word file to PDF using Aspose.Words and adding stamp to the generated PDF file using same code snippet that you shared and saved it. We did not face any issue. Furthermore, the exception that you are facing is caused when a document is invalid PDF file or it was not saved correctly (with correct save options or format).

We request you provide a sample console or web application which is able to reproduce the same issue that you are facing. We will run it at our end and try to replicate the issue. We will share our feedback with you then accordingly.

Hi Ali and team,

How we can check whether the pdf file is incorrect format? Do we have any method to check before downloading it.

Please find the attached pdf which is giving the mentioned error while downloading with the same code snippet.

Could you look into it and feedback on the same?

image001.gif (7.74 KB)

image003.jpg (181 Bytes)

Sample 1.pdf (12 KB)

@chaitunc

You can check whether a PDF is a valid or corrupted document using the below method:

bool IsCorrupt(string path)
{
try
{
Document doc = new Document(path)
}
catch(Exception ex)
{
return true;
}
return false;
}

Furthermore, we have checked your document and noticed that it was corrupted. Adobe Reader was also unable to open it. It seems like your issue is more related to the part where you are converting a word document into PDF in your application. Could you please share how you are converting a .docx to PDF so that we can further proceed to assist you accordingly.

Hi Ali,

The issue is with the given code snippet, I get the Incorrect file header issue. How can we solve this?

Some of the pdfs are uploaded in one of the client site, so those give this error while downloading.

Do we have any solution for this ?

image001.gif (7.74 KB)

image003.jpg (181 Bytes)

image003.jpg (164 Bytes)

@chaitunc

The code snippet seems fine and should produce the correct results as we shared earlier after testing it. The issue can be related to specific PDF document or the code part where you are downloading the files. Please share some more details like sample PDF files along with code snippet to download them that you are using. We will again test the scenario in our environment and address it accordingly.