Free Support Forum - aspose.com

PdfFileStamp.Save() fails if PDF is linearized and have password

Save PDF with password and watermarks PdfFileStamp.Save fails with message "Object reference not set to an instance of an object." and callStack:

at . ()
at ..ctor( )
at ​ ..ctor( , Int32 , Int32 , )
at .( , Int32 , Int32 , )
at .(​ )
at ..ctor(​ )
at .(​ )
at .()
at . ( , )
at . ()
at . (Stream )
at . (Stream )
at Aspose.Pdf.Document.Save(Stream output)
at Aspose.Pdf.Facades.SaveableFacade.Save(Stream destStream)
at Aspose.Pdf.Facades.PdfFileStamp.Save(Stream destStream)

Only if I set password and PDF file has linearized (Fast Web View in Adobe Reader).
If I edited PDF file and save without linearized PdfFileStamp.Close correct and exception did not fail.
File for example in attachment.

Hi Igor,


Thanks for contacting support.

I have tested the scenario using latest release of Aspose.Pdf for .NET 11.5.0 in Visual Studio 2015 running over Windows 10 (x64) and I am unable to notice any issue when using following code snippet. Can you please try using the latest release and in case the issue still persists, please share your sample code, so that we can further look into this matter. We are sorry for this inconvenience.

[C#]

//open
document
<o:p></o:p>

Aspose.Pdf.Facades.PdfFileStamp fileStamp = new Aspose.Pdf.Facades.PdfFileStamp();

fileStamp.BindPdf("c:/pdftest/PDF32000_2008.pdf");

//create stamp

Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();

stamp.BindLogo(new Aspose.Pdf.Facades.FormattedText("Hello World!", System.Drawing.Color.Blue, System.Drawing.Color.Gray, Aspose.Pdf.Facades.FontStyle.Helvetica, Aspose.Pdf.Facades.EncodingType.Winansi, true, 14));

stamp.SetOrigin(200, 200);

stamp.Rotation = 90.0F;

stamp.IsBackground = true;

//add stamp to PDF file

fileStamp.AddStamp(stamp);

//save updated PDF file

fileStamp.Save("c:/pdftest/PDF32000_2008_Stampped.pdf");

Hi,

I tried in 10.2 and 11.5 version Aspose.Pdf. I created semple project ConsoleApplicationPDF and add in attachment.

Hi Igor,


Thanks for sharing the sample project.

I have tested the scenario and have managed to reproduce same problem. For the sake of correction, I have logged it as PDFNEWNET-40642 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

Hi,

Ok. Could you tell us how long would it take to fix this? approximately, week, month …

Hi Igor,


Thanks for your patience.

As we recently have noticed earlier reported issue, so its pending for review and is not yet resolved. However the product team will surely consider investigating/fixing it as per development schedule and as soon as we have some definite updates regarding its resolution, we will let you know. Please be patient and spare us little time. We are sorry for this delay and inconvenience.

Hi,


Unfortunately, the issue is very critical for our clients :frowning:

If we set
pdfStamp.Document.IsLinearized = false;
it works.

Could you please confirm that the fix is correct and we can apply it for us?

Thanks.

Hi Igor,


Thanks for your patience.

The issue reported earlier is pending for review and is not yet resolved. However if above stated workaround resolves your problems, you may consider using it. Meanwhile I have also shared your findings with product team and they will surely consider them during the resolution of this problem.

Hi,


Any news about this issue?
How can i check status of PDFNEWNET-40642 ?

Thanks.

Hi Igor,


Thanks for your patience.

I am afraid the earlier reported issue is not yet resolved and is pending for review. However I have intimated the product team to try accommodating it in their development schedule and as soon as we have some further updates, we will let you know.

We are sorry for this delay and inconvenience.

Hi Igor,


Thanks for your patience.

We have further investigated earlier reported issue and as per our observations, your shared code snippet works fine without pdfStamp.Close call (this call is redundant, but I will also investigate why exception is raised). Although it is strange why PdfStamp is used here because no stamps were added.

[C#]

using (PdfFileInfo fileInfo
= new PdfFileInfo())<o:p></o:p>

{

{

PdfFileStamp pdfStamp = new PdfFileStamp();

try

{

pdfStamp.BindPdf(@"c:/pdftest/PDF32000_2008.pdf");

pdfStamp.Save(@"c:/pdftest/PDF32000_2008_FileStamped.pdf"); // failed

}

finally

{

//pdfStamp.Close();

}

using (PdfFileSecurity sec = new PdfFileSecurity())

{

sec.BindPdf(@"c:/pdftest/PDF32000_2008_FileStamped.pdf");

DocumentPrivilege documentPrivilege = DocumentPrivilege.ForbidAll;

documentPrivilege.AllowScreenReaders = true;

documentPrivilege.AllowPrint = true;

documentPrivilege.PrintAllowLevel = 2;

sec.EncryptFile("password", Guid.NewGuid().ToString(), documentPrivilege, KeySize.x128);

sec.Save(@"c:/pdftest/PDF32000_2008_FileStamped_Secured.pdf");

}

// return securedStream;

}

}