Add a password to PDF files generated by Phantomjs - pdf

I've got some server-side node.js code that generates PDF files on request, using phantomJS, and I'm looking for a way to add password protection to the output.
Sadly I haven't found any mention of such an option in phantom, which makes sense because Chrome doesn't provide that either. Alternately I could run some other tool that would take the PDF created by phantom and add password protection to it, but I can't seem to find any that can do exactly that (add a password to an existing file) and that's completely free to use (preferably, non-GPL).
Will be happy for suggestions on how to approach this task. Thanks!

You can use the node-qpdf package to encrypt and decrypt PDFs. It makes use of qpdf. So first you need to convert HTML -> PDF then PDF -> Password Protected PDF.

Related

any PDF plugin for cakePHP?

I need to implement in a page/view of a form an option to generate a PDF file; looking for information I have seen that cakepdf exists, but there is hardly any information on how to implement/install it and it seems to be outdated.
Are there other options compatible with CakePHP?
Best option to use is https://wkhtmltopdf.org/ via https://github.com/mikehaertl/phpwkhtmltopdf ... we use this to generate PDF documents in our CakePHP solution.

TCPDF SetProtection method is not working as expected

I started writing here:
PHP PDF password protection (no open without password)
But I can't add comments due to my reputation here (I'm better on AskUbuntu but I can't take my rep points from there). I also started a bounty there, and if someone will answer here in two days with an acceptable solution, I will award there.
Now, the problem: SetProtection method is not working as expected.
Wanted behaviour: create a protected/encrypted PDF document with TCPDF library so that the document view is always granted to everyone without asking any password, but if one tries to edit, a password is requested.
I use the following syntax:
$pdf->SetProtection(array('modify', 'copy', 'annot-forms', 'fill-forms', 'extract', 'assemble'), null, 'mypwd', 1);
I can open the file with a pdf viewer as expected.
If I try to open the file with Libreoffice Draw, the password is requested (as expected), but I'm able to edit the document BOTH with mypwd (expected) AND giving a blank password (NOT expected).
What is the right syntax, if any, to have pdf readable by everyone BUT editable ONLY with "mypwd" provided?
EDIT:
here you are with a file with a blank user password and a strong master password. Ilovepdf.com finds it UNLOCKED, Libreoffice Draw can edit it.
This is NOT the expected behaviour.
https://www.dropbox.com/s/864p8xjh1ue041z/tracking_12750_16.pdf?dl=0
As far as I can see your example PDF is encrypted just the way you wanted, with an empty user password and a non-empty owner password. Thus, TCPDF does just what it was asked to do.
Most likely the problem is that your expectation is too strong: If a program can open a PDF for reading, that program can do anything with the PDF, no matter how restricted it is configured to be. The permissions and different owner and user roles require the cooperation of the software in question, they are not technically enforced.
This already is clear from the specification:
Once the document has been opened and decrypted successfully, a PDF reader technically has access to the entire contents of the document. There is nothing inherent in PDF encryption that enforces the document permissions specified in the encryption dictionary. PDF readers shall respect the intent of the document creator by restricting user access to an encrypted PDF file according to the permissions contained in the file.
(ISO 32000-2, section 7.6.4 Standard security handler)
Apparently Libreoffice Draw simply does not behave as required by the PDF specification, i.e. it is not properly restricting user access to an encrypted PDF file according to the permissions contained in the file. Probably by design, probably just a programming glitch.
You should simply be aware that your expectation to
create a protected/encrypted PDF document with TCPDF library so that the document view is always granted to everyone without asking any password, but if one tries to edit, a password is requested.
cannot be implemented using standard PDF encryption facilities for arbitrary PDF processors, merely for those that follow the PDF specification requirement quoted above.
There are some providers of PDF DRM software solutions which are not so easy to circumvent, but I doubt any of them can withstand a determined hacker. (Unless the solution in question is not giving the PDF to the user at all but only images in a custom, webservice-based viewer; but this is not your use case.)
Depending on your actual requirements, you might want to investigate into using digital signatures instead of encryption; if your objective is to make sure that any recipient can be sure that he got your document contents and not what someone else edited into it, this appears more apropos.

Windward Document Generation - PDF Copy Protected

In our application, we generate a few reports and documents through Windward. The documents are generated based on specific user conditions and the user is able to download the document.
As part of a new requirement, we would like to enable copy protection of the generated PDF -- basically, users would not be able to Copy the contents of the document.
Is there anyway we can achieve this through Windward? Or do we have to integrate with external third party software like LockLizard or Win2PDF?
We did think of converting the document to an image and recreating the PDF but this is unacceptable as the document formatting became off the mark.
Appreciate any insights or alternate solutions.
Thanks,
Aravind
Windward does this. If you're using the Java engine use the following calls (javadoc):
ProcessPdfAPI.setOwnerPassword()
ProcessPdfAPI.setUserPassword()
For the .NET engine use the following calls (api docs):
ReportPdf.OwnerPassword
ReportPdf.Security
ReportPdf.UserPassword
Is this what you need?

Is there a public website that converts swagger json to PDF for HTML?

Has anyone made where, where you just enter your swagger URL .../swagger/docs/v1
and then the website converts it to HTML, pdf, doc or whatever in a nice readable format? I'd think that site would get a lot of traffic (hint)
I know there are some things on github you can download that will convert things, but I'd think someone has made a public site so I can save some time.
You can use this website : Swagger Editor
Copy your swagger file and in the menu, select 'Generate Client' -> 'HTML' (or Dynamic HTML')
You can also use Swagger Code Generator if you want to add this step in an automatic build flow.
Try this one: swagger2html .
The document generated by swagger-codegen is indeed not readable. This project makes a neat appearance(bootstrap css) and shows the fields in the request/response models in a straightforward manner.

iPDF-poppler passworded document

Note: I am not sure if this is better here, or at superuser, but since it concerns the poppler library, I would assume here, because people here are more likely to know how it works.
Software: iPDF 2.12 + Poppler 2.11 (Last commit 2006-12-12) for Irex Iliad. Sources are here.
Problem Documents: Sciam digital PDFs (any of them, since all are produced the same way).
The document will load fine using Okular, Adobe Reader, and XPDF without requesting any passwords, and can be read without problem.
Loading using iPDF - so poppler - requests a password to open the document.
I have tried bypassing the SecurityHandler:checkEncryption method in Poppler/SecurityHandler.cc, by making it return true. This works, but fails to load the pdf with errors:
Error: Unsupported version/revision (4/4) of Standard security handler
Error (13571568): Unknown compression method in flate stream
Error: Top-level pages object is wrong type (null)
Error: Couldn't read page catalog
(PV_E)PDFCore.cpp:61,open() Open PDF document (èÖ#(èÖ#à failed with error code 2
(PV_E)PDFApp.cpp:185,open() Could not open file!
This suggests that the actual stream is encrypted, which - if true - suggests that okular is somehow bypassing this.
I am aware of people having similar problems on other mobile devices (I found a similar report with a Nexus One).
I do not know enough about how the pdf format works to know whether there is some 'default' password that should be used instead to open (no other permissions needed) the document. Is there?
Is it a case that it is requesting the owner password, when it only needs to use the user password (blank?) to open it?
Else, does anyone know how something like Okular/XPDF would be able to open it without problem?
This turned out to be an issue with the version of poppler being used by the application being too old for the required security handler.
As such, I have started my own project to create a new pdf viewer for my iliad based on the latest (0.14.*) version of poppler which can handle it. Sources here.