FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Comportamiento extraño PRINT oPrn FILE "factura.pdf"
Posts: 1816
Joined: Wed Oct 26, 2005 02:49 PM
Comportamiento extraño PRINT oPrn FILE "factura.pdf"
Posted: Thu May 16, 2019 04:49 PM
Buenos días para todos,

Tengo el siguiente código, el cual genera un pdf directo al disco sin hacer la previsualización, asi:
Code (fw): Select all Collapse
***********************************************************************
function ImpFactura(tipo)

    local oPrn, oFont
    local cName    := PadR( "Cliente de Prueba", 20 )
    local cCity    := PadR( "1234567890", 20 )
    local cCountry := PadR( "Calle 55 No. 777-988", 20 )
    local cItem    := "31198765431"
   
    PRINT oPrn FILE "factura.pdf"  

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

    PAGE

    oPrn:PrintImage( 100, 700 , "Logo.bmp", 715 , 1000 )


    @ 3.00, 1 PRINT TO oPrn TEXT cName    INCHES FONT oFont
    @ 3.30, 1 PRINT TO oPrn TEXT cCity    INCHES FONT oFont
    @ 3.60, 1 PRINT TO oPrn TEXT cCountry INCHES FONT oFont
    @ 3.90, 1 PRINT TO oPrn TEXT cItem    INCHES FONT oFont


    @ 3.00,5.00 PRINT TO oPrn TEXT dato ;
    AS BARCODE TYPE "QR-CODE" SIZE 1.9,1.9 INCHES


    ENDPAGE

    ENDPRINT


    RELEASE FONT oFont

return nil


El problema es que algunas veces me genera el archivo completo que pesa 140KB, y otras veces lo genera incompleto con un peso de 2KB.

Incompleto
Code (fw): Select all Collapse
%PDF-1.3
2 0 obj
<<
/Type /Page /Parent 1 0 R
/Resources 3 0 R
/MediaBox [ 0 0 595.00 842.00 ]
/Contents 4 0 R
>>
endobj
3 0 obj
<<
/ColorSpace << /DeviceRGB /DeviceGray >>
/ProcSet [ /PDF /Text /ImageB /ImageC ]
/XObject
<<
/Image1 0 0 R
>>
>>
endobj
4 0 obj << /Length 5 0 R 

>>
stream

q
595.0 0 0 842.0 0 0 cm
/Image1 Do
Q 
endstream
endobj
5 0 obj
43
endobj
6 0 obj
<<
/Type /Page /Parent 1 0 R
/Resources 7 0 R
/MediaBox [ 0 0 595.00 842.00 ]
/Contents 8 0 R
>>
endobj
7 0 obj
<<
/ColorSpace << /DeviceRGB /DeviceGray >>
/ProcSet [ /PDF /Text /ImageB /ImageC ]
/XObject
<<
/Image1 0 0 R
>>
>>
endobj
8 0 obj << /Length 9 0 R 

>>
stream

q
595.0 0 0 842.0 0 0 cm
/Image1 Do
Q 
endstream
endobj
9 0 obj
43
endobj
1 0 obj
<<
/Type /Pages /Count 1
/Kids [ ]
>>
endobj
10 0 obj
<< /Title ()
/Producer ()
/Author ()
/Creator ()
/Subject ()
/Keywords ()
/CreationDate (D:20190516114059)
>>
endobj
11 0 obj
<< /Type /Catalog /Pages 1 0 R /Outlines 12 0 R >>
endobj
12 0 obj
<< /Type /Outlines /Count 0 >>
endobj

xref
0 13
0000000000 65535 f
0000000784 00000 n
0000000010 00000 n
0000000130 00000 n
0000000271 00000 n
0000000376 00000 n
0000000397 00000 n
0000000517 00000 n
0000000658 00000 n
0000000763 00000 n
0000000843 00000 n
0000000979 00000 n
0000001049 00000 n
trailer << /Size 13 /Root 11 0 R /Info 10 0 R >>
startxref
1101
%%EOF


Alguien a tenido un problema similar? Hay algo mal en el código?

De antemano gracias
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 25.01 ] [ xHarbour 64 bits) ]
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Comportamiento extraño PRINT oPrn FILE &quot;factura.pdf&quot;
Posted: Thu May 16, 2019 05:51 PM
Mira se te gusta:

Code (fw): Select all Collapse
#include "fivewin.ch"

#define PAD_LEFT            0
#define PAD_RIGHT           1
#define PAD_CENTER          2

