Generar PDF con TPrinter

Generar PDF con TPrinter

Postby José Luis Sánchez » Wed Sep 04, 2024 2: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: Select all  Expand view

  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
User avatar
José Luis Sánchez
 
Posts: 552
Joined: Thu Oct 13, 2005 9:23 am
Location: Novelda - Alicante - España

Re: Generar PDF con TPrinter

Postby José Luis Sánchez » Wed Sep 04, 2024 2:41 pm

Hola,
Acabo de descubrir como hacerlo, utilizando FWSavePreviewToPDF( oPrn, cFile, .f. ) al final del listado. Algo así:

Code: Select all  Expand view

      ... 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,
User avatar
José Luis Sánchez
 
Posts: 552
Joined: Thu Oct 13, 2005 9:23 am
Location: Novelda - Alicante - España

Re: Generar PDF con TPrinter

Postby karinha » Wed Sep 04, 2024 3:34 pm

Mira este ejemplo, creo que de mister Nages. No recuerdo el author.

Code: Select all  Expand view

// 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
User avatar
karinha
 
Posts: 7613
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Generar PDF con TPrinter

Postby nageswaragunupudi » Wed Sep 04, 2024 8: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: Select all  Expand view

TPrinter():lUseHaruPDF := .t.
PRINTER oPrn FILE cPdf
PAGE
// print
ENDPAGE
ENDPRINT
 

Now your PDF is ready
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10467
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Generar PDF con TPrinter

Postby Enrico Maria Giordano » Thu Sep 05, 2024 6:39 am

nageswaragunupudi wrote:
Code: Select all  Expand view
TPrinter:lUseHaruPDF := .t. 


Better this way:

Code: Select all  Expand view
TPrinter():lUseHaruPDF := .t.
User avatar
Enrico Maria Giordano
 
Posts: 8512
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Generar PDF con TPrinter

Postby nageswaragunupudi » Fri Sep 06, 2024 3:57 am

Enrico Maria Giordano wrote:
nageswaragunupudi wrote:
Code: Select all  Expand view
TPrinter:lUseHaruPDF := .t. 


Better this way:

Code: Select all  Expand view
TPrinter():lUseHaruPDF := .t.

Sorry it was my typo. Corrected now
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10467
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Generar PDF con TPrinter

Postby José Luis Sánchez » Fri Sep 06, 2024 5:36 am

Thanks Mr. Rao, I'll try this way.
Regards,
User avatar
José Luis Sánchez
 
Posts: 552
Joined: Thu Oct 13, 2005 9:23 am
Location: Novelda - Alicante - España


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 52 guests