Printing PDF files (OpenInsight 32-Bit)
At 17 NOV 2009 11:08:14AM Bruce Cameron wrote:
I've seen a few posts regarding printing PDF files and am wondering which way to go. I would like to create a button that the user can click and automatically send a PDF file to the printer.
I creatd the following code but cannot get anything to print. The object loads and the pdf file loads but nothing comes out to print.
I am also looking at doing it with ShellExecute but am wondering if I can/should take advantage of the VSPDF.ocx, VSPRINT7.ocx or other, and how I would accomplish that.
Thanks
Function [/color][/size]Print_PDF[/color][/size]([/size]PDFFile[/size],[/size]Options[/size]) [/size]* [/color]PDFFile [/color][/size]= [/size]"c:\temp\test.pdf" [/color]Options [/color][/size]= [/size]"" [/color]* [/color]PDFOBJ [/color][/size]= [/size]OLECreateInstance[/size]([/size]"AcroPDF.PDF.1"[/color]) Status=[/color]OleStatus[/size]() [/size]If [/color]Status [/color]then Call [/color]Msg([/color]""[/color],[/color]'OLE Error code: '[/color]:Status) [/color]End Else [/color]x [/color][/size]= [/size]OLECallMethod[/size]([/size]PDFOBJ[/size],[/size]"loadFile"[/color],[/color]PDFFile[/size]) Status=[/size]OleStatus[/size]() [/size]If [/color]status [/color]then Call [/color]Msg([/color]""[/color],[/color]'OLE Error code: '[/color]:Status) [/color]end Else [/color]* Give time for the document to load [/color]Call [/color]Yield[/color][/size]() [/size]* [/color]y [/color][/size]= [/size]OLECallMethod[/size](PDFOBJ[/size],[/size]"printAll"[/color]) Status=[/color]OleStatus[/size]() [/size]if [/color]Status [/color]then Call [/color]Msg([/color]@window[/color],[/color]'OLE Error code: '[/color]:Status) [/color]end End End [/color]* [/color]Return [/color]0[/color][/size]
At 17 NOV 2009 02:45PM Bruce Cameron wrote:
Well I couldn't get this to work so I created a work around if anyone is interested. I would still like to know what is wrong with the function but the following is a 'clunky' solution.
1. Create a window/form called Print_PDF
2. Add and OLE control, name it OLE_PDF, for the text user AcroPDF.PDF.1
3. Make the control invisible
4. Add a test control "Your PDF file has been sent to the printer"
5. Add a button control, text=Ok", quick event-] close window
6. Add the following to the "CREATE" event
<code>
[/color][/size]<code> Call Set_Property(@WINDOW:".OLE_PDF","VISIBLE",0)
PDFFile=CreateParam If CreateParam=" Then Option=PrintWithDialog" Else Option=CreateParam If PDFFile # "" Then
Var=Send_Message(@WINDOW:".OLE_PDF","LoadFile",PDFFile) Call Yield() If Var=0 Then Call Set_Property(@WINDOW,"VISIBLE",0) Call Msg("","Error loading PDF file!||Value passed=:PDFFile:"","STANDARD_HALT") Call End_Dialog(@WINDOW) End Else Call Send_Message(@WINDOW:".OLE_PDF",Option) Call Yield("") EndEnd Else
Call Set_Property(@WINDOW,"VISIBLE",0) Call Msg("","No PDF file passed to print!","STANDARD_INFO") Call End_Dialog(@WINDOW)End
RETURN 0[/color][/size]
7. Call this from a function or event using
Call Dialog_Box("PRINT_PDF",@WINDOW,PDFFileToPrint:@FM:PrintOpt)Note: if a MSG is sent then the window will close by itself. If not then the PRINT_PDF window is left visible and the user clicks "Ok" to close.
Any improvements, suggestions, and other ways of doing this are appreciated.