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