I'm trying to give my users the option of password protecting the PDFs they create via PDFLib. I've read the documentation regarding PLOP, and came across the following paragraph in appendix A of the the manual (located here):
Memory-Based Combination The memory-based method is faster, but requires more memory. It is recommended for dynamic PDF generation and signature in Web applications unless you deal with very large documents. Instead of generating a PDF file on disk with PDFlib, use in-core PDF generation by supplying an empty file name to
PDF_begin_document( )
, fetch the contents of the buffer containing the generated PDF data usingPDF_get_buffer( )
, and create a virtual file withPLOP_create_pvf( )
. The file name used for the virtual file can then be passed to PLOP/PLOP DS usingPLOP_open_document( )
without having to create a physical file on disk. Note that it is not possible to fetch the PDFlib buffer contents in multiple portions since the full document must be supplied to PLOP/PLOP DS in a single buffer. Therefore you must callPDF_get_buffer( )
betweenPDF_end_document( )
andPDF_delete( )
. The hellosign programming sample, which is included in all PLOP packages, demonstrates how to use PDFlib for dynamically creating a PDF document and passing it to PLOP in memory for applying a digital signature.
So far I have the following method written, to be called prior to PDF_end_document()
, as the manual instructs:
function encrypt_pdf($pdf_buffer, $password) {
$optlist = '';
$filename = "temp";
create_pvf($filename, $pdf_buffer, $optlist);
$optlist = "masterpassword=$password";
open_document($filename, $optlist);
$doc = create_file($filename, $optlist);
}
I have no idea how to proceed from here. There is no documentation that I've found that even remotely covers what I'm trying to do (even though I imagine this is a common usage of the PLOP API).
How can I complete this method, and password protect my output PDF?