Page 1 of 2

Creating a silent file to .pdf

Posted: Wed Aug 12, 2020 1:04 pm
by Rick Lipkin
To All

I have a requirement when a Project is complete to automatically generate a report and to send it to a .pdf printer .. save the file and cc that .pdf document to an e-mail. I see is the new FWH2009 this is now possible :

* HaruPDF:
FWH1909 made it possible to generate native pdf documents using harupdf.
What all is required is to use commands
PRINT TO oPrn FILE "name.pdf"
REPORT oRep PREVIEW TO FILE ("name.pdf" )
and continue programming like normal print/report program. This generates
output to pdf instead to preview/printer.

This new feature sounds just like what I need to generate a "silent" report and create a .pdf document of the report in the background without any user intervention .. no User dialog or the user to select a .pdf printer ..

PRINT TO oPrn FILE "name.pdf"

Am I on the right track here in my understanding of this new .pdf feature ?

Thanks
Rick Lipkin

Re: Creating a silent file to .pdf

Posted: Wed Aug 12, 2020 2:26 pm
by Marco Augusto
Hay un buen ejemplo en:

SAMPLES\PDFHARU1.PDF

Re: Creating a silent file to .pdf

Posted: Wed Aug 12, 2020 2:26 pm
by Marco Augusto
samples\pdfharu1.prg
samples\pdfharu2.prg

Re: Creating a silent file to .pdf

Posted: Thu Aug 13, 2020 6:16 am
by nageswaragunupudi

Code: Select all

PRINT TO oPrn FILE "name.pdf"
 
This was available even prior to 1909.

If you want a pdf generated by harupdf, then add these lines to your program

Code: Select all

REQUEST FWHARU

function Main()

   TPrinter():lUseHaruPDF := .t.
 

Re: Creating a silent file to .pdf

Posted: Tue Sep 08, 2020 7:05 pm
by Rick Lipkin
Rao

I am getting compile errors .. I have compiled \samples\pdfharu1.prg with buildx.bat and It compiles and links .. however using xMate I am linking in Fivehx and Fivehc and my app will not compile .. I have rem'd out all the libs in buildx except Fivehx and Fivehc and the sample compiles ..

I am going crazy ... what lib am I missing..

Thanks Rick Lipkin

Code: Select all

if NOT EXIST %1.prg GOTO :NOEXIST

ECHO Compiling...

if "%FWDIR%" == "" set FWDIR=c:\fwh2006\
if "%XHDIR%" == "" set XHDIR=c:\xharbour
rem if "%2" == "/b" set GT=gtwin
rem if not "%2" == "/b" set GT=gtgui
set GT=gtgui

set hdir=%XHDIR%
set hdirl=%hdir%\lib
set bcdir=c:\borland\bcc74
set fwh=%FWDIR%

%hdir%\bin\harbour %1 /n /i%fwh%\include;%hdir%\include /w /p %2 %3 > comp.log 2> warnings.log
IF ERRORLEVEL 1 GOTO COMPILEERRORS
@type comp.log
@type warnings.log

echo -O2 -e%1.exe -I%hdir%\include -I%bcdir%\include %1.c > b32.bc
%bcdir%\bin\bcc32 -M -c -v @b32.bc
:ENDCOMPILE

IF EXIST %1.rc %bcdir%\bin\brc32.exe -r -I%bcdir%\include -I%bcdir%\include\windows\sdk %1

