FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour creation of a pdf
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
creation of a pdf
Posted: Wed Dec 02, 2020 10:02 AM

I save a text on a variable cPdf
this text must taken between two quotes of an italian electronic invoice

<Attachment> </Attachment>
cFile-> xml file
hFile := FOpen( cFile )
nFileLines := FLineCount( cfile )
i := 1
DO WHILE i <= nFileLines
HB_FReadLine( hFile, @Linea )
Linea := LTrim( Linea )

     cField := hb_AtX( &quot;&lt;[^&gt;]*&gt;&quot;, Linea, .F. )
     cField := SubStr( cField, 2, Len( cField ) -2 )
     IF cField == 'Attachment

How take the text between the quotes <Attachment> </Attachment> and create a pdf ?

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: creation of a pdf
Posted: Wed Dec 02, 2020 11:46 AM
You open a XML file...

Maybe this function can help you...

Code (fw): Select all Collapse
function Xmlreader()
   local aMail:={}
   local hFile    := FOpen( "c:\users\marc\downloads\archive.xml"  )

   Local oXmlDoc  := TXmlDocument():New( hFile )
   Local oXmlIter := TXmlIterator():New( oXmlDoc:oRoot ), oTagActual
   while .T.
      oTagActual = oXmlIter:Next()
      If oTagActual != nil
         if oTagActual:cName = "Email"
            aadd(aMail,oTagActual:cData)
         endif
         if oTagActual:cName = "NewsletterID"
            aadd(aMail,oTagActual:cData)
         endif
         if oTagActual:cName = "Subject"
            aadd(aMail,oTagActual:cData)
         endif

//         MsgInfo( oTagActual:cName, oTagActual:cData )
//         HEval( oTagActual:aAttributes, { | cKey, cValue | MsgInfo( cKey, cValue ) } )
      Else
         Exit
      Endif
   End
   xbrowse(aMail)
   FClose( hFile )

return nil
Marc Venken

Using: FWH 23.08 with Harbour
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: creation of a pdf
Posted: Wed Dec 02, 2020 11:55 AM
I print pdf like this

Maybe this is needed

#include "report.ch"


Code (fw): Select all Collapse
function druk_rappel(nRappel)

   Local nDruk:=0, nDrukafstand:= 0.5, nDrukstart:= 8.5, nType:=0

   nType = nRappel
   aFacturen ={}

   Public oPrn
   Public oF12,oF12B,oF12I,oF12U,oFlarge
   cRapport = "c:\programmas\rappels\rappels\rappel_"+alltrim(klant->klant_nr)+".pdf"

   ferase(cRapport)

   PRINT oPrn FILE cRapport PREVIEW

   DEFINE FONT oF12    NAME "CAMBRIA" SIZE 0, -10 OF oPrn
   DEFINE FONT oF12B   NAME "CAMBRIA" BOLD SIZE 0, -10 OF oPrn
   DEFINE FONT oF12I   NAME "CAMBRIA" ITALIC SIZE 0, -10 OF oPrn
   DEFINE FONT oF10    NAME "CAMBRIA" SIZE 0, -10 OF oPrn
   DEFINE FONT oF12U   NAME "CAMBRIA" UNDERLINE BOLD SIZE 0, -10 OF oPrn
   DEFINE FONT oFLarge NAME "CAMBRIA" BOLD SIZE 0, -22 OF oPrn

   oPrn:startpage()

   hoofding(oPrn,"RAP")  // afdruk hoofding
   nDruk = nDrukstart

   do case
      case nType = 1  //  eerste rappel per mail
        oPrn:cmsay (nDruk,2,"Betreft : Openstaande facturen",oF12b)
        oPrn:cmsay (nDruk+1.0,2,"Geachte klant,",oF12)
        oPrn:cmsay (nDruk+2.0,2,"Met dit ",oF12)
        oPrn:cmsay (nDruk+2.5,2,"overschr",oF12)
        oPrn:cmsay (nDruk+3.0,2,"Gelieve ",oF12)
        oPrn:cmsay (nDruk+4,2,"Hieronder kan U het overzicht vinden van de openstaande facturen : ",oF12)
   endcase

   nDruk = nDruk + 4 + 1
   //  Facturen blok
   oPrn:cmsay (nDruk,2," Document            Datum                 Verval Datum              Bedrag              Dagen",oF12u)
   nDruk += nDrukafstand
   nSubsaldo := 0

   facturen->(dbgotop())
   do while !facturen->(eof())
       if !facturen->select
          facturen->(dbskip())
          loop
       endif
       cFactuur = "d:\facturen\" + alltrim(str(facturen->factuur,6))+".pdf"

       if file(cFactuur)
          aadd(afacturen,{cFactuur,cFactuur})
       else
          msginfo("Factuur "+cFactuur+" niet gevonden")
       endif

       oPrn:cmsay (nDruk,2.3,str(facturen->factuur,6,0),oF12)
       oPrn:cmsay (nDruk,4.3,dtoc(facturen->datum),oF12)
       oPrn:cmsay (nDruk,7.3,dtoc(facturen->vervaldat),oF12)

       oPrn:cmsay (nDruk,11.5,str(facturen->totaal,9,2),oF12,,,,1)
       oPrn:cmsay (nDruk,13.5,str( (date()-facturen->vervaldat),9,0),oF12,,,,1)

       nDruk += nDrukafstand
       facturen->(dbskip())
   enddo
   nDruk += nDrukafstand
   */


   do case
     case nType >= 1
        oPrn:cmsay (nDruk,2,"Gelieve te storten op rekening : ",oF12)
        nDruk += nDrukafstand+0.5
        oPrn:cmsay (nDruk,2,"Hopend op een spoedige regeling, verblijven wij,",oF12)
        nDruk += 2
        oPrn:cmsay (nDruk+0,2,"Met de meeste hoogachting,",oF12)
        oPrn:cmsay (nDruk+0.5,2,"De Boekhouding",oF12)
   endcase

   nDruk += 2
   oPrn:cmsay (nDruk,2,"Vragen over deze a" ,oF10)

   oPrn:endpage()

   //oPrn:Preview()

   ENDPRINT
   oF12:end();oF12B:end();oF12I:end();oF12U:end();oFlarge:end();oPrn:end()
