1. Christopher Craft
  2. PowerBuilder
  3. Thursday, 10 October 2024 22:10 PM UTC

PB 2022

Wondering if anyone has used 'Microsoft Print to PDF' as the DataWindow.Print.Printername while also specifying the DataWindow.Print.Filename in order to save PDF documents automatically so the SaveAs popup does not show. I am trying to find another possible solution because I keep running into issues with NativePDF (File size issues, font issues, Images not being included).  Would love to hear your thoughts/ideas/pitfalls on this approach.

Thank you,

Chris Craft

Who is viewing this page
Accepted Answer
Ronnie Po Accepted Answer Pending Moderation
  1. Thursday, 10 October 2024 22:46 PM UTC
  2. PowerBuilder
  3. # Permalink

Hey Chris,

I've tried this exact approach, and was surprised that it works well! I've been able to avoid the NativePDF rendering issues that I was dealing with.

ldw_print.Object.DataWindow.Print.PrinterName = "Microsoft Print to PDF"
ldw_print.Object.DataWindow.Print.FileName = <file path>
li_printRet = ldw_print.Print()

The one problem that I've run into is that Print() often returns before the file is actually ready (if you're popping a PDF viewer, or emailing the file, that action would sometimes fail).

As a workaround, I created the following function uof_waitForFile() and call it immediately after calling Print()

// Function uof_waitForFile(string as_filepath, long al_maxWaitSeconds)
//
// Called after saving a file (e.g. PrintToPDF)
// Loop until the file save is complete and the file is accessible
//
// Returns:
//	1 - File is readable
//	-1 - File is not readable after looping for al_maxWaitSeconds
//

// Loop until the saved file is readable
integer li_fileNo
blob lblob_file
// infinite loop buster
time ltime_start, ltime_now
integer li_ret = -1

ltime_start = now()
DO
	ltime_now = now()
	/* Should never happen, but force a break after al_maxWaitSeconds seconds */
	IF secondsAfter(ltime_start, ltime_now) > al_maxWaitSeconds THEN
		EXIT
	END IF
	li_fileNo = FileOpen(as_filepath, StreamMode!, Read!)
	IF li_fileNo <> -1 THEN
		IF FileRead(li_fileNo, lblob_file) > 0 THEN
			/* File is readable and assumed valid. */
			FileClose(li_fileNo)
			li_ret = 1
			EXIT
		ELSE
			/* Set up to loop again */
			li_fileNo = -1
			FileClose(li_fileNo)
		END IF
	END IF
LOOP WHILE li_fileNo = -1

return li_ret
Comment
  1. Christopher Craft
  2. Friday, 11 October 2024 23:18 PM UTC
Also - I just noticed a bug in your File Check code - when the FileRead() fails you set li_fileno to -1 and then call CloseFile(li_fileno). You need to reverse that logic and Close it before setting it back to -1.
  1. Helpful
  1. Ronnie Po
  2. Saturday, 12 October 2024 00:32 AM UTC
Good catch! FWIW, I don't think that line is ever reached. Once FileOpen() succeeds, FileOpen() does as well, but I'll fix the code.
  1. Helpful
  1. Christopher Craft
  2. Thursday, 21 November 2024 00:01 AM UTC
Just another tidbit of information on this - I opened a ticket regarding the Font not being properly included in the PDF document when a Kyocera printer is the default (It changed from Arial to Courier). For the heck of it I just called Object.DataWindow.Print.PrinterName = 'Microsoft Print to PDF' then fired the SaveAs and guess what? The Font was now correct in the PDF! I was planning on setting the default printer then setting it back but it seems this does the trick. Anyway, just thought I would pass this along.
  1. Helpful
There are no comments made yet.
Torgeir Lund Accepted Answer Pending Moderation
  1. Wednesday, 16 October 2024 07:41 AM UTC
  2. PowerBuilder
  3. # 1

Hi

We have been using Amyuni for a long time, but we switched to 3-Heigts PDFProducer (PDFTools) since Amyuni became too expensive. PDProducer will be discontinued in December 2025, so we are also looking for another PDFPrinter. It should also be mentioned that we experienced (also with Amyuni) and experience problems with printing from our 32-bit application on a 64-bit environment, where splwow64 hangs and the print fails. So it could therefore be nice to find a product where we do not use the printer spooler.

We are also using PB 2022 R3 and have looked at NativePDF but are also having some image issues. And now reading the problems from Christopher, NativePDF seems to be even less interesting to use.

For us, the possibility of embedding customer fonts as well as control of the type of embedding, such as partial or full font embedding, is important. Performance is very important. PDF file size and thus options for compressing the pdf output.
We use graphs in the WMF image format (due to the use of a really old activex control), and it is important that these appear sharp, which NativePDF does not quite do.

So I'm hanging on to this thread to see if others have any good experiences.

Regards
Torgeir Lund

Comment
  1. Christopher Craft
  2. Thursday, 24 October 2024 15:51 PM UTC
Torgeir,



Have you looked in using PDFDocument to save it as PDF? This allows you to specify a compression level.



I don't want to scare you out of NativePDF because for the most part it does work for us. Let me clarify my issues I am having:

1) File Size Issue - This is related to me having a company logo on every page of a report. The image seems to get embedded on each page instead of using a reference. I changed my report to only print the logo on the first page and the size went back to normal.

2) Font Issue - This came up because I had to change the NativePDFPrintDC option to zero which then makes it look at the default printer for fonts. The printer the user had as a default did not allow the Arial font to be embedded into the PDF so it used Courier - which made our report not align very well. I had the user change the default to Microsoft Print to PDF and everything started working again. The reason I had to set the PrintDC to zero was because I had a complex report that would crash when trying to save as PDF and this made it start working again.

3) Images not being Included - This is because I have a reporting service that uses multiple threads to send emails out. The problem here was when you use Bitmap or Display as Picture in the DW then Appeon uses a temp directory to pull those images in to include them in the report but in a multi-threaded envirnment it would process at the same time thereby pictures would get replaced so the DW would include whatever file was created last. I had to force my service to only use a single thread and that issue went away. They will have a hotfix for that in 3391.



Anyway - I hope this helps. I would also be curious to know how you deal with your images. Do you keep them in a Database or on the file system. What technique do you use to display these images in the DW?



Chris Craft
  1. Helpful
  1. Torgeir Lund
  2. Friday, 25 October 2024 05:11 AM UTC
Hi Chris,

We use the picture object in DW and the filsystem. Our report can only be displayed as a pdf. Our system produces, for some of our customer 40.000 reports. This reports ar financial reports containing many pages. And therefore performance is very important for us, for producing that amount of reports.



Torgeir Lund
  1. Helpful
There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Saturday, 12 October 2024 16:53 PM UTC
  2. PowerBuilder
  3. # 2

how do you check that Microsoft Print to PDF is installed?  seems like first available with windows 10?

Comment
  1. Christopher Craft
  2. Monday, 14 October 2024 15:19 PM UTC
I use PrintGetPrinters() and then check to see if that printer is valid for this machine.
  1. Helpful 1
There are no comments made yet.
Bruce Armstrong Accepted Answer Pending Moderation
  1. Friday, 11 October 2024 19:28 PM UTC
  2. PowerBuilder
  3. # 3

What we used to use was the Amyuni Printer Driver.  However, we ripped that out and replaced it with NativePDF.

https://www.amyuni.com/en/developer-tools/pdf-converter-developer-pro/learn-more

 

Comment
  1. mike S
  2. Saturday, 12 October 2024 16:50 PM UTC
samesis!
  1. Helpful 1
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.