LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically use Microsoft Print to PDF

Does anyone know if there's a way in LabVIEW to utilize the "Microsoft Print to PDF" printer in an automatic way?  I have XML files I want to print to PDF and I'd like to use the free Print to PDF printer in Windows 10, but I'd like to automatically specify the PDF path and also disable any user prompts.  

0 Kudos
Message 1 of 9
(8,144 Views)

How do you plan to print the XML file - with syntax highlighting or some sort of XSL transform, or just like a plain text file?

0 Kudos
Message 2 of 9
(8,078 Views)

The XML has an associated XSL.  

 

I plan on using IWebBrowser2 to display and print the file, like in the example from this post, though I would choose the DoNotPromptUser option:

https://forums.ni.com/t5/LabVIEW/Print-file-via-ActiveX-and-it-is-not-found-always/td-p/1667298?prof...

I have verified this code works with my files, and do not have any of the issues discussed in the post.

 

If I have Microsoft Print to PDF set as my default printer, is there a way to execute this print command, but without prompting the user for the PDF path?

 

I have a method to do this using Adobe Acrobat, but I thought there might be a way to save a little bit of money and use what's included with Windows.

0 Kudos
Message 3 of 9
(8,025 Views)

Hi pulidotech,

 

I know this is an old thread, but I've been working on the same thing and got the Microsoft to PDF printer working without a dialog box. Hopefully, this helps someone.

 

This is an example going from a MS Word document to PDF (but would work for any MS program). This is an edited copy of the Print Report VI that comes with the Report Generation Toolkit. The only edit you need to make is to add an 'Output File Name' to the ActiveX invoke node (and set the printer name to 'Microsoft Print to PDF'). 

 

 

Print MS.png

 

Message 4 of 9
(7,585 Views)

Just a bit further to my previous reply. An easier approach is to use the ActiveX invoke node 'ExportAsFixedFormat'. However, this gives a low-resolution PDF (not one I was happy with) hence why I started looking at the MS Print to PDF printer.

 

Annotation 2020-07-23 140504.png

0 Kudos
Message 5 of 9
(7,582 Views)

If you specify a different option for "OptimizeFor" then do you get a better quality file? I would imagine that optimizing for screen means any images are only 72dpi.

0 Kudos
Message 6 of 9
(7,546 Views)

I tried both optimize for screen and for print, but they both caused images to appear pixelated. The MS Print to PDF Printer is much better. 

0 Kudos
Message 7 of 9
(7,538 Views)

Thanks for the suggestion.  Does your method only work with Word documents?  I would prefer a much more generic solution that doesn't require a license for anything else.  As I said in the original post, my goal is to print XML reports.

0 Kudos
Message 8 of 9
(7,486 Views)

@pulidotech wrote:

Thanks for the suggestion.  Does your method only work with Word documents?  I would prefer a much more generic solution that doesn't require a license for anything else.  As I said in the original post, my goal is to print XML reports.


Your question got me thinking about Text Editors, some of which have free editions and have syntax highlighting for certain extensions (like .xml).  I opened Notepad++ (one such Text Editor), verified that it had XML highlighting, and that in its Printer Setup, you could choose "Print to Microsoft PDF".  I suspect that here are "hooks" built into Notepad++ (or similar editors) that you could exploit to get it to open and print your document for you ...

 

If you manage to figure out how to do this, it would be nice to "share it" back with the Community.

 

Bob Schor

0 Kudos
Message 9 of 9
(7,478 Views)