echo %bcdir%\lib\c0w32.obj + > b32.bc
echo %1.obj, + >> b32.bc
echo %1.exe, + >> b32.bc
echo %1.map, + >> b32.bc
echo %fwh%\lib\Fivehx.lib %fwh%\lib\FiveHC.lib + >> b32.bc
rem echo %fwh%\lib\libmysql.lib + >> b32.bc
rem echo %fwh%\lib\pgsql.lib + >> b32.bc
rem echo %fwh%\lib\libpq.lib + >> b32.bc
echo %hdirl%\hbhpdf.lib + >> b32.bc
echo %hdirl%\libharu.lib + >> b32.bc
echo %hdirl%\png.lib + >> b32.bc
echo %hdirl%\rtl.lib + >> b32.bc
echo %hdirl%\vm.lib + >> b32.bc
echo %hdirl%\%GT%.lib + >> b32.bc
echo %hdirl%\lang.lib + >> b32.bc
echo %hdirl%\macro.lib + >> b32.bc
echo %hdirl%\rdd.lib + >> b32.bc
echo %hdirl%\dbfntx.lib + >> b32.bc
echo %hdirl%\dbfcdx.lib + >> b32.bc
echo %hdirl%\dbffpt.lib + >> b32.bc
echo %hdirl%\hbsix.lib + >> b32.bc
echo %hdirl%\debug.lib + >> b32.bc
echo %hdirl%\common.lib + >> b32.bc
echo %hdirl%\codepage.lib + >> b32.bc
echo %hdirl%\pp.lib + >> b32.bc
echo %hdirl%\pcrepos.lib + >> b32.bc
echo %hdirl%\ct.lib + >> b32.bc
echo %hdirl%\zlib.lib + >> b32.bc
echo %hdirl%\hbzip.lib + >> b32.bc
echo %hdirl%\libmisc.lib + >> b32.bc
echo %hdirl%\tip.lib + >> b32.bc
echo %hdirl%\hbzebra.lib + >> b32.bc
rem echo %hdirl%\png.lib + >> b32.bc


 
Image

Re: Creating a silent file to .pdf

Posted: Tue Sep 08, 2020 7:26 pm
by karinha
Maybe,

Code: Select all

C:\HARUPDF

3/08/2020  12:57    <DIR>          .
3/08/2020  12:57    <DIR>          ..
0/05/2008  23:06            44.059 harupdf.ch
0/10/2012  17:53            35.840 hbhpdf.lib
9/05/2012  17:10             4.187 hbzebra.ch
0/10/2012  17:53            53.248 hbzebra.lib
8/05/2011  17:42           692.736 libharu.lib
0/10/2012  17:52           153.088 png.lib
 
Regards, saludos.

Re: Creating a silent file to .pdf

Posted: Tue Sep 08, 2020 10:04 pm
by nageswaragunupudi
Add these libs in your xmate configuration
echo %hdirl%\hbhpdf.lib + >> b32.bc
echo %hdirl%\libharu.lib + >> b32.bc
echo %hdirl%\png.lib + >> b32.bc

Re: Creating a silent file to .pdf

Posted: Thu Sep 10, 2020 2:51 pm
by Rick Lipkin
Rao

Thank you for your lib advice .. I am able to compile without any issues .. Looking at the sample programs PdfHaru1 and PdfHaru2 .. I see no way I can adapt my code to FWHaru .. The report I am trying to print to pdf works fine if you use the print viewer .. however, I am doing a lot in this report by using the Printer oPrint:nVertRes() and oPrint:nHorzRes() properties and placing my text on the page in relatively the same position based on what ever printer is used ..

I just do not know where to start to retrofit this code to create a FWHARU pdf .. here is a small snipit of code

Code: Select all

Func _ReqPrint1( nView,oDlg,oSay,cSay,oRsTrav, cToPdf, lIsRunning )     // cToPrf

REQUEST FWHARU




Local oPrint
Local oFont8,oFont8b,oFont10,oFont10b,ofont12ib,oFont12b,oFOnt14,oFont24b,oFont10d,oFont10i
Local oPen1,nLines,nPages,nMargin,nPage
Local nRowStep,nColStep
Local cHead1,cHead2,cText,yText,nPrice
Local xLine,nLinCnt,i
Local dDate

Local  cTrainTp1,cTrainTp2,cTrainTp3,cTrainTp4,cTrainTp5,cTrainTp6


