What's the best way to generate a print-protected PDF?

I need to generate PDF files from DOC, DOCX, XLS, XLSX, ODT, ODS so the user can’t print the PDF file, setting the IsPrintingAllowed property to false. I’m using the following code:

Workbook xls = new Workbook();
xls.Open(pFileName);
or
Document doc = new Document(pFileName);
pTmpFileName = pTmpFileName.Remove(pTmpFileName.IndexOf(pExt));
doc.Save(pTmpFileName +
“.xml”, Aspose.Words.SaveFormat.Pdf);
Pdf pdfFile = new Pdf();
pdfFile.BindXML(pTmpFileName +
“.xml”, null);
pdfFile.SetUnicode();
pdfFile.IsImagesInXmlDeleteNeeded =
true;
pdfFile.Security =
new Security();
pdfFile.Security.IsPrintingAllowed =
false;
pdfFile.Security.IsDegradedPrintingAllowed =
false;
pdfFile.Security.IsCopyingAllowed =
false;
pdfFile.Security.IsContentsModifyingAllowed =
false;
pdffile.Save
(pTmpFileName + “.pdf”);
I wonder if that’s the best way to do that.

Hi there,

Thanks for your inquiry.

You can use Aspose.Words to convert DOC, DOCX and ODT files to PDF. You can also directly restrict printing permissions using Aspose.Words as well, please see the following link for details: http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.saving.pdfpermissions.html

Regarding the other formats, my colleagues will answer you shortly. If you have any further queries, please feel free to ask.

Thanks,

Hi,

I am from Aspose.Cells team.

You can also use Aspose.Cells for .NET to directly convert XLS, XLSX and ODS etc. files to PDF and can also directly restrict printing permissions or secure PDF files using its API as well, please see the following link for details:

http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/secure-pdf-documents.html

Thank you.