Readout Security Information

Hi,

I try to read out the security-informations of pdf-files (using the latest version of Aspose.pdf.dll).

mStream = ReadFile2Stream(sFileName);

mStream.Position = 0;

Aspose.Pdf.Generator.Pdf pdfObj = new Aspose.Pdf.Generator.Pdf(mStream);

bool bOk = pdfObj.Security.IsCopyingAllowed;

...

private MemoryStream ReadFile2Stream(string sInFile)

{

FileStream inStream = File.OpenRead(sInFile);

MemoryStream ms = new MemoryStream();

ms.SetLength(inStream.Length);

inStream.Read(ms.GetBuffer(), 0, (int)inStream.Length);

ms.Flush();

inStream.Close();

return ms;

}

the pdfObj.Security is NULL.

Could you please advice, what is wrong in my coding?

Thank you.

best regards,

Oliver

Hi Oliver,

Thank you for the sample code. I tried using your code to test your issue but unable to replicate the scenario at my end. Please share template PDF document with us. This will help us to figure out the issue and reply back to you soon.

We apologize for your inconvenience.

Thanks & Regards,

Hi,

here is a pdf-file to replicate the scenario.
thanks for your support.

Best regards,
Oliver

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

Thank you for sharing the template file.

Actually, the issue is with your code and that needs to be modified a bit to get the correct results. Please see the following update code segment (check the bold line).

mStream = ReadFile2Stream(sFileName);

mStream.Position = 0;

Aspose.Pdf.Generator.Pdf pdfObj = new Aspose.Pdf.Generator.Pdf(mStream);

pdfObj.Security = new Aspose.Pdf.Generator.Security();

bool bOk = pdfObj.Security.IsCopyingAllowed;

Please do let us know if you still face any issue.

Thank You & Best Regards,

Hi,

thanks for your quick response. I still don’t get the expected results. Please check the provided pdf.
Here nothing is allowed. But using
pdfObj.Security = new
Aspose.Pdf.Generator.Security();
I get a security-object with all flags set to true (=allowed).
It looks to me, as I instanciate a new security-object with default-values, but not an object with the values from the opend pdf-file.
Could you please check?

Thanks.
best regards,
Oliver

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

Well, to get the security information for an existing document, please use Aspose.Pdf.Facades. PdfFileInfo.GetDocumentPrivilege(). Please use the below code as per your requirement:

mStream = ReadFile2Stream(sFileName);

mStream.Position = 0;

PdfFileInfo pdf = new PdfFileInfo(mStream);

DocumentPrivilege priv = pdf.GetDocumentPrivilege();

bool b0k = priv.AllowCopy;

Thank You & Best Regards,

Thank you very much,

that's the way it works fine now!

Best regards,

Oliver