Recent Posts

Pages: 1 ... 4 5 [6] 7 8 ... 10
51
General / Re: Using dll with python
« Last post by ekopta on October 28, 2021, 01:03:10 AM »
I should have mentioned that the dll only works with 32-bit Python installations.  :-[
52
General / Using dll with python
« Last post by ekopta on October 28, 2021, 12:59:26 AM »
I've found the way to use PdfShellTools.dll with python, and here's the basic recipe. This doesn't format the text input to all the particular specifications PdhShellTools requires; it's just about getting it to the dll.

Code: [Select]
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)

My guess is that you only want to do the setup part once to realize the full speed gain. It's probably good to minimize the calls to make_function as well. I haven't looked into performance concerns yet.
53
General / Re: barcode import list
« Last post by RTT on October 03, 2021, 02:00:48 PM »
1. if I want to align the barcode right top it seems not positioned correctly. I have attached an example image
Uncheck 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.
Quote
2. which is the unit measurement for the size of the barcode, width and height ? I use millimeters
It uses the points unit.
1 inch = 72 points
1 inch = 25.4 mm
1 point = 0.352777778 mm

So, to convert the value in mm, divide it by 0.352777778 and type the result in the tool.
54
General / Re: barcode import list
« Last post by Nick Riviera on October 01, 2021, 08:50:38 AM »
Hi,

I have some questions..
The barcodes are generated very quickly but,

1. if I want to align the barcode right top it seems not positioned correctly. I have attached an example image
2. which is the unit measurement for the size of the barcode, width and height ? I use millimeters
Thank you



55
General / Re: Using with python - truncated help
« Last post by RTT on August 26, 2021, 08:33:38 PM »
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.
The exported functions use the same prototype as the functions that can be run by the rundll32.exe Windows tool. It is explained in the user's guide DLL interface topic.
Take note you must use a 32-bit version of Python, to use the DLL interface, as the pdfshelltools.dll is 32-bit.

Quote
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.

The help data is in a xml file, embedded as a resource in the PDFShellTools.exe, that for sure you can extract and process using python.
You can use a tool such as the Resource Hacker to check the PDFShellTools.exe resources.
56
General / Using with python - truncated help
« Last post by ekopta on August 25, 2021, 06:18:20 PM »
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:
Code: (python) [Select]
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))


57
Ideas/Suggestions / Re: Extract/Split File Into Two Files
« Last post by nightslayer23 on August 13, 2021, 01:24:58 AM »
 :o oops. that was easy! Seriously, this is the best PDF software ever invented.
58
Ideas/Suggestions / Re: Extract/Split File Into Two Files
« Last post by RTT on August 12, 2021, 03:59:50 PM »
Use a semicolon character to specify multiple split operations.

1-270;3241-3374
59
Ideas/Suggestions / Extract/Split File Into Two Files
« Last post by nightslayer23 on August 12, 2021, 02:08:01 PM »
The extract / split allows you to only split files out into one file... what about if you want to split a file out into multiple files?

File 1 [pages: 1-270]
File 2 [pages: 3241-3374]

Pages would always vary..
60
General / Re: trim + bleed size
« Last post by RTT on July 13, 2021, 05:46:27 AM »
As with the Displaying PDF Page Size in Windows Explorer example, use the manager to create the 3 custom properties, named ArtSize, TrimSize and BleedSize.
Import and run the attached script to calculate and fill these properties, before they can show in the respective Windows File Explorer columns.
Code: [Select]
var ProgressBar = pdfe.ProgressBar;
ProgressBar.max = pdfe.SelectedFiles.Count;

for (var i = 0; i < pdfe.SelectedFiles.Count; i++) {
    ProgressBar.position = i + 1;
    var file = pdfe.SelectedFiles(i);
    var Page = file.Pages(0);
    var TrimSize = '';
    var BleedSize = '';
    var ArtSize = '';
    if (Page) {
        var TrimBox = Page.TrimBox ? Page.TrimBox : Page.CropBox ? Page.CropBox : Page.MediaBox;
        var BleedBox = Page.BleedBox ? Page.BleedBox : Page.CropBox ? Page.CropBox : Page.MediaBox;
        var ArtBox = Page.ArtBox ? Page.ArtBox : Page.CropBox ? Page.CropBox : Page.MediaBox;

        if (Page.Rotation == 90 || Page.Rotation == 270) {
            TrimSize = GetDist_mm(TrimBox.top, TrimBox.bottom).toFixed() + 'x' + GetDist_mm(TrimBox.left, TrimBox.right).toFixed() + ' mm';
            ArtSize = GetDist_mm(ArtBox.top, ArtBox.bottom).toFixed() + 'x' + GetDist_mm(ArtBox.left, ArtBox.right).toFixed() + ' mm';
        } else {
            TrimSize = GetDist_mm(TrimBox.left, TrimBox.right).toFixed() + 'x' + GetDist_mm(TrimBox.top, TrimBox.bottom).toFixed() + ' mm';
            ArtSize = GetDist_mm(ArtBox.left, ArtBox.right).toFixed() + 'x' + GetDist_mm(ArtBox.top, ArtBox.bottom).toFixed() + ' mm';
        }

        var BleedSize = GetDist_mm(BleedBox.top, TrimBox.top).toFixed() + ' mm';

        var FileMetadata = file.Metadata;
        var Changed = false;
        if (FileMetadata.TrimSize !== TrimSize) {
            FileMetadata.TrimSize = TrimSize;
            Changed = true;
        }

        if (FileMetadata.ArtSize !== ArtSize) {
            FileMetadata.ArtSize = ArtSize;
            Changed = true;
        }

        if (FileMetadata.BleedSize !== BleedSize) {
            FileMetadata.BleedSize = BleedSize;
            Changed = true;
        }

        if (Changed) {
            if (FileMetadata.CommitChanges()) {
                pdfe.echo(file.Filename + ' : (ArtSize=' + ArtSize + ', TrimSize=' + TrimSize + ', BleedSize=' + BleedSize + ') [OK]');

            } else {
                pdfe.echo(file.Filename + ' [commit failed]', 0xFF0000);
            }
        } else {
            pdfe.echo(file.Filename + ' : (ArtSize=' + ArtSize + ', TrimSize=' + TrimSize + ', BleedSize=' + BleedSize + ') [properties already set]');
        }
    }
}
pdfe.echo("Done");

function GetDist_mm(x1, x2) {
    return Math.abs(x1 - x2) * 25.4 / 72
}
Pages: 1 ... 4 5 [6] 7 8 ... 10