I'm taking a stab at writing a python wrapper for PDF-ShellTools, and I'm wondering if anyone else at the forum has any experience with this. Specifically, I'm running PDFShellTools.exe with the subprocess package. This will suffice to let me work out the logic of what I'm trying to build, though I'd love to hear if anyone has used the dll from python. Heck, which dll?
First things first, I've hit a snag trying to capture the help message. When I don't capture the output, the full message is displayed in the Windows command line terminal. However, trying to capture the output to stdout only gets the first three lines (version, copyright, and link). Where did the rest go? How do I get that too?
Here's a MWE:
import subprocess
class PdfTool(object):
"""Base class for PDF-ShellTools function classes."""
def __init__(self, functionname=None, rundll=False):
"""Initialize class."""
self.functionname = functionname
self.rundll = rundll
self.exename = 'PdfShellTools'
self.params = []
self.runsettings = {}
def _run_dll(self):
"""Run tool via dll."""
pass
def _run_exe(self, captureoutput=False):
"""Run tool via command line exe."""
toolargs = [self.exename, ]
if self.functionname is not None:
toolargs.append(self.functionname)
cp = subprocess.run(toolargs, capture_output=captureoutput)
return cp
def run(self, captureoutput=False):
"""Run the tool in the preferred way."""
if self.rundll:
processdict = self._run_dll()
else:
processdict = self._run_exe(captureoutput=captureoutput)
return processdict
def pdf_shelltools_help(captureoutput=False):
"""Return top-level PDF-ShellTools help."""
return PdfTool().run(captureoutput=captureoutput)
print('###############################################################')
print('Output not captured')
print(pdf_shelltools_help())
print('\n\n')
print('###############################################################')
print('Output captured\n\n')
print(pdf_shelltools_help(captureoutput=True))