Q: How to attach files to PDFs generated with the PDF Report Writer

Hello all-

Using PLP 2024 on Windows Server 2019. For a current project, I've generated a PDF that is needed for auditing purposes, and QA is happy. (This is a validated Pipeline Pilot instance, and we're validating all the protocols that go on the instance.)

However, I have far more information available than can be easily or nicely written to a PDF and I've been able to add it to a multi-sheet Excel file using the Excel Writer. I know that the PDF specification allows for attachments of files to PDF documents - this has been used by many different applications over the years and Acrobat allows one to do so manually. A number of software libraries (\\\$\\\$\\\$) also support this capability, but I don't have the necessary licenses on hand to use those to create my own little hack solution.

Thus - my question to you - is there a way to attach a file to a PDF that is generated usign the standard reporting framework? We have the Documents and Text collection but it appears that doens't have this functionality either.

Is there a bare-metal way using the embedded PDF generation code (a Java library maybe?) to do this after the PDF has been created? (I'm not particularly skilled in Java, but more than happy to learn. More comfy with python and C#.)

Thanks!

Marty

 

Answers 2
MB
MB 2024-03-25 Best Answer

Hi @JH - thanks for the hint! 

After looking at the info for PdfTK, it looks like it was last updated about 10 years ago, and since it's a binary I probably wouldn't be able to get it on our infrastructure. :^(-

In looking around a bit more, I found a python package called pypdf that does exactly what is needed. Benefit - cross platform! I've attached a very prototype protocol that demonstrates the use of this package (tested on PLP 2023 and 2024). To the PLP product team on this forum - this is a useful potential add (PDF manipulation tools).

I started by installing the latest version of pypdf on the server using the "Install Python Packages Using Built-In Python" protocol, writing the libraries to public://installedPythonPackages. Then, ran the protocol with the PythonPath set to that location.

For those of you who are interested in packaging components with these libraries, I figured out that you'll need to take all the files in the installedPythonPackages folder and copy them to the directory location in the package that's associated with the package PythonPath. Then, you can use the package details (e.g. MyCompany/PdfManipulators) in the python on server component to load those libraries without needing to install them on each server which is convenient.

-Marty

comment imagecomment image
JH
JH 2024-03-21

I know that this is not quite what you asked, but when I did a project several years ago and needed to attach thousands of Excel (and other) files into thousands of PDFs, I used pdftk which is free.

It is a little confusing if you go to their site, because they have multiple versions - one is labeled Free, one is labeled Pro (clearly not free) and one is labeled Server, which one would assume at first glance is not free -- but it turns out that it is, unless you want to package and redistribute it. Even better, this is the one you want if you are looking for command line functionality. https://www.pdflabs.com/tools/pdftk-server/

 

When I did this, I installed pdftk server on the PP server, wrote both files, and used the "Run Command on Server" component (or whatever it's called) to do the attachment. 

I'm still curious if there's a way to do this using the native PP components, but if not this might get your job done.