return
Marc Venken

Using: FWH 23.08 with Harbour
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: creation of a pdf
Posted: Wed Dec 02, 2020 12:02 PM
Marc Venken wrote:You open a XML file...

Maybe this function can help you...

Code (fw): Select all Collapse
function Xmlreader()
   local aMail:={}
   local hFile    := FOpen( "c:\users\marc\downloads\archive.xml"  )

   Local oXmlDoc  := TXmlDocument():New( hFile )
   Local oXmlIter := TXmlIterator():New( oXmlDoc:oRoot ), oTagActual
   while .T.
      oTagActual = oXmlIter:Next()
      If oTagActual != nil
         if oTagActual:cName = "Email"
            aadd(aMail,oTagActual:cData)
         endif
         if oTagActual:cName = "NewsletterID"
            aadd(aMail,oTagActual:cData)
         endif
         if oTagActual:cName = "Subject"
            aadd(aMail,oTagActual:cData)
         endif

//         MsgInfo( oTagActual:cName, oTagActual:cData )
//         HEval( oTagActual:aAttributes, { | cKey, cValue | MsgInfo( cKey, cValue ) } )
      Else
         Exit
      Endif
   End
   xbrowse(aMail)
   FClose( hFile )

return nil



thanks
I tried with
if oTagActual:cName = "Attachment"
aadd(aMail,oTagActual:cData)
endif

oTagActual: cName "Attachment" finds it but then doesn't save anything on cData



the same error make me
probably does not recognize the string which is then the content of the pdf file
however if I go to xbrowse and create the excel file he inserts the text of the pd
So, on Cdata there is something
Now How Create a Pdf with the content of cData?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: creation of a pdf
Posted: Wed Dec 02, 2020 01:06 PM
Try this:

Code (fw): Select all Collapse
FUNCTION MAIN()

    ESTRAI( "your xml here" )

    RETURN NIL


STATIC FUNCTION ESTRAI( cXml )

    LOCAL cTxt := MEMOREAD( cXml )

    LOCAL nSta, nLen, cPdf

    cTxt = STRTRAN( cTxt, CHR( 4 ) + CHR( 130 ) + CHR( 4 ) + CHR( 0 ), "" )
    cTxt = STRTRAN( cTxt, CHR( 4 ) + CHR( 81 ), "" )

    nSta = AT( "<NomeAttachment>", cTxt ) + 16
    nLen = AT( "</NomeAttachment>", cTxt, nSta ) - nSta
    cPdf = SUBSTR( cTxt, nSta, nLen )
    nSta = AT( "<Attachment>", cTxt ) + 12
    nLen = AT( "</Attachment>", cTxt, nSta ) - nSta

    cTxt = SUBSTR( cTxt, nSta, nLen )
    cTxt = HB_BASE64DECODE( cTxt )

    MEMOWRIT( cPdf, cTxt, .F. )

    RETURN NIL


EMG
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: creation of a pdf
Posted: Thu Dec 03, 2020 09:56 AM
Enrico Maria Giordano wrote:Try this:

Code (fw): Select all Collapse
FUNCTION MAIN()

    ESTRAI( "your xml here" )

    RETURN NIL


