Free Support Forum - aspose.com

Suggestion for using AutoFiller with Streams +

Hello,

I'm successfully using AutoFiller, setting the OutputStream to Response.OutputStream. That works great, however, now I'd like to combine DocumentPrivileges, but I can't quite get the combination to work. Do you have a suggestion on how I can get the following to work?

Specifically, the code seems to have trouble in working with the output stream. Obviously I'm trying to route the AutoFiller output to the Reponse.OutputStream.

Many thanks... Mike

// Reset the response headers and perform the merge

Response.Expires = 0;

Response.Buffer = true;

Response.ClearContent();

Response.AddHeader("content-disposition", "attachment; filename=" + tempFN);

Response.ContentType = "application/pdf";

autoFiller.OutputStream = Response.OutputStream;

autoFiller.ImportDataTable(workingTable);

autoFiller.Save();

// Enable security

if (pdfEncrypt)

{

DocumentPrivilege privilege = DocumentPrivilege.ForbidAll;

if (pdfAllowPrint)

privilege.AllowPrint = true;

if (pdfAllowCopy)

privilege.AllowCopy = true;

if (pdfAllowFill)

privilege.AllowFillIn = true;

PdfFileSecurity fileSecurity = new PdfFileSecurity(autoFiller.OutputStream, autoFiller.OutputStream);

fileSecurity.EncryptFile("abc", "abc", privilege, false);

}

Response.End();

Hi,

Please try the following:

// Reset the response headers and perform the merge

Response.Expires = 0;

Response.Buffer = true;

Response.ClearContent();

Response.AddHeader("content-disposition", "attachment; filename=" + tempFN);

Response.ContentType = "application/pdf";

MemoryStream temp = new MemoryStream();

autoFiller.OutputStream = temp;

autoFiller.ImportDataTable(workingTable);

autoFiller.Save();

temp.Seek(0, SeekOrigin.Begin);

// Enable security

if (pdfEncrypt)

{

DocumentPrivilege privilege = DocumentPrivilege.ForbidAll;

if (pdfAllowPrint)

privilege.AllowPrint = true;

if (pdfAllowCopy)

privilege.AllowCopy = true;

if (pdfAllowFill)

privilege.AllowFillIn = true;

PdfFileSecurity fileSecurity = new PdfFileSecurity(temp; Response.OutputStream);

fileSecurity.EncryptFile("abc", "abc", privilege, false);

}

Response.End();

Thanks.

Thank you, Adeel. That helped a lot.

I’ve started with the ideas you suggested and gone past that and it looks like I’m making progress. I’m now experiencing a problem with this code:

PdfFileSecurity fileSecurity = new PdfFileSecurity(temp, Response.OutputStream);
fileSecurity.EncryptFile(null, null, privilege, false);

I’m getting a “Bad Password!” error. I’ve tried setting the user and owner passwords to null, “”, or setting an explicit value and it errors every time. Suggestions on that?

I’ve just upgraded from 2.6.3.0 to 2.6.4.0 and that appears to have corrected the “Bad Password!” problem.

I’m very close to a solution now! The output PDF is encrypted and looks very good, however, even with “AllowCopy” set to false, the data that has been populated into fields can still be copied to the clipboard (at least by right-clicking and choosing Copy).

I’ve attached a sample. Even though the PDF is locked, if you right-click on the address data (“Boulder CO 80301”) , you’ll see that the data can be copied. Thankfully, the rest of the form cannot be copied to the clipboard. The funny thing is that the data in the name field (“Jason McGovern”) can’t be copied.

Am I missing a step to protect the data in some fields?

Anyway, this looks great and I’m very pleased with PDF.Kit!

Mike

Hi,

I have tested your pdf document with Adobe Reader 7.0 and wasn't able to copy any data, not even the "Boulder CO 80301".

Thanks.

Interesting. I’m using Acrobat 8.1.1 – perhaps there’s a difference between Acrobat 8 and 7.

Hi,

I have just checked with Adobe Reader 8 and was able to reproduce the problem. I will have to discuss this developers. This could take some time to sort out.

Thanks.

Hi,

I have tested the same function in acrobat 8, the same problem exists.So we now can not improve the function to support your problem. But i have found that if the attribute of text field was set "readonly", after encrypted, this field can not be copied. you can try the way that the attribute of all text fields are set "readonly" before being encrypted. In aspose.pdf.kit, FormEditor. SetFieldAttribute() can finished the task.you can try this method, if any question, please fell free to inform me.