Convert image to PDF + OCR from command line

Discussion for the End User use of OCR in PDF-XChange Editor and Viewer

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

margian
User
Posts: 26
Joined: Thu Feb 20, 2025 3:13 am

Convert image to PDF + OCR from command line

Post by margian »

Hello, there.
I need to take and archive long screenshots from webpages in .png or .jpg (or other image) formats, convert them to .pdf and overlay OCR so that I can search their content if needed.
Is this possible from the command line so that I can script a .bat/.ps1 file for mass background conversion?
Alternatives?
Thanks, Folks.
User avatar
Sean - PDF-XChange
Site Admin
Posts: 1489
Joined: Wed Sep 14, 2016 5:42 pm

Re: Convert image to PDF + OCR from command line

Post by Sean - PDF-XChange »

Hi margian,

Yes, this is possible using PDF-Tools, which enables you to combine multiple actions into a single custom tool and subsequently run that tool from the command line.

You could for example create a custom tool that contains the following sequence of actions:

Choose Input Files
Create PDF from Images
OCR Pages
Save Documents

You can then configure the settings for each action as desired, including the OCR output type and the location in which the resulting documents are saved. Further information on creating custom tools is available here:

https://help.pdf-xchange.com/pdfxp11/create-tool_t.html

When you have created your custom tool, right-click it and select 'Copy Tool Identifier'. You can then use the /RunTool command to run the tool from the command line, specifying the tool identifier and the folder containing your images. Further information on the available command line options is available here:

https://help.pdf-xchange.com/pdfxt9/com ... ons_t.html

Alternatively, you could use the Folder Monitor feature of PDF-Tools to automate this process whenever new images are added to a specified folder, avoiding the need to create a script.

Kind regards,
Sean Godley
Technical Writer
PDF-XChange Co LTD
Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623
margian
User
Posts: 26
Joined: Thu Feb 20, 2025 3:13 am

Re: Convert image to PDF + OCR from command line

Post by margian »

Thanks, it looks like it's working, however, despite I set the same image compression/conversion parameters between PDF-Tools vs. opening the .png image directly into PDF-XChange the converted image directly opened by PDF-XChange contains no compression artifacts while the PDF-Tools has many apparent jpeg artifcats that make the final image blurry
image.png
image(1).png
image(2).png
image(3).png
You do not have the required permissions to view the files attached to this post.
User avatar
Sean - PDF-XChange
Site Admin
Posts: 1489
Joined: Wed Sep 14, 2016 5:42 pm

Re: Convert image to PDF + OCR from command line

Post by Sean - PDF-XChange »

Hi margian,

Could you please export your custom PDF-Tools tool and provide it to us, along with the original PNG image and the resulting PDF documents created in both PDF-Tools and PDF-XChange Editor? Please also try disabling the OCR Pages action temporarily to determine whether the compression artifacts are introduced during the initial image conversion or the subsequent OCR process. This will enable us to reproduce the issue and determine why there is a discrepancy in the output quality despite the use of identical compression settings.

Kind regards,
Sean Godley
Technical Writer
PDF-XChange Co LTD
Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623
margian
User
Posts: 26
Joined: Thu Feb 20, 2025 3:13 am

Re: Convert image to PDF + OCR from command line

Post by margian »

You can test the attached file; Looks like the default open for:
PDF-XChange with compression set to Auto uses ZIP
image.png
PDF-Tools with compression set to Auto uses JPEG, ZIP
image(1).png
I changed PDF-Tools manually to ZIP and artifacts disappeared.
You do not have the required permissions to view the files attached to this post.
margian
User
Posts: 26
Joined: Thu Feb 20, 2025 3:13 am

Re: Convert image to PDF + OCR from command line

Post by margian »

testimg1.zip
You do not have the required permissions to view the files attached to this post.
User avatar
Sean - PDF-XChange
Site Admin
Posts: 1489
Joined: Wed Sep 14, 2016 5:42 pm

Re: Convert image to PDF + OCR from command line

Post by Sean - PDF-XChange »

Hi margian,

Thanks for the file. Could you now please also export your custom PDF-Tools tool and provide it to us?

Please also try disabling the OCR Pages action temporarily to determine whether the compression artifacts are introduced during the initial image conversion or the subsequent OCR process.

Kind regards,
Sean Godley
Technical Writer
PDF-XChange Co LTD
Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623
margian
User
Posts: 26
Joined: Thu Feb 20, 2025 3:13 am

Re: Convert image to PDF + OCR from command line

Post by margian »

Yes, even disabling the OCR post-proc, if I set True Color Compression Enabled to Auto, it creates jpeg noise/artifacts (Same if I set it to JPEG/ZIP)
image.png
If I force it to ZIP it works as expected with no noise
PDF-Tools Exchange.zip
The export is attached.
You do not have the required permissions to view the files attached to this post.