STATIC FUNCTION ESTRAI( cXml )

    LOCAL cTxt := MEMOREAD( cXml )

    LOCAL nSta, nLen, cPdf

    cTxt = STRTRAN( cTxt, CHR( 4 ) + CHR( 130 ) + CHR( 4 ) + CHR( 0 ), "" )
    cTxt = STRTRAN( cTxt, CHR( 4 ) + CHR( 81 ), "" )

    nSta = AT( "<NomeAttachment>", cTxt ) + 16
    nLen = AT( "</NomeAttachment>", cTxt, nSta ) - nSta
    cPdf = SUBSTR( cTxt, nSta, nLen )
    nSta = AT( "<Attachment>", cTxt ) + 12
    nLen = AT( "</Attachment>", cTxt, nSta ) - nSta

    cTxt = SUBSTR( cTxt, nSta, nLen )
    cTxt = HB_BASE64DECODE( cTxt )

    MEMOWRIT( cPdf, cTxt, .F. )

    RETURN NIL


EMG


Harbour 3.2.0dev (r1712141320)
Copyright (c) 1999-2016, http://harbour-project.org/
Compiling 'test.prg'...
test.prg(293) Error E0021 Incorrect number of arguments in AT
Passed: 3, expected: 2
test.prg(296) Error E0021 Incorrect number of arguments in AT
Passed: 3, expected: 2
2 errors
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: creation of a pdf
Posted: Thu Dec 03, 2020 10:02 AM

I tried to save only the cData

  if oTagActual:cName = &quot;NomeAttachment&quot;
       cNamePdf:= oTagActual:cData
     endif

     if oTagActual:cName = &quot;Attachment&quot;
       cPdf  := oTagActual:cData
    endif

  cTxt = HB_BASE64DECODE( cPdf )

MEMOWRIT( cNamePdf, cTxt, .F. )

seem to run ok

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: creation of a pdf
Posted: Thu Dec 03, 2020 04:47 PM
Harbour 3.2.0dev (r1712141320)
Copyright (c) 1999-2016, http://harbour-project.org/
Compiling 'test.prg'...
test.prg(293) Error E0021 Incorrect number of arguments in AT
Passed: 3, expected: 2
test.prg(296) Error E0021 Incorrect number of arguments in AT
Passed: 3, expected: 2
2 errors

Use HB_AT() instead of AT() or link xhb.lib.
Regards



G. N. Rao.

Hyderabad, India
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: creation of a pdf
Posted: Fri Dec 04, 2020 10:15 AM
Enrico Maria Giordano wrote:Try this:

Code (fw): Select all Collapse
FUNCTION MAIN()

    ESTRAI( "your xml here" )

    RETURN NIL


STATIC FUNCTION ESTRAI( cXml )

    LOCAL cTxt := MEMOREAD( cXml )

    LOCAL nSta, nLen, cPdf

    cTxt = STRTRAN( cTxt, CHR( 4 ) + CHR( 130 ) + CHR( 4 ) + CHR( 0 ), "" )
    cTxt = STRTRAN( cTxt, CHR( 4 ) + CHR( 81 ), "" )

    nSta = AT( "<NomeAttachment>", cTxt ) + 16
    nLen = AT( "</NomeAttachment>", cTxt, nSta ) - nSta
    cPdf = SUBSTR( cTxt, nSta, nLen )
    nSta = AT( "<Attachment>", cTxt ) + 12
    nLen = AT( "</Attachment>", cTxt, nSta ) - nSta

    cTxt = SUBSTR( cTxt, nSta, nLen )
    cTxt = HB_BASE64DECODE( cTxt )

    MEMOWRIT( cPdf, cTxt, .F. )

    RETURN NIL


EMG


Emg now run with Hb_at
on this tag I found a xsl style format How I can save it ?
I tried with HB_BASE64DECODE but not run ok
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: creation of a pdf
Posted: Tue Dec 08, 2020 06:05 AM
Mr. EMG

Please pardon my ignorance.
I am curious to know why you are using HB_BASE64DECODE in this code.
Code (fw): Select all Collapse
    cTxt = SUBSTR( cTxt, nSta, nLen )
    cTxt = HB_BASE64DECODE( cTxt )
    MEMOWRIT( cPdf, cTxt, .F. )

Can you please enlighten on this?
Thanks in advance.
Regards



G. N. Rao.

Hyderabad, India
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: creation of a pdf
Posted: Tue Dec 08, 2020 08:14 AM

Because the PDF is encoded Base64 inside the file XML:

<Attachment>...base64code...</Attachment>

EMG

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: creation of a pdf
Posted: Tue Dec 08, 2020 12:48 PM
Enrico Maria Giordano wrote:Because the PDF is encoded Base64 inside the file XML:

<Attachment>...base64code...</Attachment>

EMG

Thanks
Regards



G. N. Rao.

Hyderabad, India
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: creation of a pdf
Posted: Wed Dec 09, 2020 12:14 PM
Enrico Maria Giordano wrote:Because the PDF is encoded Base64 inside the file XML:

<Attachment>...base64code...</Attachment>

EMG


Emg,
Now here at School we have an electronic invoice with the style sheet incorporated,
so if I use base64code and converte it not run ok
any solution please ?
how many formats and which types can be incorporated in the electronic invoice here in Italy ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion