One PDF capability that still hasn't been introduced as a native feature in PowerBuilder is the ability to merge PDF files. We're going to look at how we can easily add that capability using the open source (LGPL) PoDoFo library.
If you look at the list of runtime files for PowerBuilder, you'll note that a podofo.dll file is included in the most recent versions as needed when the OEM TX Text Control is used. Initially just the 32 bit version in 2019 R2 and more recently both the 32 and 64 bit versions in 2019 R3. Given that (as far as I know) the version of the TX Text Control didn't change between the initial 2019 release and R2, I'm not sure why it wasn't listed in the initial 2019 release docs, but that might have been a documentation error. That file is (as I write this) the 0.9.6.0 version of the PoDoFo library. That means we can create another DLL that does a dynamic import on that library that PowerBuilder is including as a runtime and add the merge capability.
The VS 2019 code and PowerBuilder 2019 R3 code sample are available here.
The C++ source code for the DLL is written in VS2019. There is a package manager utility for Visual Studio C++ projects called vcpkg. I used that to pull down the PoDoFo libraries and all the libraries it is dependent on. They are not included in the attached sample code, so you will need to do the same on your system if you want to modify the C++ source code. There is a walkthrough of how to use vcpkg which uses SQLite as an example. You just need to do steps 1 and 2 and do it for podofo instead. Since I'm supporting 32 and 64 bit I did the install of the library (and dependencies) for both platforms using the :<target> option.
The PowerBuilder 2019R3 sample code includes both 32 and 64 bit examples. Note that it appears that TX Text Control ships a debug version of the podofo.dll, so you need to use the debug version of the pdfutils.dll to work with it. Note also that you can't used one of the files you're reading as the output because the library reads the files in as it works via a stream. Therefore output of the merge needs to be a separate file than the source files.
PoDoFo has a lot more capability than just merge. There's some examples in the tools folder of the PoDoFo project. The C++ code I've provided is based on the podofomerge tool in that project. The pdfutils library can certainly be expanded to include other capability (hence naming it utils rather than just merge). At the moment though merge is all I needed. If you have additional PDF functionality not included in native PowerBuilder that you'd like to see added let me know through a comment below.
[05/17/2021 Update]: Discovered that there is a bug in PoDoFo loading landscape PDFs. I've updated the sample to include a SnapDevelop project that is a C# wrapper around SharpPDF that is then imported into PowerBuilder. The SnapDevelop approach works fine with both landscape and portrait files. The PoDoFO based sample only works with portrait files.
[09/10/2021 Update]: It appears there isn't a bug in PoDoFo. PoDoFo is dependent on a number of other DLLs, and I had assumed that those were included in the PowerBuilder runtime as PoDoFo was included. They aren't. As soon as I included the other DLLs that PoDoFo is dependent on it started working correctly. Also, I've updated the sample to PowerBuilder 2021.
Comments (26)
Your account does not have privileges to view attachments in the comment
Your account does not have privileges to view attachments in the comment