Hi Roger, Fred,
I use PDFCreator in some my apps with no problems for creating and printing PDF output.
This is trick:
- in PDFCrerator's Options just set Automatically saving printed documents in wanted location and needed name, e.g. d:\myprint.pdf
- in create function add this
DCPRINT ON TO M->poPrinter NAME 'PDFCreator' && ORIENTATION 2
- in print function just wait/test for finishing creating pdf - pdfcreator needs a few seconds (if it is not possible rename created file it is still in progress)
If ( FRename( 'd:\myprint.pdf', ( cDisk + 'temptlac.pdf' ) ) == 0 )
FRename( ( cDisk + 'temptlac.pdf' ), 'd:\myprint.pdf' )
Exit
EndIf
- show/print created file
note: attached code(see bellow) is extracted from real app, so please, ignore some comments and variables
HTH
Zdeno
s pozdravom
zdeno bielik
ace system, spol. s r.o.
štiavnická 18
949 01 nitra
http://www.acesystem.sk
tel: 0904 – 328 888
... s nami dostávate vždy viac
Code: Select all
M->pnDriver := 1
MakeReport()
PrintReport()
*
*******************
Function MakeReport()
*******************
Local bEvalPreview := { |o,p| o:SetFrameState( XBPDLG_FRAMESTAT_MAXIMIZED ), p:zoom(p:zoomFactor + (p:zoomIncr*3) ) }
Private poPrinter, pnLine := 0, pnMove := 0.7, pnPage := 1, pcFont := '10.Courier New CE'
...
Do Case
Case ( M->pnDriver == 1 )
DCPRINT ON TO M->poPrinter NAME 'PDFCreator' && ORIENTATION 2
Case ( M->pnDriver == 2 )
DC_PrintPreviewAcrobatOpt( { 0, nil, '5', nil, nil, .f., 'Win2PDF', 3 } )
DCPRINT ON NAME 'Win2PDF' TOFILE OUTFILE ( M->aFirma[ 1, 22 ] ) TO M->poPrinter TITLE ( M->aFirma[ 1, 22 ] )
Case ( M->pnDriver == 3 )
DCPRINT ON PREVIEW TO M->poPrinter HIDE NONSTOP EXITAFTERPRINT && BUSYMESSAGE 'generujem stránky...'
Otherwise
MyAlert( 'No supported PDF driver installed!' )
Release poPrinter, pnLine, pnMove, pnPage, pcFont
DC_GetDestroy(GetList)
My_dbSelectArea( cOldAlias )
lRet := { .F., '' }
Return ( lRet )
EndCase
If ( ( ValType( M->poPrinter ) != 'O' ) .or. ( M->poPrinter:lActive == .F. ) )
MyAlert( 'Eror while creating printer object...' )
Release poPrinter, pnLine, pnMove, pnPage, pcFont
DC_GetDestroy(GetList)
My_dbSelectArea( cOldAlias )
lRet := { .F., '' }
Return ( lRet )
EndIf
...
DCPRINT ...
DCPRINT ...
DCPRINT ...
DCPRINT ...
...
If ( M->pnDriver == 3 ) && internal DC-Preview system
Eval( bEvalPreview, M->poPrinter:oDlg, M->poPrinter:oPreview )
EndIf
DCPRINT OFF
Release poPrinter, pnLine, pnMove, pnPage, pcFont
DC_GetDestroy(GetList)
My_dbSelectArea( cOldAlias )
lRet := { .T., cRet }
Return ( lRet )
*
********************
Function PrintReport( p1, p2, p3 )
********************
&& p1 == nDoklad
&& p2 == P/V/D/F-F/F-R/F-X/SZ/I/U
&& p3 -/+/K
Local GetList := {}, GetOptions
*
Local nRecNo := 0 && ( M->cAlias1 )->( RecNo() )
Local cOldAlias := '' && Alias()
Local oFocus := SetAppFocus()
* Local nTemp := 0
Local cTypDoklad := ''
Local cTemp
Local lTemp
Local cDisk := SubStr( AllTrim( M->aFirma[ 1, 22 ] ), 1, 3 )
Local cAdrPdf
Local cNazSub := ''
Local cNazOdb := ''
Local xTemp
Local bErrorBlock, oError, lError := .F.
*
Local oBusyDlg, oStatic, lStatus := .T., oDlg, nCount := 0, nCountMax := 10 /*120*/, nReset := 0, nMaxReset := 3, ;
cMessage := 'Chvíľu strpenia, prosím, čakám na vytlačenie zostavy ...'
cTypDoklad := 'faktura03'
cAdrPdf := ( M->aS[ S_cLok_Adr ] + 'PDF\Faktury03\' )
cTemp := PadL( AllTrim( Str( p1, 8 ) ), 8, '0' )
FErase( 'd:\myprint.pdf' )
FErase( ( cDisk + 'Xbase++ Spooled Print Job.pdf' ) )
bErrorBlock := ErrorBlock( {|e| Break(e)} )
BEGIN SEQUENCE
xTemp := t_faktura( p1, 'R' )
lTemp := xTemp[1]
cNazOdb := xTemp[2]
If lTemp
If ( M->pnDriver != 3 )
* Do While ( .T. .and. ( nCount < nCountMax ) )
If ( FRename( 'd:\myprint.pdf', ( cDisk + 'temptlac.pdf' ) ) == 0 )
FRename( ( cDisk + 'temptlac.pdf' ), 'd:\myprint.pdf' )
Exit
EndIf
* If ( nCount >= nCountMax )
* If ( nReset <= nMaxReset )
* nReset ++
* nCount := 0
* * MyAlert( 'reseting...' )
* EndIf
* EndIf
* DC_Pause( 0.25 )
* EndDo
DC_BusyOff( oBusyDlg )
If ( nCount < nCountMax )
* Copy File ( M->aFirma[ 1, 22 ] ) To ( M->aS[ S_cLok_Adr ] + cTypDoklad + '.pdf' )
* Copy File ( M->aFirma[ 1, 22 ] ) To ( cAdrPdf + cTypDoklad + '_'+ cTemp + '.pdf' )
RunShell( ( M->aS[ S_cLok_Adr ] + cTypDoklad + '.pdf' ), M->pcAdobe )
* DC_SpawnURL( ( M->aS[ S_cLok_Adr ] + cTypDoklad + '.pdf' ) )
Else
MyAlert( 'Ľutujem, z nejakého dôvodu sa nepodarilo vytvoriť tlačovú zostavu !' )
EndIf
EndIf
EndIf
RECOVER USING oError
DC_BusyOff( oBusyDlg )
oBusyDlg := NIL
oDlg := NIL
lError := .T.
MyAlertTM( 'Print was NOT successfull ' + p2 + ', číslo: ' + AllTrim( Str( p1 ) ) + '...' )
END SEQUENCE
ErrorBlock( bErrorBlock )
SetAppFocus( oFocus )
My_dbSelectArea( cOldAlias )
DC_GetDestroy(GetList)
* DC_ClearEvents()
If lError
MyAlertTM( 'TD - Končím, vyskytla sa chyba...' )
User( .F. )
UserLog( .F. )
* ActiveLog( .F., .T. ) && toto bolo vypnute, lebo sa to vola vo f. Koniec()...
ZapisPDI( 'td end', .T. )
Koniec()
EndIf
Return ( { nRecNo } )
*