function Main()

   local oPrn, oFont, oPen
   Local nLinI, nColI, nLinF, nColF

   // verifica o formato do papela na impressora
   // FOLHA_PAPEL_FOLIO()

   PRINT oPrn NAME "Imprimir" PREVIEW MODAL

      DEFINE FONT oFont NAME "Arial" SIZE 0, -10 BOLD OF oPrn
      DEFINE PEN oPen WIDTH  2                        OF oPrn
 
      // oPrn:SetPage(9)  // A4
      oPrn:SetPage(14)    // FOLIO?
      oPrn:SetPortrait()  //Vertical

      PAGE

         nLinI :=  0.90
         nColI :=  0.90

         nLinF := 28.6
         nColF := 20.0

         oPrn:Cmtr2Pix(@nLinI, @nColI)
         oPrn:cmtr2Pix(@nLinF, @nColF)
         oPrn:Box(nLinI, nColI, nLinF, nColF, oPen  )
         oPrn:cmSay( 1.0,  1.0, "Superior Izquierda", oFont,,CLR_BLACK,,PAD_LEFT  )
         oPrn:cmSay( 1.0, 10.5, "Superior Centro",    oFont,,CLR_BLACK,,PAD_CENTER )
         oPrn:cmSay( 1.0, 20.0, "Superior Derecha",   oFont,,CLR_BLACK,,PAD_RIGHT )
         oPrn:cmSay(28.0,  1.0, "Inferior Izquierda", oFont,,CLR_BLACK,,PAD_LEFT  )
         oPrn:cmSay(28.0, 10.5, "Inferior Centro",    oFont,,CLR_BLACK,,PAD_CENTER )
         oPrn:cmSay(28.0, 20.0, "Inferior Derecha",   oFont,,CLR_BLACK,,PAD_RIGHT )

      ENDPAGE

      // sin preview
      oPrn:lMeta = .F.

   ENDPRINT

   // save pdf
   FWSavePreviewToPDF( oPrn )
 
return nil

FUNCTION FOLHA_PAPEL_FOLIO()

   LOCAL oPrinter, aPaper

   // Para Checar o Tipo de Papel Que Esta Na Impressora - Correto
   oPrinter = TPrinter():New( 'Meu Documento' , .F., .F., NIL, .F. )

   aPaper = PrnGetPaper( oPrinter )

   IF .NOT. aPaper[3] = "Folio" // 'A4'

      // Trocar nas propriedades da impressora.
      MsgInfo( "Troque o Formato do Papel Para Folio", "Impressora" )

   ENDIF

