Free Support Forum - aspose.com

Error for Encrypted File - Invalid pdf format:pdf head signature is not found

Hi

When I tried for Building form of already encrypted file it throws error

The code is following

1st Take 1 method which will return me InputStream

PdfFileSecurity sec = new PdfFileSecurity(pdfInputStream, pdfOutputStream);

asposeResponse = sec.DecryptFile(permissionPassword);

pdfInputStream.Close();

return pdfOutputStream;

Than used that stream to make form using,

Form pdfForm = new Form(pdfFileStream, pdfOutputFileStream);

Here it throws error "Invalid pdf format:pdf head signature is not found"

Please Help me out

Thanks

Hi,

Please call the statement pdfFileStream.Seak(0, SeekOrigin.Begin) before passing it to the Form constructor.

Thanks.

Thanks, Its working ,

Can you please describe me why we have to use this method

Thanks

Hi,

It is because the DecryptFile method doesn't reset the stream pointer to the begining and when Form class tries to read from the same stream it is already at the end and thinks that the file is corrupt.

Thanks.