Page 1 of 3
FwSavePreviewToPdf
Posted: Wed Mar 07, 2018 7:21 pm
by vilian
Hi Guys,
My application is crashing when I try to save the preview report as a PDF. In hb_out.log I can see this:
Code: Select all | Expand
Application Internal Error - C:\VFATEC\SFP\SFP.EXE
Terminated at: 2018-03-07 15:56:48
Unrecoverable error 6005: Exception error:
Exception Code:C0000005 ACCESS_VIOLATION
Exception Address:76FB22D2
EAX:74616474 EBX:FFFA0EDF ECX:026910D0 EDX:00000000
ESI:74616474 EDI:74616470 EBP:0018EB4C
CS:EIP:0023:76FB22D2 SS:ESP:002B:0018EB38
DS:002B ES:002B FS:0053 GS:002B
Flags:00010202
....
....
Called from PDFBEGIN(0) in .\source\function\PRV2PDF.PRG
Called from FWPDF:NEW(171) in .\source\function\PRV2PDF.PRG
Called from FWSAVEPREVIEWTOPDF(53) in .\source\function\PRV2PDF.PRG
Called from TPREVIEW:SAVEAS(1667) in rpreview.prg
Called from (b)TPREVIEW_SAVEASMENU(1569) in rpreview.prg
Do you know why ?
Re: FwSavePreviewToPdf
Posted: Wed Mar 07, 2018 7:30 pm
by karinha
Talvez haya perdido la ruta de grabación, en el caso del PDF, lo hice así:
// PRV2PDF.PRG
Code: Select all | Expand
function FWSavePreviewToPDF( oDevice, cPDF, lOpen ) // oDevice can be oPrinter or oPreview
local cOrient, oPDF
local hWnd
if oDevice:IsKindOf( "TPREVIEW" )
hWnd := oDevice:oWnd:hWnd
oDevice := oDevice:oDevice
endif
#ifndef USEGDI
if LoadFreeImage() <= 32
MsgAlert( FWString( "freeimage.dll not found" ), FWString( "Alert" ) )
return nil
endif
#endif
// MODIFICADO EM: 14/03/2016 PARA SALVAR O PDF NA PASTA: C:\NFEPDF
cPRGPATH := cFILEPATH( "C:\NFEPDF\" )
lCHDIR(cPRGPATH)
// ? hb_CurDrive() + ":\" + CurDir() + "\"
DEFAULT cPDF := cGetFile( FWString( "PDF files | *.pdf |" ),;
FWString( "Select PDF File to Save" ),, ;
CurDir(), .T.,,,;
hb_CurDrive() + ":\" + CurDir() + "\" + ;
If( oDevice:IsKindOf( "TPreview" ),;
oDevice:cName, oDevice:cDocument ) + ".pdf" )
if ! Empty( cPDF )
cPDF = cFileSetExt( cPDF, "pdf" )
CursorWait()
cOrient = If( oDevice:nHorzSize() > oDevice:nVertSize(), 'L', 'P' )
oPdf = fwPdf():New( cPdf, cOrient )
AEval( oDevice:aMeta, { | cMeta | oPdf:AddMeta( cMeta ) } )
oPdf:Close()
CursorArrow()
DEFAULT lOpen := MsgYesNo( If( FWLanguageID() == 2, FWString( "¿" ) + " ", "" ) + ;
FWString( "View" ) + ;
" " + cPDF + " " + FWString( "(Y/N)" ) + " ?",;
FWString( "Please select" ) )
if lOpen
ShellExecute( IfNil( hWnd, GetWndDefault() ), "open", cPDF )
endif
else
cPDF := nil
endif
// VOLTO AO DIRETORIO DO PLENO PARA NAO QUEBRAR OS BANCOS.
lCHDIR( cDirPleno )
// ? hb_CurDrive() + ":\" + CurDir() + "\"
return cPDF
Re: FwSavePreviewToPdf
Posted: Wed Mar 07, 2018 8:59 pm
by vilian
Karinha,
Thanks , but I think isn't ... I think it's a memory problem, because if I try save as PDF file in other computer with more memory, works. Both computers have the same windows version (7.0).
I don't know why FwSavePreviewToPdf is generating too big files... I think I will return this resource to use Image2PDF.DLL it generate a PDF file 90% smaller than FwSavePreviewToPdf.
Re: FwSavePreviewToPdf
Posted: Wed Mar 07, 2018 9:29 pm
by nageswaragunupudi
Image2PDF is the best.
FwSavePreviewToPdf is the last resort
Re: FwSavePreviewToPdf
Posted: Wed Mar 07, 2018 10:53 pm
by vilian
ohh... and I'm thinking fivewin is the best

Re: FwSavePreviewToPdf
Posted: Wed Mar 07, 2018 11:21 pm
by nageswaragunupudi
Back to your issue.
This problem can happen if the filename is invalid or can not be written to.
Re: FwSavePreviewToPdf
Posted: Thu Mar 08, 2018 12:02 am
by vilian
Thanks,
I returned to Image2PDF and everything is fine again

Just to illustrate, I included bellow 2 files - The first one from Image2PDF, the second from FwSavePreviewToPdf
Image2PDF-> teste2.pdf 3 kb
http://www.mediafire.com/file/cfk7nw1cy1drh3k/teste2.pdfFiveWin-> teste1.pdf 140kb !!!
http://www.mediafire.com/file/f5x6p7b97w4ri4b/teste1.pdf
Re: FwSavePreviewToPdf
Posted: Thu Mar 08, 2018 12:38 am
by TimStone
I ran into the same problems a few years ago and have stayed with Image2PDF.dll ever since. It always works. The FWH PDF utility often gave my clients frustration.
Tim
Re: FwSavePreviewToPdf
Posted: Thu Mar 08, 2018 12:59 am
by vilian
Yes, but I'm a little bit worried because I don't find more the utilitywarrior website active . Do you know if they still working ?
Re: FwSavePreviewToPdf
Posted: Thu Mar 08, 2018 1:57 am
by TimStone
The library works so I wouldnt worry about it now
Sent from my iPhone using Tapatalk
Re: FwSavePreviewToPdf
Posted: Tue Mar 13, 2018 8:02 pm
by cnavarro
Please try with Printer "Microsoft Print to PDF" if is installed ( default in Win 10 and Win 8 )
Re: FwSavePreviewToPdf
Posted: Tue Mar 13, 2018 10:02 pm
by Enrico Maria Giordano
I don't like "Microsoft Print to PDF" very much because the result PDF is almost ten times bigger than the one created by PDFCreator. And PDFCreator can be driven by OLE.
EMG
Re: FwSavePreviewToPdf
Posted: Wed Mar 14, 2018 12:01 am
by vilian
Another reason for don´t use "Microsoft Print to PDF" is that sometimes I just want to create the PDF File, I don´t want to preview the report.
Re: FwSavePreviewToPdf
Posted: Wed Mar 14, 2018 6:31 am
by AntoninoP
Hello,
excuse me for the ignorance, but what is Image2PDF and how can I integrate it in my program?

Re: FwSavePreviewToPdf
Posted: Wed Mar 14, 2018 7:48 am
by Silvio.Falconi
yes, of course
MENUITEM "Generar PDF" ACTION SavePDF(oDevice) ;
MESSAGE "Generar archivo tipo PDF" RESOURCE "Acrobat"
Code: Select all | Expand
FUNCTION SavePDF(oDevice)
LOCAL error, hLibImg2PDF
LOCAL imageFilename:=" "
LOCAL cPdfFilename
LOCAL nI, iErr:=0
LOCAL aFiles:={}, cTemp
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
ShellExecute(,"Open",cPdfFileName,"",".\",.T.)
ENDIF
RETURN (NIL)
//----------------------------------------------------------------------------//
DLL32 FUNCTION I2PDF_License( code AS LPSTR) AS LONG;
PASCAL FROM "I2PDF_License" LIB "IMAGE2PDF.dll"
DLL32 FUNCTION IPMeta( ) AS LONG;
PASCAL FROM "I2PDF_MetaToNativePDF" LIB "Image2PDF.dll"
DLL32 FUNCTION IPMetaAdjustText() AS LONG;
PASCAL FROM "I2PDF_MetaTextFitBoundingRect" LIB "Image2PDF.dll"
DLL32 FUNCTION IPSize( ) AS LONG;
PASCAL FROM "I2PDF_UseEMFDeviceSize" LIB "Image2PDF.DLL"
DLL32 FUNCTION IPAddImg( cImage AS LPSTR ) AS LONG;
PASCAL FROM "I2PDF_AddImage" LIB "Image2PDF.dll"
DLL32 FUNCTION IPSetDpi( nDpi AS LONG ) AS LONG;
PASCAL FROM "I2PDF_SetDPI" LIB "Image2PDF.dll"
DLL32 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"
//----------------------------------------------------------------------------//