RETURN( .T. )
//----------------------------------------------------
FUNCTION PrnGetPaper( oPrn )

   LOCAL aPoint := PrnGetSize( oPrn:hDc ), aRecmm := {}, nW := 0
   LOCAL nH := 0, wx := 0

   LOCAL aPapers:={{"DMPAPER_LETTER            " ,  1 , "Letter              " , {216,279} },;
                   {"DMPAPER_LETTERSMALL       " ,  2 , "Letter Small        " , {216,279} },;
                   {"DMPAPER_TABLOID           " ,  3 , "Tabloid             " , {280,432} },;
                   {"DMPAPER_LEDGER            " ,  4 , "Ledger              " , {432,280} },;
                   {"DMPAPER_LEGAL             " ,  5 , "Legal               " , {216,356} },;
                   {"DMPAPER_STATEMENT         " ,  6 , "Statement           " , {140,216} },;
                   {"DMPAPER_EXECUTIVE         " ,  7 , "Executive           " , {184,257} },;
                   {"DMPAPER_A3                " ,  8 , "A3                  " , {297,420} },;
                   {"DMPAPER_A4                " ,  9 , "A4                  " , {210,297} },;
                   {"DMPAPER_A4SMALL           " , 10 , "A4 Small            " , {210,297} },;
                   {"DMPAPER_A5                " , 11 , "A5                  " , {148,210} },;
                   {"DMPAPER_B4                " , 12 , "B4                  " , {250,354} },;
                   {"DMPAPER_B5                " , 13 , "B5                  " , {182,257} },;
                   {"DMPAPER_FOLIO             " , 14 , "Folio               " , {216,330} },;
                   {"DMPAPER_QUARTO            " , 15 , "Quarto              " , {215,275} },;
                   {"DMPAPER_10X14             " , 16 , "10x14 in            " , {254,356} },;
                   {"DMPAPER_11X17             " , 17 , "11x17 in            " , {280,432} },;
                   {"DMPAPER_NOTE              " , 18 , "Note                " , {216,279} },;
                   {"DMPAPER_ENV_9             " , 19 , "Envelope #9         " , {098,225} },;
                   {"DMPAPER_ENV_10            " , 20 , "Envelope #10        " , {105,241} },;
                   {"DMPAPER_ENV_11            " , 21 , "Envelope #11        " , {114,264} },;
                   {"DMPAPER_ENV_12            " , 22 , "Envelope #12        " , {109,279} },;
                   {"DMPAPER_ENV_14            " , 23 , "Envelope #14        " , {127,292} },;
                   {"DMPAPER_ENV_DL            " , 27 , "Envelope DL         " , {110,220} },;
                   {"DMPAPER_ENV_C5            " , 28 , "Envelope C5         " , {162,229} },;
                   {"DMPAPER_ENV_C3            " , 29 , "Envelope C3         " , {324,458} },;
                   {"DMPAPER_ENV_C4            " , 30 , "Envelope C4         " , {229,324} },;
                   {"DMPAPER_ENV_C6            " , 31 , "Envelope C6         " , {114,162} },;
                   {"DMPAPER_ENV_C65           " , 32 , "Envelope C65        " , {114,229} },;
                   {"DMPAPER_ENV_B4            " , 33 , "Envelope B4         " , {250,353} },;
                   {"DMPAPER_ENV_B5            " , 34 , "Envelope B5         " , {176,250} },;
                   {"DMPAPER_ENV_B6            " , 35 , "Envelope B6         " , {176,125} },;
                   {"DMPAPER_ENV_ITALY         " , 36 , "Envelope            " , {110,230} },;
                   {"DMPAPER_ENV_MONARCH       " , 37 , "Envelope Monarch    " , {098,191} },;
                   {"DMPAPER_ENV_PERSONAL      " , 38 , "6 3/4 Envelope      " , {092,165} },;
                   {"DMPAPER_FANFOLD_US        " , 39 , "US Std Fanfold      " , {378,279} },;
                   {"DMPAPER_FANFOLD_STD_GERMAN" , 40 , "German Std Fanfold  " , {216,305} },;
                   {"DMPAPER_FANFOLD_LGL_GERMAN" , 41 , "German Legal Fanfold" , {216,330} } }

   aRecmm = oPrn:Pix2Mmtr(aPoint[1], aPoint[2])

   nW = ROUND(aRecmm[1],0)
   nH = ROUND(aRecmm[2],0)

   for wx=1 to len(aPapers)
      if aPapers[wx,4,1] = nW .AND. aPapers[wx,4,2] = nH
         return {aPapers[wx,1],aPapers[wx,2],aPapers[wx,3]}
      endif
   next

return {"",0,""}


João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Comportamiento extraño PRINT oPrn FILE &quot;factura.pdf&quot;
Posted: Thu May 16, 2019 07:19 PM
Code (fw): Select all Collapse
#include "FiveWin.ch"
#Include "Directry.ch"

static oWnd

function Main()

   local oBar, Tipo

   DEFINE WINDOW oWnd TITLE "Factura"

   DEFINE BUTTONBAR oBar _3D OF oWnd

   DEFINE BUTTON OF oBar ACTION( ImpFactura( tipo ) )

   SET MESSAGE OF oWnd TO "Factura" NOINSET CLOCK DATE KEYBOARD

   ACTIVATE WINDOW oWnd

return nil

function ImpFactura( tipo )

    local oPrn, oFont, nRow, nCol
    local cName    := PadR( "Cliente de Prueba", 20 )
    local cCity    := PadR( "1234567890", 20 )
    local cCountry := PadR( "Calle 55 No. 777-988", 20 )
    local cItem    := "31198765431"

    IF FILE( "factura.pdf" )

      FERASE( "factura.pdf" )

      IF FILE( "factura.pdf" )

         ? "Que pasa con el PDF? No borra"

         RETURN NIL

      ENDIF

    ENDIF
   
    PRINT oPrn FILE "factura.pdf"

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

       oPrn:SetPage( 9 )  //-> A4
       oPrn:SetPortrait()  //-> Vertical(Retrato)

       PAGE

          // oPrn:PrintImage( 100, 700 , "Logo.bmp", 715 , 1000 )

          nRow        :=   1.50  // Linha
          nCol        := 650.00  // Coluna do Logo.jpg

          // JPG es mejor.
          @ nRow, nCol PRINT TO oPrn IMAGE "LOGO.JPG" SIZE 650, 650 LASTROW nRow

          @ 3.00, 1 PRINT TO oPrn TEXT cName    INCHES FONT oFont

          @ 3.30, 1 PRINT TO oPrn TEXT cCity    INCHES FONT oFont

          @ 3.60, 1 PRINT TO oPrn TEXT cCountry INCHES FONT oFont

          @ 3.90, 1 PRINT TO oPrn TEXT cItem    INCHES FONT oFont

          // esto no funciona en mi version.
          @ 3.00,5.00 PRINT TO oPrn TEXT dato ;
             AS BARCODE TYPE "QR-CODE" SIZE 1.9,1.9 INCHES

       ENDPAGE

    ENDPRINT

    // oFont:End()
    RELEASE FONT oFont

    IF FILE( "factura.pdf" )

       ? "PDF Creado. Very Good"

    ENDIF

