We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

PdfFileSecurity constructor with Document

Hi,

We are trying to migrate from PDF.Kit and I am trying to use the PdfFileSecurity constructor that takes an Aspose.Pdf.Document object, rather than a stream. The constructor call creates an object successfully, but once I call SetPrivilege(), an System.ApplicationException is thrown - “Pdf document has not been provided yet or it was closed after changing document security properties.”. This does not occur when I create the PdfFileSecurity object with the stream (the same stream used to create the Document).

Also, how much more efficient is it to pass in a Document object to the various PDF objects (PdfFileSecurity, PdfExtractor, etc…), rather than using the original stream? This implementation detail can make a relatively big difference and change how I (the caller) code.

Thanks,
Daniel

Hi Daniel,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I tested the SetPrivilege method with DocumentPrivilage options and it works fine. Please share your template file and sample code with us to help us re-generate the issue. Following is the sample code I used to test with Aspose.Pdf for .NET v6.5.

string inFile = "E:\\AP Data\\input.pdf";

string outFile = "E:\\AP Data\\output.pdf";

PdfFileSecurity fileSecurity = new PdfFileSecurity(inFile, outFile);

fileSecurity.SetPrivilege("abc", "def", DocumentPrivilege.Print);

Thank You & Best Regards,

Hi,

Thanks for the quick reply. I believe there is a misunderstanding here. I am saying that instanciating PdfFileSecurity with a Aspose.Pdf.Document object (not a file path or stream) causes SetPriviledge() to fail.

Here’s an example:



string file = @“C:\test\input_pdf\cantprint.pdf”;
Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(file, “”);
PdfExtractor pdfExtractor = new Aspose.Pdf.Facades.PdfExtractor(pdfDoc);
PdfFileInfo pdfInfo = new Aspose.Pdf.Facades.PdfFileInfo(pdfDoc);
DocumentPrivilege priv = pdfInfo.GetDocumentPrivilege();
PdfConverter pdfConv = new Aspose.Pdf.Facades.PdfConverter(pdfDoc);
priv.AllowPrint = true;
MemoryStream streamOut = new MemoryStream();
PdfFileSecurity fs = new Aspose.Pdf.Facades.PdfFileSecurity(pdfDoc, streamOut);//causes SetPriviledge to throw
//PdfFileSecurity fs = new Aspose.Pdf.Facades.PdfFileSecurity(file, streamOut);//doesn’t throw - is ok
fs.SetPrivilege(priv);

Hi Daniel,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the sample code.

I am able to reproduce your mentioned issue and it has been register into our issue tracking system with issue id: PDFNEWNET-32931 for rectification. We will notify you regarding any updates against your issue via this forum thread.

Sorry for the inconvenience,

The issues you have found earlier (filed as PDFNEWNET-32931) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.