FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Generar PDF con TPrinter
Posts: 564
Joined: Thu Oct 13, 2005 09:23 AM
Generar PDF con TPrinter
Posted: Wed Sep 04, 2024 02:26 PM
Hola a todos,
Quiero generar un fichero PDF usando TPrinter pero sin utilizar HaruPDF. Hasta ahora hacía lo siguiente utilizando HaruPDF:
Code (fw): Select all Collapse
  cFile := oApp():cPdfPath+Rtrim(FI->FiNombre)+DtoS(date())+StrTran(Time(),":","")+'.pdf'
  PRINTER oprn FILE cFile
   oPrn:SetLandscape() 
   oPrn:lUseHaruPDF := .t.
   oPrn:StartPage()
   WITH OBJECT oPrn
      nLin  := 1.5// 0.5
      nRow  := 0.5
      nMar  := 1 // oAppl:MarGen
      nDes1 := 2.4
      nDes2 := 7.4
      ... aqui siguen los :cmsay del listado
      :EndPage()
      :GenHaruPdf( cFile, .f. )
      :End()
   END WITH
y me generaba el fichero en la ruta que yo indicaba. El problema de usar HaruPDF es que me descuadra los PDF que genero desde los listados - ver https://forums.fivetechsupport.com/viewtopic.php?f=6&t=44794&sid=c8abcb4d21aa6df0be9d15c47b7e8078 - y por eso quiero evitar su uso.

El problema es que no se generar el PDF son HaruPDF. Cambio oPrn:lUseHaruPDF := .t. por oPrn:lUseFWPDF := .t. y quito la linea de :GenHaruPdf( cFile, .f. ) y el fichero PDF no se genera en la ruta indicada. He visto los ejemplos print01.prg y print02.prg pero no me llego a enterar de qué hacer para generar los PDF. Me vendría genial una ayuda.

Saludos,
José Luis
Posts: 564
Joined: Thu Oct 13, 2005 09:23 AM
Re: Generar PDF con TPrinter
Posted: Wed Sep 04, 2024 02:41 PM
Hola,
Acabo de descubrir como hacerlo, utilizando FWSavePreviewToPDF( oPrn, cFile, .f. ) al final del listado. Algo así:
Code (fw): Select all Collapse
      ... aqui siguen los :cmsay del listado
      :EndPage()
   END WITH  
FWSavePreviewToPDF( oPrn, cFile, .f. )
oPrn:End()
Como no se como llamar al propio oPrn dentro del WITH OBJECT oPrn he cerrado antes el bloque y lo llamo de esta manera.
De todos modos, aunque lo tenga solucionado, si alguien quiere aportar algo será bienvenido.

Saludos,
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Generar PDF con TPrinter
Posted: Wed Sep 04, 2024 03:34 PM
Mira este ejemplo, creo que de mister Nages. No recuerdo el author.
Code (fw): Select all Collapse
// C:\FWH\SAMPLES\IMPDPDF6.PRG

#include "fivewin.ch"

FUNCTION Main()

   LOCAL oPrn, oFont
   LOCAL cPdf := "lerele.pdf" // your pdf file name

   TPrinter():lUseFWPDF := .T.

   PRINT oPrn FILE cPdf PREVIEW MODAL // PREVIEW is optional. You can ommit PREVIEW

      DEFINE FONT oFont NAME "Arial" SIZE 0, - 60 NESCAPEMENT 900 OF oPrn

      PAGE

        oPrn:Box( 1, 1, 9, 4, 1, NIL, NIL, "INCHES" )

        @ 1, 1 PRINT TO oPrn TEXT "VERTICAL" SIZE 3, 8 INCHES ALIGN ""       ;
           FONT oFont

      ENDPAGE

   ENDPRINT

   RELEASE FONT oFont

   TPrinter():lUseFWPDF := .F.

RETURN NIL

// FIN / END
Regrads, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Generar PDF con TPrinter
Posted: Wed Sep 04, 2024 08:44 PM
Please do not use lUseHaruPDF after the command PRINTER.
Also do not use GenHaruPDF() method in the application program. This is used internally.

This is the way:
Code (fw): Select all Collapse
TPrinter():lUseHaruPDF := .t.
PRINTER oPrn FILE cPdf
PAGE
// print
ENDPAGE
ENDPRINT
Now your PDF is ready
Regards



G. N. Rao.

Hyderabad, India
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Generar PDF con TPrinter
Posted: Thu Sep 05, 2024 06:39 AM
nageswaragunupudi wrote:
Code (fw): Select all Collapse
TPrinter:lUseHaruPDF := .t.
Better this way:
Code (fw): Select all Collapse
TPrinter():lUseHaruPDF := .t.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Generar PDF con TPrinter
Posted: Fri Sep 06, 2024 03:57 AM
Enrico Maria Giordano wrote:
Code (fw): Select all Collapse
TPrinter:lUseHaruPDF := .t.
Better this way:
Code (fw): Select all Collapse
TPrinter():lUseHaruPDF := .t.
Sorry it was my typo. Corrected now
Regards



G. N. Rao.

Hyderabad, India
Posts: 564
Joined: Thu Oct 13, 2005 09:23 AM
Re: Generar PDF con TPrinter
Posted: Fri Sep 06, 2024 05:36 AM

Thanks Mr. Rao, I'll try this way.

Regards,

Continue the discussion