Do Case
Case nVIEW = 1
   PRINTER oPRINT FROM USER                ;
   PREVIEW MODAL                           ;
   NAME "Request Print Routine "+xLOGIN

   IF EMPTY( oPRINT:hDC )
      MsgStop ( "Printer not Ready !" )
      CLOSE DATABASES
      oDlg:END()
      RETURN(NIL)
   ENDIF

Case nVIEW = 2

   PRINTER oPRINT from USER                ;
   NAME "Gross Sales Summary Report for "+xLOGIN

   IF EMPTY( oPRINT:hDC )
      MsgStop ( "Printer not Ready !" )
      CLOSE DATABASES
      oDlg:END()
      RETURN(NIL)
   ENDIF

Case nVIEW = 3

   TPrinter():lUseHaruPDF := .t.
   PRINT to oPrint FILE "C:\dbtmp\Rick.pdf"
   // create request.pdf, export all documents and create e-mail

EndCase

oFont8    := TFont():New( "Times New Roman", 0,-8, .F.,.F. , , , ,.F.,,,,,,, oPRINT, )
oFont8b   := TFont():New( "Times New Roman", 0,-8, .F.,.T. , , , ,.F.,,,,,,, oPRINT, )
oFont10   := TFont():New( "Arial",           0,-9, .F.,.F. , , , ,.F.,,,,,,, oPRINT, ) //-10
oFont10b  := TFont():New( "Times New Roman", 0,-10,.F.,.T. , , , ,.F.,,,,,,, oPRINT, )
oFont10i  := TFont():New( "Times New Roman", 0,-10,.F.,.T. , , , ,.T.,,,,,,, oPRINT, )
oFont12ib := TFont():New( "Times New Roman", 0,-12,.F.,.T. , , , ,.T.,,,,,,, oPRINT, )
oFont12b  := TFont():New( "Times New Roman", 0,-12,.F.,.T. , , , ,.F.,,,,,,, oPRINT, )
oFont14b  := TFont():New( "Times New Roman", 0,-14,.F.,.T. , , , ,.F.,,,,,,, oPRINT, )
oFont24b  := TFont():New( "Times New Roman", 0,-24,.F.,.T. , , , ,.F.,,,,,,, oPRINT, )

oFont10d  := TFont():New(  "Courier New",    0,-10,.F.,.T. , , , ,.F.,,,,,,, oPRINT, )

DEFINE PEN oPen1 WIDTH 1 // 5 //10

cSay := "Generating Output"
oSay:ReFresh()
SysReFresh()

SysWait(1)  // take out later

lIsRunning := .t.    // cancel trap


nLines    := 0
nPages    := 1

Do Case
Case nView = 1 .or. nView = 2
   nRowStep := oPrint:nVertRes() / 55      // pixel per line = 57.65 @ 55
   nColStep := oPrint:nHorzRes() /130      // columns
Case nView = 3
   nRowStep := 56.66             // to pdf
   nColStep := 39.33
Otherwise
   nRowStep := oPrint:nVertRes() / 55      // pixel per line = 57.65 @ 55
   nColStep := oPrint:nHorzRes() /130      // columns
EndCase

oPRINT:StartPage()     // error here <<<----------------------------------

nMargin := Int(oPrint:nLogPixelX()*0.2)
LINE    := nMargin
nPage   := 1

cHead1 := "State of South Carolina Department of Insurance"
cHead2 := "Travel / Training Request Form"

oPRINT:SAY ( LINE, (oPrint:nHorzRes()*.25), cHead1, oFONT14b )
Line += oFont12b:nHeight
oPRINT:SAY ( LINE, (oPrint:nHorzRes()*.34), cHead2, oFONT14b )
Line += oFont12b:nHeight
Line += oFont12b:nHeight

oPrint:Line( line, (oPrint:nHorzRes()*.02 ), line, (oPrint:nHorzRes()*.9792), oPen1 )   // top line

