Mira el ejemplo en testprn6.prg en samples
Te lo dejo acá por las dudas...
// Printing an ascii file
#define REVISED // March 2022
#ifdef REVISED
#include "fivewin.ch"
REQUEST FWHARU
function Main()
local oPrn, oFont
local cText := MemoRead( "testprn5.prg" )
TPrinter():lUseHaruPDF := .t.
PRINT oPrn PREVIEW FILE "prueba.pdf"
DEFINE FONT oFont NAME "Courier New" SIZE 0, -10 OF oPrn
PAGE
@ 1,1 PRINT TO oPrn TEXT cText SIZE 6,9 INCHES FONT oFont
ENDPAGE
ENDPRINT
RELEASE FONT oFont
return nil
#else
// OBSOLETE.
// Not recommended way to save to PDF
#include "FiveWin.ch"
#include "harupdf.ch"
#include "directry.ch"
#define H_SIZE 592
#define V_SIZE 800
function Main()
local cFile
local hDir := maKedir('png')
local hMeta
local oPrn, cText := MemoRead( "testprn5.prg" ), n := 0
local nRowStep, oFont
Aeval( Directory( "png\*.png" ),{|val| FErase( "png\" + val[ F_NAME ] ) } )
PRINTER oPrn PREVIEW
DEFINE FONT oFont NAME "Courier New" SIZE 0, -10 OF oPrn
nRowStep = oPrn:nVertRes() / 40
PAGE
while n < 40
oPrn:Say( n * nRowStep, 1, MemoLine( cText,, n + 1 ), oFont )
n++
end
ENDPAGE
cFile = "png\" + cFileNoExt( ATail( oPrn:aMeta ) ) + ".png "
// CONVERTEMF2PNG( hMeta:=GetEnhMetaFile( ATail( oPrn:aMeta ) ), V_SIZE, H_SIZE, cFile )
// CloseEnhMetafile( hMeta )
FW_SaveImage( MEMOREAD( ATail( oPrn:aMeta ) ), cFile )
ENDPRINTER
BuildPdf()
oFont:End()
ShellExecute( 0, "Open", "prueba.pdf" ) //Esto solo si ademas de crearlo quieres mostrarlo
return nil
function BuildPdf()
LOCAL pdf := HPDF_New()
LOCAL cFileToSave := "prueba.pdf"
LOCAL aDir := Directory( "png\*.png" )
LOCAL aFile
LOCAL page, dst, image
HPDF_SetCompressionMode( pdf, HPDF_COMP_ALL )
for each aFile in aDir
page := HPDF_AddPage(pdf)
HPDF_Page_SetWidth(page, H_SIZE)
HPDF_Page_SetHeight(page, V_SIZE)
dst := HPDF_Page_CreateDestination(page)
HPDF_Destination_SetXYZ(dst, 0, HPDF_Page_GetHeight(page), 1)
HPDF_SetOpenAction(pdf, dst)
// Commentout the following line if you need ASCII chart by Codepages
//Page_CodePages( pdf )
image := HPDF_LoadPngImageFromFile(pdf, "png\" + aFile[ F_NAME ] )
HPDF_Page_DrawImage(page, image, 0, 0, H_SIZE, V_SIZE)
//FErase( aFile[ F_NAME ] )
next
HPDF_SaveToFile( pdf, cFileToSave )
HPDF_Free( pdf )
Aeval( aDir,{|val| FErase( "png\" + val[ F_NAME ] ) } )
return nil
#endif