return nil


João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1816
Joined: Wed Oct 26, 2005 02:49 PM
Re: Comportamiento extraño PRINT oPrn FILE &quot;factura.pdf&quot;
Posted: Thu May 16, 2019 08:43 PM
karinha, muchas gracias pror el dato :-) , funciono a la perfección.

Asi quedo el reporte final

Code (fw): Select all Collapse
***********************************************************************
function ImpFactura(tipo)

    local oPrn, oFont
    local cName    := PadR( "Cliente de Prueba", 20 )
    local cCity    := PadR( "1234567890", 20 )
    local cCountry := PadR( "Calle 55 No. 777-988", 20 )
    local cItem    := "31198765431"   
    local dato  := "NumFac:5465465"

    
    PRINT oPrn PREVIEW


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

        PAGE

        oPrn:PrintImage( 100 , 700 , "Logo.bmp", 715 , 1000 )


        @ 3.00, 1 PRINT TO oPrn TEXT cName    INCHES FONT oFont
        @ 3.30, 1 PRINT TO oPrn TEXT cCity    INCHES FONT oFont
        @ 3.60, 1 PRINT TO oPrn TEXT cCountry INCHES FONT oFont
        @ 3.90, 1 PRINT TO oPrn TEXT cItem    INCHES FONT oFont


        @ 3.00,5.00 PRINT TO oPrn TEXT dato ;
        AS BARCODE TYPE "QR-CODE" SIZE 1.9,1.9 INCHES


    ENDPAGE
    
    // sin preview
    oPrn:lMeta = tipo   

    ENDPRINT
    RELEASE FONT oFont
    
    if !tipo
        FWSavePreviewToPDF( oPrn, "pruebafactura.pdf" ,.f. )
    endif

    

return nil
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com

[ Turbo Incremental Link64 6.98 Embarcadero 7.70 ] [ FiveWin 25.01 ] [ xHarbour 64 bits) ]
Posts: 141
Joined: Fri Feb 15, 2019 01:37 PM
Re: Comportamiento extraño PRINT oPrn FILE &quot;factura.pdf&quot;
Posted: Sat Feb 17, 2024 05:20 PM

Hola amigos.

Leandro

Como resolviste el problemas donde unos pdf se generan bien y otros se genera en blanco con un peso de 2kb.

Cuando las genero de uno en uno me lo genera bien, pero cuando mando generar, diez facturas, me genera algunas en blanco. Son aproximandamente que tengo que generar unas 10.000 facturas. Como estoy practicando me encuentro con ese inconveniente.

Posts: 141
Joined: Fri Feb 15, 2019 01:37 PM
Re: Comportamiento extraño PRINT oPrn FILE &quot;factura.pdf&quot;
Posted: Sat Feb 17, 2024 05:57 PM
Asi se ven en la carpeta:


Las que pesan 2kb estan vacias.
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Comportamiento extraño PRINT oPrn FILE &quot;factura.pdf&quot;
Posted: Sat Feb 17, 2024 07:51 PM
Martinez, en tú caso, creo que el mejor, és usar HARUPDF:

https://forums.fivetechsupport.com/viewtopic.php?f=3&t=44222&hilit=HARUPDF&sid=36411525580dc6981b43c3755b15d13d

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 141
Joined: Fri Feb 15, 2019 01:37 PM
Re: Comportamiento extraño PRINT oPrn FILE &quot;factura.pdf&quot;
Posted: Sat Feb 17, 2024 11:16 PM

Gracias karinha

Veo qu esta disponible apartir de la version de FWH1909, toca actualizar mi version es fwh1905.

Continue the discussion