Comportamiento extraño PRINT oPrn FILE "factura.pdf"

Comportamiento extraño PRINT oPrn FILE "factura.pdf"

Postby leandro » Thu May 16, 2019 4: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: Select all  Expand view

***********************************************************************
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: Select all  Expand view

%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

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1481
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Re: Comportamiento extraño PRINT oPrn FILE "factura.pdf"

Postby karinha » Thu May 16, 2019 5:51 pm

Mira se te gusta:

Code: Select all  Expand view

#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
User avatar
karinha
 
Posts: 7213
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Comportamiento extraño PRINT oPrn FILE "factura.pdf"

Postby karinha » Thu May 16, 2019 7:19 pm

Code: Select all  Expand view

#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
User avatar
karinha
 
Posts: 7213
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Comportamiento extraño PRINT oPrn FILE "factura.pdf"

Postby leandro » Thu May 16, 2019 8:43 pm

karinha, muchas gracias pror el dato :D , funciono a la perfección.

Asi quedo el reporte final

Code: Select all  Expand view

***********************************************************************
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

[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
User avatar
leandro
 
Posts: 1481
Joined: Wed Oct 26, 2005 2:49 pm
Location: Colombia

Re: Comportamiento extraño PRINT oPrn FILE "factura.pdf"

Postby Adolfredo Martinez » Sat Feb 17, 2024 5: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.
Adolfredo Martinez
 
Posts: 95
Joined: Fri Feb 15, 2019 1:37 pm
Location: Aracataca-Colombia

Re: Comportamiento extraño PRINT oPrn FILE "factura.pdf"

Postby Adolfredo Martinez » Sat Feb 17, 2024 5:57 pm

Asi se ven en la carpeta:
Image

Las que pesan 2kb estan vacias.
Adolfredo Martinez
 
Posts: 95
Joined: Fri Feb 15, 2019 1:37 pm
Location: Aracataca-Colombia

Re: Comportamiento extraño PRINT oPrn FILE "factura.pdf"

Postby karinha » Sat Feb 17, 2024 7: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
User avatar
karinha
 
Posts: 7213
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Comportamiento extraño PRINT oPrn FILE "factura.pdf"

Postby Adolfredo Martinez » 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.
Adolfredo Martinez
 
Posts: 95
Joined: Fri Feb 15, 2019 1:37 pm
Location: Aracataca-Colombia


Return to FiveWin para Harbour/xHarbour

Who is online

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