// --- Cambios a RPreview para trabajar con Image2PDF
// ---
DEFINE BUTTON RESOURCE "Acrobat" OF oBar ;
MESSAGE "Generar archivo tipo PDF" ;
ACTION SavePDF( oDevice, .f. ) ;
TOOLTIP "Generar archivo PDF"
DEFINE BUTTON RESOURCE "Email" OF oBar ;
MESSAGE "Enviar archivo PDF por correo" ;
ACTION SavePDF( oDevice, .t. ) ;
TOOLTIP "Enviar por correo"
// ---
MENUITEM "Generar PDF" ACTION SavePDF( oDevice, .f. ) ;
MESSAGE "Generar archivo tipo PDF" RESOURCE "Acrobat"
MENUITEM "Enviar por correo" ACTION SavePDF( oDevice, .t. ) ;
MESSAGE "Enviar archivo PDF por correo" RESOURCE "Email"
FUNCTION SavePDF(oDevice,lEmail)
LOCAL error, hLibImg2PDF
LOCAL imageFilename:=" "
LOCAL cPdfFilename
LOCAL nI, iErr:=0
LOCAL aFiles:={}, cTemp, oMail, cMail, cNick
LOCAL oDlg, oFont, oEml[4], aEml[4], lCont:=.f.
cPdfFileName:=cUTem+"\"+Left(cNSys,2)+"_Temp\"+oDevice:cDocument+".Pdf"
IF !File("Image2PDF.Dll")
MsgAlert("No existe DLL para generar PDFs.","Precaución!")
RETURN (NIL)
ENDIF
aFiles:=oDevice:aMeta
hLibImg2PDF:=LoadLib32("Image2PDF.Dll")
IF ValType(aFiles)=="A"
I2PDF_License("LICENCIA")
iErr:=IPMeta() // Flag that his is a meta file
iErr:=IPSize() // Reset the size
iErr:=IPMetaAdjustText()
iErr:=IPSetDPI(0) // Set DPI to the default for PDF's. It works better
FOR nI:=1 TO Len(aFiles) // Build the pages using the array of temp files
CursorWait()
imageFilename:=aFiles[nI]
iErr:=IPAddImg(imageFilename)
NEXT nI
CursorWait()
iErr:=IPMakePDF(cPdfFileName,0,error,40) // Create the PDF.
ENDIF
FreeLib32(hLibImg2PDF)
CursorArrow()
IF !File(cPdfFileName)
MsgInfo("No se generó el archivo PDF.","Información!")
ELSE
IF !lEmail
ShellExecute(,"Open",cPdfFileName,"",".\",.T.)
ELSE
aEml[1]:=""
aEml[2]:=AllTrim(Control->NomEmp)
aEml[3]:=oDevice:cDocument+".Pdf"
aEml[4]:="Adjunto información de... "
DEFINE FONT oFont NAME "MS Sans Serif" SIZE 0,-10
DEFINE DIALOG oDlg RESOURCE "Email" FONT oFont
REDEFINE GET oEml[1] VAR aEml[1] ID 101 MEMO OF oDlg VALID !Empty(aEml[1])
oEml[1]:bGotFocus:={|| oEml[1]:SetSel(0,0)}
REDEFINE GET oEml[2] VAR aEml[2] ID 102 MEMO OF oDlg VALID !Empty(aEml[2])
oEml[2]:bGotFocus:={|| oEml[2]:SetSel(0,0)}
REDEFINE GET oEml[3] VAR aEml[3] ID 103 MEMO OF oDlg VALID !Empty(aEml[3])
oEml[3]:bGotFocus:={|| oEml[3]:SetSel(0,0)}
REDEFINE GET oEml[4] VAR aEml[4] ID 104 MEMO OF oDlg VALID !Empty(aEml[4])
oEml[4]:bGotFocus:={|| oEml[4]:SetSel(0,0)}
REDEFINE BUTTON ID 110 OF oDlg ACTION (lCont:=.T.,oDlg:End())
REDEFINE BUTTON ID 120 OF oDlg ACTION (lCont:=.F.,oDlg:End()) CANCEL
ACTIVATE DIALOG oDlg
IF lCont
cNick:=Substr(aEml[1],1,AT("@",aEml[1])-1)
DEFINE MAIL oMail ;
SUBJECT aEml[2] ;
TO cNick,aEml[1] FILES cPdfFileName,cPdfFileName TEXT aEml[4]
ACTIVATE MAIL oMail
ENDIF
oFont:End()
ENDIF
ENDIF
RETURN (NIL)
//--- Wrappers para Image2PDF ---------------------------------------------------------------//
DLL32 STATIC FUNCTION I2PDF_License( code AS LPSTR) AS LONG;
PASCAL FROM "I2PDF_License" LIB "IMAGE2PDF.dll"
DLL32 STATIC FUNCTION IPMeta( ) AS LONG;
PASCAL FROM "I2PDF_MetaToNativePDF" LIB "Image2PDF.dll"
DLL32 STATIC FUNCTION IPMetaAdjustText() AS LONG;
PASCAL FROM "I2PDF_MetaTextFitBoundingRect" LIB "Image2PDF.dll"
DLL32 STATIC FUNCTION IPSize( ) AS LONG;
PASCAL FROM "I2PDF_UseEMFDeviceSize" LIB "Image2PDF.DLL"
DLL32 STATIC FUNCTION IPAddImg( cImage AS LPSTR ) AS LONG;
PASCAL FROM "I2PDF_AddImage" LIB "Image2PDF.dll"
DLL32 STATIC FUNCTION IPSetDpi( nDpi AS LONG ) AS LONG;
PASCAL FROM "I2PDF_SetDPI" LIB "Image2PDF.dll"
DLL32 STATIC FUNCTION IPMakePDF( cOutFile AS LPSTR, nOptions AS LONG, cErrTxt AS LPSTR, nMaxESize AS LONG ) AS LONG;
PASCAL FROM "I2PDF_MakePDF" LIB "Image2PDF.dll"
DLL32 FUNCTION COPYFILE( cExistName AS LPSTR, cNewName AS LPSTR, nFailIfExist AS LONG ) AS BOOL;
PASCAL FROM "CopyFileA" LIB "kernel32.dll"
DLL32 FUNCTION xI2PDF_BatesFormat( format AS LPSTR ) AS LONG;
PASCAL FROM "I2PDF_BatesFormat" LIB "Image2PDF.dll"
DLL32 FUNCTION xI2PDF_BatesLocation( verticalPosition AS LONG, horizontalPosition AS LONG, orientation AS LONG, margin AS LONG) AS LONG;
PASCAL FROM "I2PDF_BatesLocation" LIB "Image2PDF.dll"
DLL32 FUNCTION xI2PDF_BatesFont_Int( iSize AS LONG, FontID AS LPSTR, fillRed AS LONG, fillGreen AS LONG, fillBlue AS LONG, iStyle AS LONG, otherRed AS LONG, otherGreen AS LONG, otherBlue AS LONG) AS LONG;
PASCAL FROM "I2PDF_BatesFont_Int" LIB "Image2PDF.dll"
DLL32 FUNCTION xI2PDF_BatesBackground_Int( shape AS LONG, bkRed AS LONG, bkGreen AS LONG, bkBlue AS LONG, borderRed AS LONG, borderGreen AS LONG, borderBlue AS LONG ) AS LONG;
PASCAL FROM "I2PDF_BatesBackground_Int" LIB "Image2PDF.dll"
//-------------------------------------------------------------------------------------------//