[Solved] PDF encryption

The Amyuni PDF Converter is our Printer Driver that enables you to convert any documents to PDF format. If you have any questions about installing and using the Amyuni PDF Converter please post them here.
Post Reply
lp
Posts: 66
Joined: Mon Dec 12 2005
Location: Italy

[Solved] PDF encryption

Post by lp »

We are currently using the professional version of the PDF Converter driver, invoking it through the DLL interface.
When using version 2.50f we are able to encrypt PDFs as soon as we print them: we call EncryptPDFDocument128 and the output PDF gets protected with passwords or restricted from some possible use.
Yesterday we were testing our application using version 3.02 (the last one available in your site) and discovered we weren't able to encrypt the resulting PDFs anymore.
Version 3.01a works too, only 3.02 doesn't.
Are there known problems with it or am I missing something?

I've also tried using the SetPermissions, SetUserPassword and SetOwnerPassword functions instead of EncryptPDFDocument128 with the same outcome...
By the way, what's the difference between using the EncryptPDFDocument128 function compared to the sequence of SetXxxx functions?
I'm calling them before printing, after enabling the printer and also after calling SetLicenseKeyA...

Any clue is welcome :)
Please let me know if you need more details...
Thank you in advance,
Luke
lp
Posts: 66
Joined: Mon Dec 12 2005
Location: Italy

Re: PDF encryption

Post by lp »

PS: i also found a clue that v.3.02 doesn't work well with PDF encryption in this other post, which reads:
We are using PDF Converter 3.00, not 3.02. I tried 3.02, but that seems to have problems encrypting PDFs using the EncryptPDFDocument() method, so I abandoned that.
..which is exactly what I'm facing now :)
However I guess [s]he probably didn't find a way to solve this... Well, at least I'm not alone :wink: :)
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Re: PDF encryption

Post by Joan »

Hello Luke,

Are you running your application on 64-bits machine.

We have some problems in version 3.02 with some post processing functions on 64-bits systems. We are currently checking them.
Custom Brand the Amyuni PDF Printer Driver http://www.amyuni.com/en/developer/branding/index.html

Amyuni PDF Converter tested for true PDF performance. View results - http://www.amyuni.com/benchmark
lp
Posts: 66
Joined: Mon Dec 12 2005
Location: Italy

Re: PDF encryption

Post by lp »

Hello Joanna,

Thank you for the reply!
No, I tried this only on the 32bit Vista machine I'm working with.... didn't try on a 64bit machine yet.

PS: I have UAC enabled, if that matters..
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Re: PDF encryption

Post by Joan »

Hello,

EncryptPDFDocument() should work properly on Vista 32-bits. You need to make sure that the PDF file is completely generated before trying to open it and encrypt it.

Also please make sure that you are calling SetDefaultConfig after calling the EncryptPDFDocument() or EncryptPDFDocument128()

UAC shouldn't have any effect here but you may want to try turning it off.

If you wish to use the SetPermission, SetUserPassword, ect... you need to add Encrypt PDF Document option to FileNameOptions.

Hope this helps
Custom Brand the Amyuni PDF Printer Driver http://www.amyuni.com/en/developer/branding/index.html

Amyuni PDF Converter tested for true PDF performance. View results - http://www.amyuni.com/benchmark
lp
Posts: 66
Joined: Mon Dec 12 2005
Location: Italy

Re: PDF encryption

Post by lp »

So let me undestand...
From what I read, I have two choices:

One:
1. create the PDF (or take an already existing one)
2. call SetLicenseKeyA, then EncryptPDFDocument() or EncryptPDFDocument128(), and then SetDefaultConfig()

this one is doing some kind of post-processing on the PDF, so I'll have to make sure my PDF can be modified...
(how can I be sure it's safe to encrypt it if I'm creating it with the PDF Converter driver itself? is there a suggested way?)

Two:
1. Call EnablePrinter, then SetPermission, SetUserPassword, etc...
2. Call FileNameOptions including the appropriate flag for Encrypting PDF Document.
3. Start printing to the PDF

this one, on the other side, is encrypting it "on the fly"

Is that correct?

I'll try to stick to the second approach and let you know if that works..
Thank you in advance!

Luke
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Re: PDF encryption

Post by Joan »

Hello,

It is almost this with some modifications:



Option One: (Post-processing)
1. create the PDF (or take an already existing one)
2. open the PDF file using the Open or OpenEx commends.
3. call SetLicenseKeyA
4. call EncryptPDFDocument() or EncryptPDFDocument128() (no need for SetDefault Config here).

You have to make sure that the PDF is fully generated before opening it. Nothing else to check.

Option two: (On the Fly)
1. Call FileNameOptions including the appropriate flag for Encrypting PDF Document.
2. Call SetPermissions(), SetUserName(),...
3. Call SetDefaultConfig()
4. EnablePrinter()
5. Start printing to the PDF

Hope this helps.
Custom Brand the Amyuni PDF Printer Driver http://www.amyuni.com/en/developer/branding/index.html

Amyuni PDF Converter tested for true PDF performance. View results - http://www.amyuni.com/benchmark
lp
Posts: 66
Joined: Mon Dec 12 2005
Location: Italy

Re: PDF encryption

Post by lp »

Thank you Joanna!

I followed you checklist and had it working at last :D
I chose the second option ("on the fly") since I think it's more appropriate for the usage pattern we have.
My problem probably was that I was trying to post-process the resulting PDF when it wasn't ready, so switching to this way of encrypting the output should also prove faster, since I don't have to wait for it to be ready 8)

I already tried this approach in the past, but what I didn't understand at time was that SetDefaultConfig() is required to "apply" the changes I did to the configuration... Yes, last time I didn't call that function, that's why it wouldn't work.

Hope this can be useful to others too :wink:

Have a nice day!

PS: I really like the new "look" of the forums :D
lp
Posts: 66
Joined: Mon Dec 12 2005
Location: Italy

Re: PDF encryption

Post by lp »

Another question:
does EnablePrinter() have to be invoked exactly in that order?
I'm currently calling it right after printer initialization and it seems to work: do you see any problem with this?

Thank you again :)
Luke
Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Re: PDF encryption

Post by Joan »

Hello,

I am glad you like the new look in the forum. Actually this is the default look of phpBB version 3. We just customize the design a little bit.

Concerning EnablePrinter(), if you have the developer version of the PDF Converter EnablePrinter() will enable the printer for a limited time. If you starting printing while the printer is still enabled printing works, if you start printing when the printer is disabled, printing will generate an error.

If your code is working as is, it is ok. If you start getting errors on the print command please remember that you need to call EnablePrinter() right before printing.

Hope this helps.
Custom Brand the Amyuni PDF Printer Driver http://www.amyuni.com/en/developer/branding/index.html

Amyuni PDF Converter tested for true PDF performance. View results - http://www.amyuni.com/benchmark
lp
Posts: 66
Joined: Mon Dec 12 2005
Location: Italy

Re: PDF encryption

Post by lp »

Perfect :)

In our code the printer is enabled right before printing, so there are no significant delays between EnablePrinter() and effective printing: just the time it takes to apply those settings we were talking about earlier in this thread :)

Thank you!
Luke
Post Reply