create pdf

create pdf

Postby Detlef » Sat May 13, 2023 4:58 pm

Hi all,
I modified rpreview.prg because i want to show a print preview to the user.
If the user decides that the preview is okay so he presses a button to save the printout as a pdf file.
I use
Code: Select all  Expand view  RUN
TPreview:oDevice:GenHaruPDF( cFile, .f. )

Everything works ok if I code oPrn:say( ... ) in my print.prg

But if I code oPrn:saytext( ... ) my program crashes with
Unrecoverable error 9003: Too many recursive error handler calls

Here a snippet from METHOD GenHaruPDF( cFile, lPreview ) of CLASS TPrinter
Code: Select all  Expand view  RUN
1905:   for each aCall in ::aCallLog
1906:      oPdf:oPrn   := Self
1907:      HB_ExecFromArray( oPdf, aCall[ 1 ], aCall[ 2 ] )  // here crash when SayText( ... ) was used in my print.prg
1908:   next
 


Could anyone give me some help for this?
Regards, Detlef
User avatar
Detlef
 
Posts: 209
Joined: Mon Feb 07, 2022 9:54 pm

Re: create pdf

Postby nageswaragunupudi » Sat May 13, 2023 8:14 pm

Could anyone give me some help for this?

1. Please DO NOT modify FWH library code. It is well written.
2. Please let us know your FWH version.
3. If you want the PDF to be generated using HaruPDF, this is all what you need to do:
At the beginning of your application (function Main(), include this code:
Code: Select all  Expand view  RUN
TPrinter():lUseHaruPDF := .t.

Please make sure you are using FWH libraries WITHOUT ANY MODIFICATIONS.

Now, when the user clicks on the PDF button in Preview, the pdf is generated using HaruPDF.

Once again we request you not to modify any part of FWH libraries
Regards

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

Re: create pdf

Postby Detlef » Sat May 13, 2023 8:41 pm

Many thanks for your reply, Mr. Rao.
My FWH version is 22.10.

I tried to explain why I modified rpreview.prg.
My concern was to show a very, very simple preview with only 3 buttons for 'save as pdf', 'send as email' and 'exit preview'.
No zoom, no export to Excel and Word just a very basic screen.
And therefor I just modified only the button bar for my needs.
Your advice to code TPrinter():lUseHaruPDF := .t. is what I already do.

I don't want a pdf immediately created but only if the user accepts the preview.
So I had to call METHOD GenHaruPDF() if the user clicks the 'save as pdf file' button.

When printing with oPrn:Say everything works fine.
But print with oPrn:SayText crashes.

Regards, Detlef
User avatar
Detlef
 
Posts: 209
Joined: Mon Feb 07, 2022 9:54 pm

Re: create pdf

Postby nageswaragunupudi » Sun May 14, 2023 9:47 am

I tested myself with FWH2210.
This is my test program, with custom buttonbar with only 3 buttons.
This is working correctly for me.

Code: Select all  Expand view  RUN
#include "fivewin.ch"

function Main()

   local oPrn, nWidth, nHeight, nRow
   local oFont, oBold

   // Before print command
   TPrinter():lUseHaruPdf  := .t.
   TPreview():bButtonBar   := { |oPrv,oWnd| MyBar( oPrv,oWnd ) }

   PRINT oPrn PREVIEW

   DEFINE FONT oFont NAME "CONSOLAS" SIZE 0,-10 OF oPrn
   DEFINE FONT oBold NAME "VERDANA"  SIZE 0,-26 BOLD OF oPrn

   oPrn:SetPage( 9 ) // A4
   nWidth   := oPrn:PageWidth(  "CM" )
   nHeight  := oPrn:PageHeight( "CM" )

   PAGE
      oPrn:Say( 2, nWidth/2, FWVERSION + " oPrn:Say()", oBold, nil, nil, nil, 2, "CM" )
      nRow  := 4
      @ nRow, 2 PRINT TO oPrn TEXT ;
         "oPrn:SayText() : tutor01.prg" + CRLF + CRLF + MEMOREAD( "tutor01.prg" ) ;
         SIZE nWidth - 4, nHeight - nRow - 2 CM FONT oFont LASTROW nRow
      nRow += 2
      @ nRow, 2 PRINT TO oPrn TEXT ;
         "oPrn:SayText() : tutor02.prg" + CRLF + CRLF + MEMOREAD( "tutor02.prg" ) ;
         SIZE nWidth - 4, nHeight - nRow - 2 CM FONT oFont LASTROW nRow

   ENDPAGE
   ENDPRINT

   TPreview():bButtonBar   := nil
   RELEASE FONT oFont, oBold

return nil

static function MyBar( Self, oWnd )

   local cFile := "mytest.pdf"

   DEFINE BUTTONBAR ::oBar OF oWnd SIZE 48,48 2007

   DEFINE BUTTON OF ::oBar RESOURCE FWBitmap( "PDF" ) CENTER ;
      ACTION ::SaveAs( .t., cFile, .t. )

   DEFINE BUTTON OF ::oBar RESOURCE FWBitmap( "email" ) CENTER ;
      ACTION ::SendEmail()

   DEFINE BUTTON OF ::oBar RESOURCE FWBitmap( "Exit2" ) CENTER ;
      ACTION oWnd:End()

return nil
 


Image
The image shows both preview with 3 buttons and also the PDF generated

I advise you to first copy the code to samples folder and run with buildh.bat and test yourself
Regards

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

Re: create pdf

Postby Detlef » Sun May 14, 2023 10:04 am

Hello Mr. Rao,

many thanks for your effort.
I'll try this when I'm at home again.

Regards, Detlef
User avatar
Detlef
 
Posts: 209
Joined: Mon Feb 07, 2022 9:54 pm

Re: create pdf

Postby Detlef » Sun May 14, 2023 1:04 pm

Hello Mr. Rao,

I tried your code and it's working fine ( as usual ). :)

Could you please, explain me why my version crashes ?
I don't see the reason why.
Code: Select all  Expand view  RUN
#include "fivewin.ch"
#define   PAD_LEFT  0

function Main()

   local oPrn, nWidth, nHeight, nRow
   local oFont, oBold
   local cBigText := MEMOREAD( "tutor02.prg" )


   // Before print command
   TPrinter():lUseHaruPdf  := .t.
   TPreview():bButtonBar   := { |oPrv,oWnd| MyBar( oPrv,oWnd ) }

   PRINT oPrn PREVIEW

   DEFINE FONT oFont NAME "CONSOLAS" SIZE 0,-10 OF oPrn
   DEFINE FONT oBold NAME "VERDANA"  SIZE 0,-26 BOLD OF oPrn

   oPrn:SetPage( 9 ) // A4
   nWidth   := oPrn:PageWidth(  "CM" )
   nHeight  := oPrn:PageHeight( "CM" )

   PAGE
      oPrn:Say( 2, nWidth/2, FWVERSION + " oPrn:Say()", oBold, nil, nil, nil, 2, "CM" )
      nRow  := 4

/* Lines from Mr. Rao which are working fine
   -----------------------------------------
      @ nRow, 2 PRINT TO oPrn TEXT ;
         cBigText ;
         SIZE nWidth - 4, nHeight - nRow - 2 CM FONT oFont LASTROW nRow
*/


      // this was my code for printing and updating the value of nRow - but crashes
      nRow := oPrn:SayText( nRow, 2, cBigText, 9.5, nHeight - nRow - 2, oFont, PAD_LEFT, nil, nil, "CM" )

      oPrn:Say( nRow, nWidth/2, "nRow after printing big Text", oFont, nil, nil, nil, 2, "CM" )

   ENDPAGE
   ENDPRINT

   TPreview():bButtonBar   := nil
   RELEASE FONT oFont, oBold

return nil

static function MyBar( Self, oWnd )

   local cFile := "mytest.pdf"

   DEFINE BUTTONBAR ::oBar OF oWnd SIZE 48,48 2007

   DEFINE BUTTON OF ::oBar RESOURCE FWBitmap( "PDF" ) CENTER ;
      ACTION ::SaveAs( .t., cFile, .t. )

   DEFINE BUTTON OF ::oBar RESOURCE FWBitmap( "email" ) CENTER ;
      ACTION ::SendEmail()

   DEFINE BUTTON OF ::oBar RESOURCE FWBitmap( "Exit2" ) CENTER ;
      ACTION oWnd:End()

return nil 
User avatar
Detlef
 
Posts: 209
Joined: Mon Feb 07, 2022 9:54 pm

Re: create pdf

Postby nageswaragunupudi » Sun May 14, 2023 1:59 pm

Do not use PAD_LEFT as 7th parameter when using SayText()
Use 'nil' and test again.
It should work without errors. Please run and let us know
Regards

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

Re: create pdf

Postby Detlef » Sun May 14, 2023 2:11 pm

nageswaragunupudi wrote:Do not use PAD_LEFT as 7th parameter when using SayText()
Use 'nil' and test again.
It should work without errors. Please run and let us know

Yes, that made the trick.
I didn't see that cAlign was meant as character type and didn't know that it's better to be nil.

Thanks for your clarification, Mr. Rao
User avatar
Detlef
 
Posts: 209
Joined: Mon Feb 07, 2022 9:54 pm

Re: create pdf

Postby nageswaragunupudi » Sun May 14, 2023 2:26 pm

cAlign is Char type

Default is TL ( topleft )
TR : Top Right
BL, BR -> BottomLeft, BottomRight
"" Center
Regards

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

Re: create pdf

Postby karinha » Sun May 14, 2023 3:25 pm

Code: Select all  Expand view  RUN

// C:\FWH...\SAMPLES\DETLEF4.PRG

#Include "FiveWin.ch"

#Define PAD_LEFT            0
#Define PAD_RIGHT           1
#Define PAD_CENTER          2

FUNCTION Main()

   LOCAL oBrushRed, oBrushGrn
   LOCAL oPrn, nWidth, nHeight, nRow
   LOCAL oFont, oBold, cTxt
   LOCAL cBigText := MemoRead( "tutor02.prg" )

   DEFINE BRUSH oBrushRed COLOR CLR_RED
   DEFINE BRUSH oBrushGrn COLOR CLR_HGREEN

   // Before print command
   TPrinter():lUseHaruPdf := .T.
   TPreview():bButtonBar  := {| oPrv, oWnd | MyBar( oPrv, oWnd ) }

   PRINT oPrn PREVIEW MODAL

      DEFINE FONT oFont NAME "CONSOLAS" SIZE 0, - 10      OF oPrn
      DEFINE FONT oBold NAME "VERDANA"  SIZE 0, - 26 BOLD OF oPrn

      oPrn:SetPage( 9 ) ; oPrn:SetPortrait()

      nWidth   := oPrn:PageWidth(  "CM" )
      nHeight  := oPrn:PageHeight( "CM" )

      PAGE

         oPrn:Say( 2, nWidth / 2, FWVERSION + " oPrn:Say()", oBold, NIL, NIL, NIL, 2, "CM" )

         oPrn:SayText( 1000, 400, "DETLEF: THE BIG TEXT IN FWH: ", 4200, 400, oBold, nil, CLR_MAGENTA, nil, "PIXEL" )

         oPrn:SayText( 1300, 400, cBigText, 4200, 4000, oFont, nil, CLR_YELLOW, oBrushRed, "PIXEL" )

         oPrn:SayText( 5700, 400, "Yellow, RedBrush DETLEF", 4200, 400, oBold, nil, CLR_YELLOW, oBrushRed, "PIXEL" )

         oPrn:SayText( 6200, 400, "Default: nil,nil DETLEF", 4200, 400, oBold, nil, nil,        oBrushGrn, "PIXEL" )

         cTxt := "kapiabafwh@gmail.com"

         oPrn:Say( 6700, 1800, cTxt, oBold, , CLR_HRED, , PAD_CENTER )

      ENDPAGE

   ENDPRINT

   TPreview():bButtonBar := nil

   RELEASE FONT oFont, oBold, oBrushRed, oBrushGrn

RETURN NIL

STATIC FUNCTION MyBar( Self, oWnd )

   LOCAL cFile   := "mytest.pdf", oFont, oBtn
   LOCAL nAlpha  := 0x60
   LOCAL nBarClr := RGB( 0, 0x2E, 0x5C )

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14

   DEFINE BUTTONBAR ::oBar OF oWnd SIZE 48, 48 2007

   ::oBar:SetColor( { |l,o| If( l, CLR_BLACK, CLR_WHITE ) }, oWnd:nClrPane )
   ::oBar:bClrGrad := { |lInvert| If( lInvert, nArgb( 96, CLR_WHITE ), nArgb( nAlpha % 256, nBarClr ) ) }

   ::oBar:GoTop()

   DEFINE BUTTON OF ::oBar RESOURCE FWBitmap( "PDF" )   CENTER ;
      ACTION ::SaveAs( .T., cFile, .T. )

   DEFINE BUTTON OF ::oBar RESOURCE FWBitmap( "email" ) CENTER ;
      ACTION ::SendEmail()

   // By master: UWE. ( Ukoenig )
   DEFINE BUTTON oBtn OF ::oBar PROMPT "Color"  FILE "..\bitmaps\colors.bmp"  ;
      ACTION ( nBarClr := ChooseColor( RGB( 0, 0x2E, 0x5C ) ), ::oBar:Refresh() )

   DEFINE BUTTON OF ::oBar RESOURCE FWBitmap( "Exit2" ) CENTER ;
      ACTION oWnd:End()

RETURN NIL

// FIN / END - kapiabafwh@gmail.com
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7831
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: create pdf

Postby Detlef » Sun May 14, 2023 3:35 pm

karinha,
your message is useless.
As you might see, your defines
Code: Select all  Expand view  RUN
#Define PAD_LEFT            0
#Define PAD_RIGHT           1
#Define PAD_CENTER          2

are all of type numeric.
Mr. Rao stated that the value of cAlign in Method oPrn:SayText has to be character type value.
User avatar
Detlef
 
Posts: 209
Joined: Mon Feb 07, 2022 9:54 pm

Re: create pdf

Postby karinha » Sun May 14, 2023 3:43 pm

DetLef, use whichever is best for you, I'm just showing other ways to use it.

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7831
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: create pdf

Postby goosfancito » Sun Aug 13, 2023 7:56 am

Como activo para que el PREVIEW este en español? italiano? etc...
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Re: create pdf

Postby karinha » Sun Aug 13, 2023 4:31 pm

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7831
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: create pdf

Postby goosfancito » Mon Aug 14, 2023 1:36 pm



Gracias!
fuen un error mio el ue no me mostrara en español. Habia entrado a strings.prg (para hacer una modificacion para mi programa) y elimine todas las lineas
que vienen por defecto de aStings.
Me di cuenta y ahora funciona

gracias!
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 76 guests