Line += oFont12b:nHeight
cText := "Is this Associated with a"
oPRINT:SAY ( LINE, (oPrint:nHorzRes()*.02), cText, oFONT10 )
cText := If(empty(oRsTrav:Fields("PrevAppr"):Value)," ",oRsTrav:Fields("PrevAppr"):Value )
oPRINT:SAY ( LINE, (oPrint:nHorzRes()*.21), cText, oFONT10b )

Line += oFont10b:nHeight
cText := "Previously approved"
oPRINT:SAY ( LINE, (oPrint:nHorzRes()*.02), cText, oFONT10 )
Line += oFont10b:nHeight
cText := "Designation (Y/N)"
oPRINT:SAY ( LINE, (oPrint:nHorzRes()*.02), cText, oFONT10 )

*oPrint:Box( line, (oPrint:nHorzRes()* .20 ), Line* .77, (oPrint:nHorzRes()*.23 ),  oPen1 )   // associaed with

Line -= oFont14b:nHeight+5
Line -= oFont8b:nHeight-12

cText := "If Yes, Please list"
oPRINT:SAY ( LINE, (oPrint:nHorzRes()*.25), cText, oFONT10 )
Line += oFont10b:nHeight
cText := "Designation"
oPRINT:SAY ( LINE, (oPrint:nHorzRes()*.25), cText, oFONT10 )
Line += oFont10b:nHeight
cText := "( 200 char )"
oPRINT:SAY ( LINE, (oPrint:nHorzRes()*.25), cText, oFONT10 )

Line -= oFont14b:nHeight+22
oPrint:Box( line, (oPrint:nHorzRes()* .38 ), Line* 1.70, (oPrint:nHorzRes()*.81 ),  oPen1 )    // designation box

xLine := Line
cText := oRsTrav:Fields("Design"):Value

If Empty(cText) .or. cText = "  "
Else

   Line += oFont8:nHeight-10

   cText := Alltrim( cText)
   nLinCnt := MlCount( cText, 75 )

   IF nLinCnt > 0
      For x := 1 to nLinCnt
          yText := MemoLine( cText, 75, x )
          oPRINT:SAY ( LINE, (oPrint:nHorzRes()*.39 ), yText, oFONT8 )
          Line += oFont8:nHeight
      Next
   Endif

Endif

Line := xLine
...
...
...
....

 
This code works fine if you send the output to the previewer ( rpreview.prg ) and select the Adobe icon .. I was hoping to create this form silently and send it to file as a Pdf .. Any ideas ?? FWHARU sounds like a Great option if I can get it to work ..

Appreciate any ideas !

Thanks
Rick Lipkin

Re: Creating a silent file to .pdf

Posted: Thu Sep 10, 2020 4:18 pm
by nageswaragunupudi
oPRINT:StartPage() // error here <<<----------------------------------
What is the error you are getting?
What if you use the command

Code: Select all

PAGE
....
ENDPAGE
 

Re: Creating a silent file to .pdf

Posted: Thu Sep 10, 2020 4:21 pm
by Rick Lipkin
Rao

Here is how I end my reports .. Thanks, Rick

Code: Select all

oPRINT:EndPage()

Do Case
Case nView = 1   // view
   oPRINT:Preview()
Case nView = 2
   PrintEnd()
Case nView = 3

*   PrintEnd()
   PRINT to oPrint FILE "C:\dbtmp\Rick.pdf"   // tried this and it did not work

EndCase


 

Code: Select all

Do Case
Case nVIEW = 1

   PRINTER oPRINT FROM USER                ;
   PREVIEW MODAL                           ;
   NAME "Request Print Routine "+xLOGIN

   IF EMPTY( oPRINT:hDC )
      MsgStop ( "Printer not Ready !" )
      CLOSE DATABASES
      oDlg:END()
      RETURN(NIL)
   ENDIF

Case nVIEW = 2

   PRINTER oPRINT from USER                ;
   NAME "Request Print Routine for "+xLOGIN

   IF EMPTY( oPRINT:hDC )
      MsgStop ( "Printer not Ready !" )
      CLOSE DATABASES
      oDlg:END()
      RETURN(NIL)
   ENDIF

