You are viewing limited content. For full access, please sign in.

Question

Question

DocumentExporter PdfExportOptions Restrictions not having any effect with ExportPdf

asked on November 18, 2022 • Show version history

I'm using SDK with DocumentExporter to export a document as a pdf. I want to put restrictions on the exported pdf so that it can't be printed/edited/copied/etc but can still be read. Here's an excerpt of code that I'm using to try to achieve this:

if (BoundEntryInfo.EntryType == EntryType.Document) {
    DocumentInfo BoundDocumentInfo = (DocumentInfo)BoundEntryInfo;

    DocumentExporter dExp = new DocumentExporter();
    dExp.CompressionQuality = 10; // through experimentation, this seems like a good balance between quality and file size for the target documents
    dExp.BlackoutRedactions = true;
    
    var pdfExportOptions =
        PdfExportOptions.IncludeText |
        PdfExportOptions.RestrictCopying |
        PdfExportOptions.RestrictPrinting |
        PdfExportOptions.RestrictDegradedPrinting |
        PdfExportOptions.RestrictModifyContents |
        PdfExportOptions.RestrictDocumentAssembly |
        PdfExportOptions.RestrictFillIn |
        PdfExportOptions.RestrictModifyAnnotations;
    
    MemoryStream ms = new MemoryStream();
    dExp.ExportPdf(BoundDocumentInfo, BoundDocumentInfo.AllPages, pdfExportOptions, ms);
}

You can see I tried a "throw it all at the wall and see what sticks" approach to putting restrictions on the pdf, but none of them seem to do anything.

I noticed that DocumentExporter objects have an ExportEncryptedPdf method, which maybe all these restrictions work for...? I stopped exploring ExportEncryptedPdf though when I realized that the password is required to even read the pdf; It's got to be readable without a password but with no printing/copying/etc.

 

More Context: After exporting the pdf to the MemoryStream, it gets written into the request body of an HttpWebRequest object and posted to a web API to be published on our website. But I've also tried just exporting as a file on the workflow server's filesystem to check if that was making any difference on the how the restrictions are being applied and it's the same story there.

 

Thanks!

0 0

Answer

SELECTED ANSWER
replied on November 18, 2022

I had an idea that worked. Use ExportEncryptedPdf but make the password an empty string.

dExp.ExportEncryptedPdf(BoundDocumentInfo, BoundDocumentInfo.AllPages, pdfExportOptions, "", PdfEncryption.RC4_40Bit, ms);

All the restrictions get applied when it's encrypted but there's no prompt for a password — perfect!

1 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.