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

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
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.
Ronnie Po Accepted Answer Pending Moderation
  1. Thursday, 10 October 2024 22:46 PM UTC
  2. PowerBuilder
  3. # 4

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 22:26 PM UTC
When viewing the PDF you can look at the Document Properties. This has Title, Author, Subject, and Application. If you use NativePDF or PDFDocument you have the opportunity to set these. Printing only allows you to set the Title using DataWindow.Print.DocumentName.
  1. Helpful
  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
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.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.