creation of a pdf

creation of a pdf

Postby Silvio.Falconi » 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( "<[^>]*>", 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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6772
Joined: Thu Oct 18, 2012 7:17 pm

Re: creation of a pdf

Postby Marc Venken » Wed Dec 02, 2020 11:46 am

You open a XML file...

Maybe this function can help you...

Code: Select all  Expand view

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.04 with Harbour
User avatar
Marc Venken
 
Posts: 1343
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: creation of a pdf

Postby Marc Venken » Wed Dec 02, 2020 11:55 am

I print pdf like this

Maybe this is needed

#include "report.ch"


Code: Select all  Expand view

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.04 with Harbour
User avatar
Marc Venken
 
Posts: 1343
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: creation of a pdf

Postby Silvio.Falconi » Wed Dec 02, 2020 12:02 pm

Marc Venken wrote:You open a XML file...

Maybe this function can help you...

Code: Select all  Expand view

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

Image

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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6772
Joined: Thu Oct 18, 2012 7:17 pm

Re: creation of a pdf

Postby Enrico Maria Giordano » Wed Dec 02, 2020 1:06 pm

Try this:

Code: Select all  Expand view
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
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: creation of a pdf

Postby Silvio.Falconi » Thu Dec 03, 2020 9:56 am

Enrico Maria Giordano wrote:Try this:

Code: Select all  Expand view
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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6772
Joined: Thu Oct 18, 2012 7:17 pm

Re: creation of a pdf

Postby Silvio.Falconi » Thu Dec 03, 2020 10:02 am

I tried to save only the cData

if oTagActual:cName = "NomeAttachment"
cNamePdf:= oTagActual:cData
endif

if oTagActual:cName = "Attachment"
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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6772
Joined: Thu Oct 18, 2012 7:17 pm

Re: creation of a pdf

Postby nageswaragunupudi » Thu Dec 03, 2020 4: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
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: creation of a pdf

Postby Silvio.Falconi » Fri Dec 04, 2020 10:15 am

Enrico Maria Giordano wrote:Try this:

Code: Select all  Expand view
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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6772
Joined: Thu Oct 18, 2012 7:17 pm

Re: creation of a pdf

Postby nageswaragunupudi » Tue Dec 08, 2020 6:05 am

Mr. EMG

Please pardon my ignorance.
I am curious to know why you are using HB_BASE64DECODE in this code.
Code: Select all  Expand view

    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
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: creation of a pdf

Postby Enrico Maria Giordano » Tue Dec 08, 2020 8:14 am

Because the PDF is encoded Base64 inside the file XML:

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: creation of a pdf

Postby nageswaragunupudi » 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
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: creation of a pdf

Postby Silvio.Falconi » 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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 6772
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

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