05-09-2023 10:17 PM - edited 05-09-2023 10:23 PM
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
Cheers!
05-10-2023 02:48 AM
05-10-2023 02:55 AM
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:
05-10-2023 06:08 AM - edited 05-10-2023 06:14 AM
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 ...
05-10-2023 08:13 AM
Thanks for your contribution!
Would you mind posting it to Example Programs - NI Community?
05-10-2023 09:12 PM
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.
05-11-2023 04:01 AM - edited 05-11-2023 04:14 AM
@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.
05-14-2023 02:47 PM
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...