Case nVIEW = 3

   TPrinter():lUseHaruPDF := .t.

   PRINTER oPRINT ; //from USER                ;
   NAME "Request Print Routine for  "+xLogin

   IF EMPTY( oPRINT:hDC )
      MsgStop ( "Printer not Ready !" )
      RETURN(.f.)
   ENDIF


*   TPrinter():lUseHaruPDF := .t.
*   PRINT to oPrint FILE "C:\dbtmp\Rick.pdf"
   // create request.pdf, export all documents and create e-mail

EndCase

 

Re: Creating a silent file to .pdf

Posted: Fri Sep 11, 2020 12:37 pm
by Rick Lipkin
Rao

I know you are busy ... I sent you a personal e-mail with my attached code to your gmail acct ...

Appreciate your suggestions.

Thanks, Rick

Re: Creating a silent file to .pdf

Posted: Mon Oct 05, 2020 3:25 pm
by leandro
Hola buenos días

Intente hacer lo que recomendó Mr.Rao, pero me devuelve el siguiente error al generar el pdf.

Code: Select all

Application
===========
   Path and name: C:\DLYMA\dlyma.exe (32 bits)
   Size: 7,460,864 bytes
   Compiler version: xHarbour 1.2.3 Intl. (SimpLex) (Build 20190613)
   FiveWin  version: FWH 19.09
   C compiler version: Borland/Embarcadero C++ 7.3 (32-bit)
   Windows version: 6.2, Build 9200 

   Time from start: 0 hours 1 mins 6 secs 
   Error occurred at: 05/10/2020, 10:21:45
   Error description: Warning BASE/1004  Message not found: FWPDF:SETCOPIES

