Jump to content

Print WordPad file to PDF


 Share

Recommended Posts

Hello everyone,

New to Autoit, but at first glance looks really powerful and something I would like to learn extensively.

But, currently I am looking to do a specific task, and could use some help since I am so new to this.

I have an existing .odt file (Open Document Text) that I want WordPad to open and print the file to a PDF, using Microsoft Print to PDF Printer, and save the file to a location with a specific name.  And all doing this in the background or hidden.

I am not sure if it is necessary to open WordPad to do this function, but if not than excellent.  I will just not have access to MSWord on the computer running this, so WordPad is necessary.

Thank you in advance!

Link to comment
Share on other sites

Welcome to AutoIt and the forum!

Is Open Office/Libre Office installed on the computer?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

You could simply use

Global $sFileToPrint = "C:\tmp\test.odt"
ShellExecute("write.exe", "/p " & $sFileToPrint)

This will send the file to the default printer.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Is there anyway to set the filename of the new PDF being printed?

I am trying to get it to where the operator doesn't have to type anything in, where it will automate the generation of a PDF, and save it to a location, all in the background.

Link to comment
Share on other sites

I have a program written in VBA, and I have run into a problem on this last step.

In VBA I am able to print to the default printer, but I cannot find a way to set the new file name without a dialog coming up.  A friend of mine showed me AutoIt, saying I could create an executable that would print a wordpad file to a PDF, set the new PDF name, and save it to a location.

Link to comment
Share on other sites

A PDF printer is nothing but a printer driver that creates the PDF output file and writes it to disk. So you need to find a way to rename the created PDF file after it has been created.
Can you post an example of the filname that is created by Microsoft Print to PDF Printer? Is it somehow related to the input filename?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

you can use AutoIt script to automate the entire process: call WordPad and initiate the printing routine (as demonstrated 4 posts above), wait for the file name dialog to appear and fill-in the file name. however, although this is fully automatic, it is visible to the user, and prone to user interference.

your reluctance to install additional software is understood, however have you considered the portable version of OpenOffice/LibreOffice? it does not require installation, and has full command line capabilities for background conversion.

for a more advanced coder than myself, i'd suggest review this link - there is a code sample using the printer object to preset the output file name.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...