81
General / Re: PDF Explorer Web Interface, API based, Client.
« Last post by RTT on November 15, 2021, 08:29:02 PM »Yes, still an active project.
from ctypes import c_int, WINFUNCTYPE, WinDLL
from ctypes.wintypes import HWND, HINSTANCE, LPSTR
def setup():
"""Set dll up to run."""
DLLNAME = 'C:/Program Files (x86)/PDF-ShellTools/PDFShellTools.dll'
dll = WinDLL(DLLNAME)
prototype = WINFUNCTYPE(None, HWND, HINSTANCE, LPSTR, c_int)
paramflags = ((1, 'hwnd', 0), (1, 'hinst', 0), (1, 'IpszCmdLine', ""),
(1, 'nCmdShow', 0))
return (dll, prototype, paramflags)
def make_function(pdfstname, dll, prototype, paramflags):
"""Make a function to run PdfShellTools action from python."""
return prototype((pdfstname, dll), paramflags)
def run_dll_function(function, param, file):
"""Run function in dll. Format param & file nicely elsewhere."""
dllinput = param + " " + file
function(IpszCmdLine=LPSTR(dllinput.encode('utf-8')))
dll, prototype, paramflags = setup()
set_metadata = make_function('SetMetadata', dll, prototype, paramflags)
pdfstparams = '"Metadata=Title=SomeTitle"'
pdfstfiles = 'afile.pdf'
run_dll_function(set_metadata, pdfstparams, pdfstfiles)
1. if I want to align the barcode right top it seems not positioned correctly. I have attached an example imageUncheck the "Fit to page" option. That option is accessible from the above design area toolbar, menu icon button. You seem to be using an older version, than the current 3.4, that has that option in the "Files" tab, stamp mode options group.
2. which is the unit measurement for the size of the barcode, width and height ? I use millimetersIt uses the points unit.
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?Can't help you with the python language, but it's the pdfshelltools.dll that exports the tool functions. These exports are the same used by the command line interface tool pdfshelltools.exe.
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?Don't know exactly why this is happening, but I'm going to make some changes to fix this issue in the next release.
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))