Stack Calls
===========
   Called from: source\rtl\tobject.prg => FWPDF:ERROR( 0 )
   Called from: source\rtl\tobject.prg => FWPDF:MSGNOTFOUND( 0 )
   Called from: source\rtl\tobject.prg => FWPDF:SETCOPIES( 0 )
   Called from: .\source\classes\ESREPORT.PRG => FW_EREPORT:NEW( 358 )
   Called from: c:\dlyma\prg\Afact.prg => CFACT:IMPRIMEFACT( 698 )
   Called from: c:\dlyma\prg\R32_fact.prg => ENVIARCLI( 4804 )
   Called from: c:\dlyma\prg\R32_fact.prg => (b)AVANCECLI( 4720 )
   Called from: .\source\classes\BUTTON.PRG => TBUTTONBMP:CLICK( 179 )
   Called from: .\source\classes\CONTROL.PRG => TBUTTON:HANDLEEVENT( 1755 )
   Called from: .\source\classes\BUTTONB.PRG => TBUTTONBMP:HANDLEEVENT( 261 )
   Called from: .\source\classes\WINDOW.PRG => _FWH( 3559 )
   Called from:  => SENDMESSAGE( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:COMMAND( 433 )
   Called from:  => TWINDOW:HANDLEEVENT( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:HANDLEEVENT( 1136 )
   Called from:  => DIALOGBOXW( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE( 304 )
   Called from: c:\dlyma\prg\R32_fact.prg => AVANCECLI( 4726 )
   Called from: c:\dlyma\prg\R32_fact.prg => (b)FFACTURAS( 93 )
   Called from: c:\dlyma\prg\R32_fact.prg => (b)FFACTURAS( 235 )
   Called from: .\source\classes\URLLINK.PRG => TURLLINK:LBUTTONDOWN( 180 )
   Called from: .\source\classes\CONTROL.PRG => TCONTROL:HANDLEEVENT( 1788 )
   Called from: .\source\classes\URLLINK.PRG => TURLLINK:HANDLEEVENT( 168 )
   Called from: .\source\classes\WINDOW.PRG => _FWH( 3559 )
   Called from:  => WINRUN( 0 )
   Called from: .\source\classes\WINDOW.PRG => TMDIFRAME:ACTIVATE( 1097 )
   Called from: c:\dlyma\prg\R32_menu.prg => VTNAPRINCIPAL( 497 )
   Called from: c:\dlyma\prg\R32_menu.prg => MAIN( 86 )
 

Code: Select all

....
TPrinter():lUseHaruPDF := .t.
.....

.....
        EASYREPORT oVRD NAME ::hOtros["rutavrd"] TO ::cPreterminada PREVIEW (.F.) FILE cNombrePDF
.....


 

Re: Creating a silent file to .pdf

Posted: Mon Oct 05, 2020 4:51 pm
by nageswaragunupudi
SetCopies() is not implemented.
Please try removing SetCopies()
Note: We have not still tested it for Easy Report.
Glad if you test and help us to know the incompatibilities.

Re: Creating a silent file to .pdf

Posted: Tue Oct 06, 2020 12:04 pm
by karinha

Code: Select all

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

#Include "FiveWin.ch"

FUNCTION Main()

   LOCAL cComeFrom := "With preview"

   // oPrn:SetCopies( nCopie ) // Does not work
   LOCAL nCopie := 3

   nSetCopies( nCopie, cComeFrom ) // nCopies

RETURN NIL

FUNCTION nSetCopies( nCopie, cComeFrom )

   LOCAL nI

   FOR nI := 1 TO nCopie

      MsgRun( "PREVIEW.  WAIT...", ;
              "Wait a Moment... ", ;
              { || CursorWait(), WinExec( Imp_Damiano( cComeFrom ) ), 3 } )

   NEXT

RETURN NIL

FUNCTION Imp_Damiano( cComeFrom )

   LOCAL aPrn, oPrn, oFont, oFont2, oFont3, m_Get := ARRAY(5)
   LOCAL nRowStep, nColStep

   m_Get[01] := DTOC( DATE() )

   aPrn := GetPrinters()

   IF Empty( aPrn )
      RETURN NIL
   ENDIF

   PRINTER oPrn PREVIEW MODAL

   IF EMPTY( oPrn:hDC )
      oPrn:End()
      RETURN( .F. )
   ENDIF

   oPrn:End()

   IF cComeFrom = "Directtoprinter"

      PRINT oPrn NAME "Cartellino finiti"      // Direct to the printer

   ELSEIF cComeFrom = "With preview"

      PRINT oPrn NAME "Cartellino finiti" PREVIEW MODAL // With preview

   ELSEIF cComeFrom = "GeneratePDF"

      PRINT oPrn PREVIEW                                // Generate PDF

   ENDIF
   
   DEFINE FONT oFont  NAME "Bahnschrift Light Condensed" SIZE 0, - 18 BOLD OF oPrn
   DEFINE FONT oFont2 NAME "Bahnschrift Light Condensed" SIZE 0, - 26 BOLD OF oPrn
   DEFINE FONT oFont3 NAME "Bahnschrift Light Condensed" SIZE 0, - 20 BOLD OF oPrn

   nRowStep = oPrn:nVertRes() / 40     // 56  righe
   nColStep = oPrn:nHorzRes() / 80    // 170 colonne
   
   PAGE

      // oPrn:Say( nRowStep * 2, nColStep * 65, Transform( m_Get[01],"@D 99/99/9999" ), oFont3 ) //Data
      oPrn:Say( nRowStep * 2, nColStep * 65, TRANSF( m_Get[01],"@D 99/99/9999" ), oFont3 ) //Data

   ENDPAGE

   ENDPRINT

   IF cComeFrom = "GeneratePDF"

      FWSavePreviewToPDF( oPrn, "Cartellino.pdf", .F. )

   ENDIF

   oFont:End()
   oFont2:End()
   oFont3:End()

RETURN NIL
 

Re: Creating a silent file to .pdf

Posted: Tue Oct 06, 2020 12:56 pm
by Rick Lipkin
karinha

Where did this function come from .. is this your personal code ?

FWSavePreviewToPDF( oPrn, "Cartellino.pdf", .F. )

Rick Lipkin