LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert PNG to PDF (Microsoft Print to PDF)

Good Day Folks!

 

I'd like to:

 

1. contribute the following VIs (hope it's helpful) and

2. ask if you see anything wrong with it? (I was trying to set the page sizes but seemed to always go back to Letter...not a big deal in my case as I, actually, wanted Letter!)

3. so, mainly if I'm doing anything wrong if you have a suggestion

 

It's using .NET to convert a PNG file to PDF using Windows built-in "Microsoft Print to PDF" printer.

PrintDocument and Graphics classes...

https://learn.microsoft.com/en-us/dotnet/api/system.drawing.printing.printdocument

https://learn.microsoft.com/en-us/dotnet/api/system.drawing.graphics

 

printPNGtoMicrosoftPDF.png

 

printPageEventHandler.png

 

 

Cheers!

0 Kudos
Message 1 of 8
(2,110 Views)

Hi T999,

 

thanks for sharing your work!

Would you mind to also attach a downconverted version of those VIs, for LV2021 or LV2019?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 8
(2,077 Views)

You don't close the reference to the image that comes from "FromFile".

 

You don't need to wait to close the references to the end. You can close the reference as soon as it's not used anymore. For instance, PrintDocument (it's reference!) can be closed after PrinterName. There's no need to sync with the error wire, error in is ignored anyway. This reduces a lot of the long wires... 

 

There's Get File Extension.vi that also gives you the name without the extension:

wiebeCARYA_0-1683705083954.png

 

Message 3 of 8
(2,074 Views)

Hi GerdW,

 

The VIs are, already, saved to LabVIEW 2018... Sorry for the confusion 😛

 

Hi Wiebe,

 

Thank you for the helpful suggestions.  Without that 10 ms wait and calling the dispose method would cause an error for me 80% of the time ...

0 Kudos
Message 4 of 8
(2,038 Views)

Thanks for your contribution!

Would you mind posting it to Example Programs - NI Community?

-------------------------------------------------------
Control Lead | Intelline Inc
Message 5 of 8
(2,004 Views)

here it is updated per the suggestions...i'll try to post it to the examples program, too...
vi files are 2018 and snippets 2023.

printPNGtoMicrosoftPDF.png

printPageEventHandler.png

Message 6 of 8
(1,963 Views)

@T999 wrote:

Thank you for the helpful suggestions.  Without that 10 ms wait and calling the dispose method would cause an error for me 80% of the time ...


The comment "LabVIEW will not shut down" in the code is a bit confusing...

 

It seems LV does in fact crash without the wait and dispose.

 

And it does seem the close needs to be done after the print.

 

I suspect the 10 ms wait is needed for the callback VI to finish, so if you add things, 10 ms might not be enough. However, synchronizing the callback with a queue didn't help (enough) to replace the wait.

 

It's all rather nasty.

 

It could help to catch the end print event in a callback and make it sync with the main (queue, user event, whatever). doesn't help either.

 

The example (PrintDocument.Print Method (System.Drawing.Printing) | Microsoft Learn) uses a stream, and that might be required to get it stable.

0 Kudos
Message 7 of 8
(1,929 Views)

Hi Wiebe,

 

I tried to be helpful with my post...

And I got this from you 

"It's all rather nasty"

I'm disappointed... Not really at you, but, also, at you and slightly, at humanity...but I'm not surprised.

You seem to be strong and possess a certain knowledge and status. 

You walk in nature...

You see a tiny seedling, trying to grow;

Don't stomp it.

Look at it.

Appreciate it.

Let it grow...

 

If you are wise, water it.

 

In a time when you are old and tired, it might just cast a lovely, cool, shadow in the burning sunlight...

 

0 Kudos
Message 8 of 8
(1,874 Views)