Protecting PDF results in protected but empty pdf

Hi,

I'm new to the pdf component and struggle a little with protecting an existing pdf (saved from aspose.words) The pdf does contains text after saved by aspose.words. However after opening the stream in Aspose.Pdf and protecting it the doc is nicely protected but completly empty. The size of the pdf file is 1 Kb larger that before executing the protection code.

Any help is appriciated,
Ron

FileStream stream = new FileStream(pdfName, FileMode.Create);
doc.Save(stream, SaveFormat.Pdf);
Aspose.Pdf.Pdf pdf1 = new Aspose.Pdf.Pdf(stream);
Aspose.Pdf.Security sec = new Aspose.Pdf.Security();
if (password != "")
{
sec.UserPassword = password;
}
sec.IsAnnotationsModifyingAllowed = bPa;//PA
sec.IsContentsModifyingAllowed = bPmd;//PMD
sec.IsCopyingAllowed = bPec;//PEC
sec.IsDegradedPrintingAllowed = bPfqp;//PFQP
sec.IsDocumentAssemblyingAllowed = bPad;//PAD
sec.IsFormFillingAllowed = bPff;//PFF
sec.IsPrintingAllowed = bPp;//PP

pdf1.Security = sec;
if (SaveAsPDFA == "Y")
{
pdf1.Conformance = Aspose.Pdf.PdfConformance.PdfA1B;
}
pdf1.Close();

Hello Ron,

Thanks for considering Aspose.

Aspose.Pdf is a component which is used to generate PDF documents from scratch. As per your requirement, there are two methods to accomplish your requirement.

1) Try the conventional method of Word document to PDF conversion using Aspose.Words and Aspose.Pdf. During the conversion process you can specify the security constraints. But this method of Word to PDF conversion is not recommended and is obsolete.

[C#]

Document doc = new Document(@"D:\pdftest\This+is+a+test123.doc");
doc.Save(@"D:\pdftest\test.xml", SaveFormat.AsposePdf);

// New a pdf object
Aspose.Pdf.Pdf pdf11 = new Aspose.Pdf.Pdf();
// Bind content from the named xml file.
pdf11.BindXML(@"D:\pdftest\test.xml", null);

Aspose.Pdf.Security sec = new Aspose.Pdf.Security();
pdf11.Security = sec;
sec.IsAnnotationsModifyingAllowed = true;// bPa;//PA
sec.IsContentsModifyingAllowed = bPmd;//PMD
sec.IsCopyingAllowed = false;// bPec;//PEC
sec.IsDegradedPrintingAllowed = bPfqp;//PFQP
sec.IsDocumentAssemblyingAllowed = bPad;//PAD
sec.IsFormFillingAllowed = bPff;//PFF
sec.IsPrintingAllowed = bPp;//PP

pdf11.Save(@"D:\pdftest\Test_conventional11.pdf");

2) If you are converting the Word document directly into PDF format using Aspose.Words, then please try using Aspose.Pdf.Kit to apply security constraints over the document. Aspose.Pdf.Kit is a component which is used to edit/manipulate any existing PDF documents. For more information on how to apply security constraints over existing PDF documents, please visit Implementing Security

I got it all working using Aspose.Pdf.Kit.

Thanks for guiding me in the right direction.
Ron

Hello Support,

I am struck in something similiar situation.
I was making use of some other tool that supported security.
Now I have switched to Aspose for creating PDF documents for my application.

I am currently experiencing problems for implementing security for the generated PDF document.
I am currently using


Hi,


Thanks for using our products.

Can you please share some sample PDF files and the code snippet which you are using so that we can test the scenario at our end. We are sorry for this inconvenience.