Clase pdflib

Clase pdflib

Postby ruben Dario » Wed Sep 02, 2015 8:03 pm

Saludos al forum.

Alguien tiene la clase pdflib para Harbuor.

Gracias
Ruben Dario Gonzalez
Cali-Colombia
rubendariogd@hotmail.com - rubendariogd@gmail.com
User avatar
ruben Dario
 
Posts: 1061
Joined: Thu Sep 27, 2007 3:47 pm
Location: Colombia

Re: Clase pdflib

Postby karinha » Thu Sep 03, 2015 1:13 pm

Ruben, mira todas las paginas en www.pctoledo.com.br, porfa. No conozco esta classe. Lo siento, no puedo ayudar.

Author:

José M. C. Quintas

www.harbourdoc.com.br

Code: Select all  Expand view

Example

PROCEDURE Main
   LOCAL oPDF, nCont, nType
   SetMode( 24, 80 )
   FOR nType = 1 TO 3
      oPDF := PDFClass():New()
      oPDF:nType := nType
      oPDF:cHeader := "TEST REPORT" + Str( nType, 1 )
      oPDF:cFileName := "test" + Str( nType, 1 ) + "." + iif( nType < 3, "pdf", "lst" )
      oPDF:Begin()
      FOR nCont = 1 TO 1000
         oPDF:MaxRowTest()
         oPDF:DrawText( oPDF:nRow++, 0, nCont )
      NEXT
      oPDF:End()
   NEXT
   RETURN

* PDFClass
*----------------------------------------------------------------

#require "hbhpdf"
#include "hbclass.ch"
#include "inkey.ch"

#define PDF_PORTRAIT  1
#define PDF_LANDSCAPE 2
#define PDF_TXT       3

CREATE CLASS PDFClass
   VAR    oPdf
   VAR    oPage
   VAR    cFileName         INIT ""
   VAR    nRow              INIT 999
   VAR    nCol              INIT 0
   VAR    nAngle            INIT 0
   VAR    cFontName         INIT "Courier"
   VAR    nFontSize         INIT 9
   VAR    nLineHeight       INIT 1.3
   VAR    nMargin           INIT 30
   VAR    nType             INIT 1
   VAR    nPdfPage          INIT 0
   VAR    nPageNumber       INIT 0
   VAR    cHeader           INIT {}
   VAR    cCodePage         INIT "CP1252"
   METHOD AddPage()
   METHOD RowToPDFRow( nRow )
   METHOD ColToPDFCol( nCol )
   METHOD MaxRow()
   METHOD MaxCol()
   METHOD DrawText( nRow, nCol, xValue, cPicture, nFontSize, cFontName, nAngle, anRGB )
   METHOD DrawLine( nRowi, nColi, nRowf, nColf, nPenSize )
   METHOD DrawRetangle( nTop, nLeft, nWidth, nHeight, nPenSize, nFillType, anRGB )
   METHOD DrawImage( cJPEGFile, nRow, nCol, nWidth, nHeight )
   METHOD Cancel()
   METHOD PrnToPdf( cInputFile )
   METHOD SetType( nType )
   METHOD PageHeader()
   METHOD MaxRowTest( nRows )
   METHOD SetInfo( cAuthor, cCreator, cTitle, cSubject )
   METHOD Begin()
   METHOD End()
   ENDCLASS

METHOD Begin() CLASS PDFClass
   IF ::nType == PDF_TXT
      IF Empty( ::cFileName )
         ::cFileName := MyTempFile( "LST" )
      ENDIF
      SET PRINTER TO ( ::cFileName )
      SET DEVICE TO PRINT
   ELSE
      IF Empty( ::cFileName )
         ::cFileName := MyTempFile( "PDF" )
      ENDIF
      ::oPdf := HPDF_New()
      HPDF_SetCompressionMode( ::oPdf, HPDF_COMP_ALL )
      IF ::cCodePage != NIL
         HPDF_SetCurrentEncoder( ::oPDF, ::cCodePage )
      ENDIF
   ENDIF
   RETURN NIL

METHOD End() CLASS PDFClass
   IF ::nType == PDF_TXT
      SET DEVICE TO SCREEN
      SET PRINTER TO
      RUN ( "cmd /c start notepad.exe " + ::cFileName )
   ELSE
      IF ::nPdfPage == 0
         ::AddPage()
         ::DrawText( 10, 10, "NENHUM CONTEUDO (NO CONTENT)",, ::nFontSize * 2 )
      ENDIF
      IF File( ::cFileName )
         fErase( ::cFileName )
      ENDIF
      HPDF_SaveToFile( ::oPdf, ::cFileName )
      HPDF_Free( ::oPdf )
      RUN ( "cmd /c start " + ::cFileName )
   ENDIF
   RETURN NIL

METHOD SetInfo( cAuthor, cCreator, cTitle, cSubject ) CLASS PDFClass
   IF ::nType == PDF_TXT
      RETURN NIL
   ENDIF
   cAuthor  := iif( cAuthor == NIL, "JPA Tecnologia", cAuthor )
   cCreator := iif( cCreator == NIL, "Harupdf", cCreator )
   cTitle   := iif( cTitle == NIL, "", cTitle )
   cSubject := iif( cSubject == NIL, cTitle, cSubject )
   HPDF_SetInfoAttr( ::oPDF, HPDF_INFO_AUTHOR, cAuthor )
   HPDF_SetInfoAttr( ::oPDF, HPDF_INFO_CREATOR, cCreator )
   HPDF_SetInfoAttr( ::oPDF, HPDF_INFO_TITLE, cTitle )
   HPDF_SetInfoAttr( ::oPdf, HPDF_INFO_SUBJECT, cSubject )
   HPDF_SetInfoDateAttr( ::oPDF, HPDF_INFO_CREATION_DATE, { Year( Date() ), Month( Date() ), Day( Date() ), ;
      Val( Substr( Time(), 1, 2 ) ), Val( Substr( Time(), 4, 2 ) ), Val( Substr( Time(), 7, 2 ) ), "+", 4, 0 } )
   RETURN NIL

METHOD SetType( nType ) CLASS PDFClass
   IF nType != NIL
      ::nType := nType
   ENDIF
   ::nFontSize := iif( ::nType == 1, 9, 6 )
   RETURN NIL

METHOD AddPage() CLASS PDFClass
   IF ::nType != PDF_TXT
      ::oPage := HPDF_AddPage( ::oPdf )
      HPDF_Page_SetSize( ::oPage, HPDF_PAGE_SIZE_A4, iif( ::nType == 2, HPDF_PAGE_PORTRAIT, HPDF_PAGE_LANDSCAPE ) )
      HPDF_Page_SetFontAndSize( ::oPage, HPDF_GetFont( ::oPdf, ::cFontName, ::cCodePage ), ::nFontSize )
   ENDIF
   ::nRow := 0
   RETURN NIL

METHOD Cancel() CLASS PDFClass
   IF ::nType != PDF_TXT
      HPDF_Free( ::oPdf )
   ENDIF
   RETURN NIL

METHOD DrawText( nRow, nCol, xValue, cPicture, nFontSize, cFontName, nAngle, anRGB ) CLASS PDFClass
   LOCAL nRadian , cTexto
   nFontSize := iif( nFontSize == NIL, ::nFontSize, nFontSize )
   cFontName := iif( cFontName == NIL, ::cFontName, cFontName )
   cPicture  := iif( cPicture == NIL, "", cPicture )
   nAngle    := iif( nAngle == NIL, ::nAngle, nAngle )
   cTexto    := Transform( xValue, cPicture )
   ::nCol := nCol + Len( cTexto )
   IF ::nType == PDF_TXT
      @ nRow, nCol SAY cTexto
   ELSE
      nRow := ::RowToPDFRow( nRow )
      nCol := ::ColToPDFCol( nCol )
      HPDF_Page_SetFontAndSize( ::oPage, HPDF_GetFont( ::oPdf, cFontName, ::cCodePage ), nFontSize )
      IF anRGB != NIL
         HPDF_Page_SetRGBFill( ::Page, anRGB[ 1 ], anRGB[ 2 ], anRGB[ 3 ] )
         HPDF_Page_SetRGBStroke( ::Page, anRGB[ 1 ], anRGB[ 2], anRGB[ 3] )
      ENDIF
      HPDF_Page_BeginText( ::oPage )
      nRadian := ( nAngle / 180 ) * 3.141592
      HPDF_Page_SetTextMatrix( ::oPage, Cos( nRadian ), Sin( nRadian ), -Sin( nRadian ), Cos( nRadian ), nCol, nRow )
      HPDF_Page_ShowText( ::oPage, cTexto )
      HPDF_Page_EndText( ::oPage )
      IF anRGB != NIL
         HPDF_Page_SetRGBFill( ::Page, 0, 0, 0 )
         HPDF_Page_SetRGBStroke( ::Page, 0, 0, 0 )
      ENDIF
   ENDIF
   RETURN NIL

METHOD DrawLine( nRowi, nColi, nRowf, nColf, nPenSize ) CLASS PDFClass
   IF ::nType == PDF_TXT
      nRowi := Round( nRowi, 0 )
      nColi := Round( nColi, 0 )
      @ nRowi, nColi SAY Replicate( "-", nColf - nColi )
      ::nCol := Col()
   ELSE
      nPenSize := iif( nPenSize == NIL, 0.2, nPenSize )
      nRowi := ::RowToPDFRow( nRowi )
      nColi := ::ColToPDFCol( nColi )
      nRowf := ::RowToPDFRow( nRowf )
      nColf := ::ColToPDFCol( nColf )
      HPDF_Page_SetLineWidth( ::oPage, nPenSize )
      HPDF_Page_MoveTo( ::oPage, nColi, nRowi )
      HPDF_Page_LineTo( ::oPage, nColf, nRowf )
      HPDF_Page_Stroke( ::oPage )
   ENDIF
   RETURN NIL

METHOD DrawImage( cJPEGFile, nRow, nCol, nWidth, nHeight ) CLASS PDFClass
   LOCAL oImage
   IF ::nType == PDF_TXT
      RETURN NIL
   ENDIF
   nRow    := ::RowToPDFRow( nRow )
   nCol    := ::ColToPDFCol( nCol )
   nWidth  := Int( nWidth * ::nFontSize / 2 )
   nHeight := nHeight * ::nFontSize
   oImage := HPDF_LoadJPEGImageFromFile( ::oPdf, cJPEGFile )
   HPDF_Page_DrawImage( ::oPage, oImage, nCol, nRow, nWidth, nHeight )
   RETURN NIL

METHOD DrawRetangle( nTop, nLeft, nWidth, nHeight, nPenSize, nFillType, anRGB ) CLASS PDFClass
   IF ::nType == PDF_TXT
      RETURN NIL
   ENDIF
   nFillType := iif( nFillType == NIL, 1, nFillType )
   nPenSize  := iif( nPenSize == NIL, 0.2, nPenSize )
   nTop      := ::RowToPDFRow( nTop )
   nLeft     := ::ColToPDFCol( nLeft )
   nWidth    := ( nWidth ) * ::nFontSize / 1.666
   nHeight   := -( nHeight ) * :: nFontSize
   HPDF_Page_SetLineWidth( ::oPage, nPenSize )
   IF anRGB != NIL
      HPDF_Page_SetRGBFill( ::oPage, anRGB[ 1 ], anRGB[ 2 ], anRGB[ 3 ] )
      HPDF_Page_SetRGBStroke( ::oPage, anRGB[ 1 ], anRGB[ 2 ], anRGB[ 3 ] )
   ENDIF
   HPDF_Page_Rectangle( ::oPage, nLeft, nTop, nWidth, nHeight )
   IF nFillType == 1
      HPDF_Page_Stroke( ::oPage )     // borders only
   ELSEIF nFillType == 2
      HPDF_Page_Fill( ::oPage )       // inside only
   ELSE
      HPDF_Page_FillStroke( ::oPage ) // all
   ENDIF
   IF anRGB != NIL
      HPDF_Page_SetRGBStroke( ::oPage, 0, 0, 0 )
      HPDF_Page_SetRGBFill( ::oPage, 0, 0, 0 )
   ENDIF
   RETURN NIL

METHOD RowToPDFRow( nRow ) CLASS PDFClass
   RETURN HPDF_Page_GetHeight( ::oPage ) - ::nMargin - ( nRow * ::nFontSize * ::nLineHeight )

METHOD ColToPDFCol( nCol ) CLASS PDFClass
   RETURN nCol * ::nFontSize / 1.666 + ::nMargin

METHOD MaxRow() CLASS PDFClass
   LOCAL nPageHeight, nMaxRow
   IF ::nType == PDF_TXT
      RETURN 63
   ENDIF
   nPageHeight := HPDF_Page_GetHeight( ::oPage ) - ( ::nMargin * 2 )
   nMaxRow     := Int( nPageHeight / ( ::nFontSize * ::nLineHeight )  )
   RETURN nMaxRow

METHOD MaxCol() CLASS PDFClass
   LOCAL nPageWidth, nMaxCol
   IF ::nType == PDF_TXT
      RETURN 132
   ENDIF
   nPageWidth := HPDF_Page_GetWidth( ::oPage ) - ( ::nMargin * 2 )
   nMaxCol    := Int( nPageWidth / ::nFontSize * 1.666 )
   RETURN nMaxCol

METHOD PrnToPdf( cInputFile ) CLASS PDFClass
   LOCAL cTxtReport, cTxtPage, cTxtLine, nRow
   cTxtReport := MemoRead( cInputFile ) + Chr(12)
   TokenInit( @cTxtReport, Chr(12) )
   DO WHILE .NOT. TokenEnd()
      cTxtPage := TokenNEXT( cTxtReport ) + HB_EOL()
      IF Len( cTxtPage ) > 5
         IF Substr( cTxtPage, 1, 1 ) == Chr(13)
            cTxtPage := Substr( cTxtPage, 2 )
         ENDIF
         ::AddPage()
         nRow := 0
         DO WHILE At( HB_EOL(), cTxtPage ) != 0
            cTxtLine := Substr( cTxtPage, 1, At( HB_EOL(), cTxtPage ) - 1 )
            cTxtPage := Substr( cTxtPage, At( HB_EOL(), cTxtPage ) + 2 )
            ::DrawText( nRow++, 0, cTxtLine )
         ENDDO
      ENDIF
   ENDDO
   RETURN NIL

METHOD PageHeader() CLASS PDFClass
   ::nPdfPage    += 1
   ::nPageNumber += 1
   ::nRow        := 0
   ::AddPage()
   ::DrawText( 0, 0, "YOU NAME HERE" )
   ::DrawText( 0, ( ::MaxCol() - Len( ::cHeader ) ) / 2, ::cHeader )
   ::DrawText( 0, ::MaxCol() - 12, "Page " + StrZero( ::nPageNumber, 6 ) )
   ::DrawLine( 0.5, 0, 0.5, ::MaxCol() )
   ::nRow := 2
   ::nCol := 0
   RETURN NIL

METHOD MaxRowTest( nRows ) CLASS PDFClass
   nRows := iif( nRows == NIL, 0, nRows )
   IF ::nRow > ::MaxRow() - 2 - nRows
      ::PageHeader()
   ENDIF
   RETURN NIL

FUNCTION TxtSaida()
   RETURN { "PDF Landscape", "PDF Portrait", "Matrix" }

FUNCTION MyTempFile( cExtensao )
   RETURN "temp." + cExtensao

/*
Library*

www.harbourdoc.com.br

Text Origin/Author

José M. C. Quintas
*/

 


Saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7353
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Clase pdflib

Postby karinha » Thu Sep 03, 2015 1:22 pm

Ruben, tests:

Code: Select all  Expand view

PROCEDURE Main

   Report1()
   Report2()
   Report3()
   Report4()
   Report5()
   RETURN NIL
   
   
STATIC FUNCTION Report1() // common clipper report
   SET PRINTER TO test1.lst
   SET DEVICE TO PRINT
   nRow  := 100
   nPage := 0
   FOR nCont = 1 TO 1000
      IF nRow > 64
         nPage += 1
         @ 0, 0 SAY "TEST1 Page" + StrZero( nPage, 5 )
         nRow := 1
      ENDIF
      @ nRow, 0 SAY nCont PICTURE "999999"
      nRow += 1
   NEXT
   SET DEVICE TO SCREEN
   SET PRINTER TO
   RETURN
   
STATIC FUNCTION Report2() // using own header
   LOCAL oPDF
   FOR nType = 1 TO 3
      oPDF := PDFClass():New()
      oPDF:nType := nType
      oPDF:cFileName := "TEST2-" + Str( nType, 1 ) + "." + iif( nType < 3, "pdf", "lst" )
      oPDF:Begin()
      FOR nCont = 1 TO 1000
         IF oPDF:nRow > oPDF:MaxRow()
            oPDF:PageHeader()
            oPDF:DrawText( 0, 0, "REPORT TEST2-" + Str( nType, 1 ) )
            oPDF:DrawText( oPDF:nRow, oPDF:nCol + 1, oPDF:nPDFPage, "999999" )
            oPDF:nRow := 1
         ENDIF
         oPDF:DrawText( oPDF:nRow, 0, nCont, "999999" )
         oPDF:nRow += 1
      NEXT
      oPDF:End()
   NEXT
   RETURN

STATIC FUNCTION Report3() // using bult-in header
   FOR nType = 1 TO 3
      oPDF := PDFClass():New()
      oPDF:nType := nType
      oPDF:cFileName := "TEST3-" + Str( nType, 1 ) + "." + iif( nType < 3, "pdf", "lst" )
      oPDF:cHeader := "REPORT TEST3-" + Str( nType, 1 )
      oPDF:Begin()
      FOR nCont = 1 TO 1000
         oPDF:MaxRowTest()
         oPDF:DrawText( oPDF:nRow++, 0, nCont )
      NEXT
      oPDF:End()
   NEXT
   RETURN
   
STATIC FUNCTION Report4() // some paint
   FOR nType = 1 TO 3
      oPDF := PDFClass():New()
      oPDF:nType := nType
      oPDF:cFileName := "TEST4-" + Str( nType, 1 ) + "." + iif( nType < 3, "pdf", "lst" )
      oPDF:cHeader := "REPORT TEST4-" + Str( nType, 1 )
      oPDF:Begin()
      lPaint := .f.
      FOR nCont = 1 TO 1000
         oPDF:MaxRowTest()
        lPaint := ( .NOT. lPaint )
         IF lPaint
            oPDF:DrawRetangle( oPDF:nRow - 1 + 0.3, 0, oPDF:MaxCol(), 1, 0.2, 2, { 0.9, 0.9, 0.9 } )
         ENDIF
        oPDF:DrawText( oPDF:nRow++, 0, nCont )
      NEXT
      oPDF:End()
   NEXT
   RETURN

STATIC FUNCTION Report5()
   FOR nType = 1 TO 3
      oPDF := PDFClass():New()
      oPDF:nType := nType
      oPDF:cFileName := "TEST5-" + Str( nType, 1 ) + "." + iif( nType < 3, "pdf", "lst" )
      oPDF:Begin()
      oPDF:PageHeader()
      oPDF:nRow := 2

      FOR nCont = 1 TO 6
         oPDF:DrawRetangle( oPDF:nRow - 0.5, ( nCont - 1 ) * oPDF:MaxCol() / 6, oPDF:MaxCol() / 6, 1.5 )
      NEXT
      oPDF:DrawText( oPDF:nRow,     oPDF:MaxCol() / 6 * 0 + 1, "II",, oPDF:nFontSize / 2 )
      oPDF:DrawText( oPDF:nRow,     oPDF:MaxCol() / 6 * 1 + 1, "IPI",, oPDF:nFontSize / 2 )
      oPDF:DrawText( oPDF:nRow,     oPDF:MaxCol() / 6 * 2 + 1, "ICMS",, oPDF:nFontSize /2 )
      oPDF:DrawText( oPDF:nRow,     oPDF:MaxCol() / 6 * 3 + 1, "ICMS ST",, oPDF:nFontSize / 2 )
      oPDF:DrawText( oPDF:nRow,     oPDF:MaxCol() / 6 * 4 + 1, "PESO BRUTO",, oPDF:nFontSize / 2 )
      oPDF:DrawText( oPDF:nRow,     oPDF:MaxCol() / 6 * 5 + 1, "VL.PRODUTOS",, oPDF:nFontSize / 2 )
      oPDF:DrawText( oPDF:nRow+0.5, oPDF:MaxCol() / 6 * 0 + 1, 1, PicVal( 10, 2 ) )
      oPDF:DrawText( oPDF:nRow+0.5, oPDF:MaxCol() / 6 * 1 + 1, 2, PicVal( 10, 2 ) )
      oPDF:DrawText( oPDF:nRow+0.5, oPDF:MaxCol() / 6 * 2 + 1, 3, PicVal( 10, 2 ) )
      oPDF:DrawText( oPDF:nRow+0.5, oPDF:MaxCol() / 6 * 3 + 1, 4, PicVal( 10, 2 ) )
      oPDF:DrawText( oPDF:nRow+0.5, oPDF:MaxCol() / 6 * 4 + 1, 5, PicVal( 10, 0 ) )
      oPDF:DrawText( oPDF:nRow+0.5, oPDF:MaxCol() / 6 * 5 + 1, 6, PicVal( 10, 2 ) )
      oPDF:nRow += 1.5
      FOR nCont = 1 TO 6
         oPDF:DrawRetangle( oPDF:nRow - 0.5, ( nCont - 1 ) * oPDF:MaxCol() / 6, oPDF:MaxCol() / 6, 1.5 )
      NEXT
      oPDF:DrawText( oPDF:nRow,     oPDF:MaxCol() / 6 * 0 + 1, "FRETE",, oPDF:nFontSize / 2 )
      oPDF:DrawText( oPDF:nRow,     oPDF:MaxCol() / 6 * 1 + 1, "SEGURO",, oPDF:nFontSize / 2 )
      oPDF:DrawText( oPDF:nRow,     oPDF:MaxCol() / 6 * 2 + 1, "OUTROS",, oPDF:nFontSize /2 )
      oPDF:DrawText( oPDF:nRow,     oPDF:MaxCol() / 6 * 3 + 1, "DESC.NF",, oPDF:nFontSize /2 )
      oPDF:DrawText( oPDF:nRow,     oPDF:MaxCol() / 6 * 4 + 1, "PESO LÍQUIDO",, oPDF:nFontSize / 2 )
      oPDF:DrawText( oPDF:nRow,     oPDF:MaxCol() / 6 * 5 + 1, "VL.NOTA",, oPDF:nFontSize / 2 )
      oPDF:DrawText( oPDF:nRow+0.5, oPDF:MaxCol() / 6 * 0 + 1, 7, PicVal( 10, 2 ) )
      oPDF:DrawText( oPDF:nRow+0.5, oPDF:MaxCol() / 6 * 1 + 1, 8, PicVal( 10, 2 ) )
      oPDF:DrawText( oPDF:nRow+0.5, oPDF:MaxCol() / 6 * 2 + 1, 9, PicVal( 10, 2 ) )
      oPDF:DrawText( oPDF:nRow+0.5, oPDF:MaxCol() / 6 * 3 + 1, 10, PicVal( 10, 2 ) )
      oPDF:DrawText( oPDF:nRow+0.5, oPDF:MaxCol() / 6 * 4 + 1, 11, PicVal( 10, 0 ) )
      oPDF:DrawText( oPDF:nRow+0.5, oPDF:MaxCol() / 6 * 5 + 1, 12, PicVal( 10, 2 ) )
      oPDF:nRow += 1.5
      oPDF:DrawImage( "harbour.jpg", 20, 10, 40, 20 )
      oPDF:End()
   NEXT
   RETURN



FUNCTION PicVal( nLen, nDec )
   LOCAL cPicture
   
   nDec     := iif( nDec == NIL, 0, nDec )
   cPicture := Replicate( "9", nLen - nDec )
   cPicture := LTrim( Transform( Val( cPicture ), "999,999,999,999,999,999" ) )
   IF nDec != 0
      cPicture := cPicture + "." + Replicate( "9", nDec )
   ENDIF
   RETURN cPicture
 


João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7353
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Clase pdflib

Postby ruben Dario » Thu Sep 03, 2015 1:56 pm

Gracias Karina.

Pero debe faltar algo. Me da este error.

Code: Select all  Expand view

Error: Unresolved external '_HB_FUN_HPDF_NEW' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_SETCOMPRESSIONMODE' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_SETCURRENTENCODER' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_SAVETOFILE' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_FREE' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_SETINFOATTR' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_SETINFODATEATTR' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_ADDPAGE' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_PAGE_SETSIZE' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_PAGE_SETFONTANDSIZE' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_GETFONT' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_PAGE_SETRGBFILL' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_PAGE_SETRGBSTROKE' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_PAGE_BEGINTEXT' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_PAGE_SETTEXTMATRIX' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_PAGE_SHOWTEXT' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_PAGE_ENDTEXT' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_PAGE_SETLINEWIDTH' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_PAGE_MOVETO' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_PAGE_LINETO' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_PAGE_STROKE' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_LOADJPEGIMAGEFROMFILE' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_PAGE_DRAWIMAGE' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_PAGE_RECTANGLE' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_PAGE_FILL' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_PAGE_FILLSTROKE' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_PAGE_GETHEIGHT' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unresolved external '_HB_FUN_HPDF_PAGE_GETWIDTH' referenced from K:\V_XHARB_V3\OBJ_H\PXPPRUEBAS.OBJ
Error: Unable to perform link
 
Ruben Dario Gonzalez
Cali-Colombia
rubendariogd@hotmail.com - rubendariogd@gmail.com
User avatar
ruben Dario
 
Posts: 1061
Joined: Thu Sep 27, 2007 3:47 pm
Location: Colombia

Re: Clase pdflib

Postby karinha » Thu Sep 03, 2015 2:48 pm

Code: Select all  Expand view

* ZE_PDF - GERACAO DE PDF

* 2013.08.17.0000 - Inicio da definicao por Harupdf
* 2013.08.24.1548 - Substituicao do PDF
* 2013.09.01.0210 - Variaveis e metodos para relatorio
* 2013.09.02.1000 - Metodo PDF:Show()
* 2013.09.02.1235 - Proporcao de coluna pra 1.69
* 2013.09.06.0932 - Cores em array
* 2013.09.07.2031 - Proporcao 1.666
* 2013.09.19.1649 - Ajuste para quando nao imprime nada
*----------------------------------------------------------------

#require "hbhpdf"
#include "hbclass.ch"
#include "inkey.ch"

#define PDF_PORTRAIT  1
#define PDF_LANDSCAPE 2
#define PDF_TXT       3

CREATE CLASS PDFClass
   VAR    oPdf
   VAR    oPage
   VAR    cFileName         INIT ""
   VAR    nRow              INIT 999
   VAR    nCol              INIT 0
   VAR    nAngle            INIT 0
   VAR    cFontName         INIT "Courier"
   VAR    nFontSize         INIT 9
   VAR    nLineHeight       INIT 1.3
   VAR    nMargin           INIT 30
   VAR    nType             INIT 1
   VAR    nPdfPage          INIT 0
   VAR    nPageNumber       INIT 0
   VAR    cHeader           INIT {}
   VAR    cCodePage         INIT "CP1252"
   METHOD AddPage()
   METHOD RowToPDFRow( nRow )
   METHOD ColToPDFCol( nCol )
   METHOD MaxRow()
   METHOD MaxCol()
   METHOD DrawText( nRow, nCol, xValue, cPicture, nFontSize, cFontName, nAngle, anRGB )
   METHOD DrawLine( nRowi, nColi, nRowf, nColf, nPenSize )
   METHOD DrawRetangle( nTop, nLeft, nWidth, nHeight, nPenSize, nFillType, anRGB )
   METHOD DrawImage( cJPEGFile, nRow, nCol, nWidth, nHeight )
   METHOD Cancel()
   METHOD PrnToPdf( cInputFile )
   METHOD SetType( nType )
   METHOD PageHeader()
   METHOD MaxRowTest( nRows )
   METHOD SetInfo( cAuthor, cCreator, cTitle, cSubject )
   METHOD Begin()
   METHOD End()
   ENDCLASS

METHOD Begin() CLASS PDFClass
   IF ::nType > 2
      IF Empty( ::cFileName )
         ::cFileName := MyTempFile( "LST" )
      ENDIF
      SET PRINTER TO ( ::cFileName )
      SET DEVICE TO PRINT
   ELSE
      IF Empty( ::cFileName )
         ::cFileName := MyTempFile( "PDF" )
      ENDIF
      ::oPdf := HPDF_New()
      HPDF_SetCompressionMode( ::oPdf, HPDF_COMP_ALL )
//      ::cFontName := HPDF_LoadTTFontFromFile( ::oPDF, "c:\windows\fonts\cour.ttf", .t. )
      IF ::cCodePage != NIL
         HPDF_SetCurrentEncoder( ::oPDF, ::cCodePage )
      ENDIF
   ENDIF
   RETURN NIL
   
METHOD End() CLASS PDFClass
   IF ::nType > 2
      SET DEVICE TO SCREEN
      SET PRINTER TO
      RUN ( "cmd /c start notepad.exe " + ::cFileName )
      // fErase( ::cFileName )
   ELSE
      IF ::nPdfPage == 0
         ::AddPage()
         ::DrawText( 10, 10, "NENHUM CONTEUDO (NO CONTENT)",, ::nFontSize * 2 )
      ENDIF
      IF File( ::cFileName )
         fErase( ::cFileName )
      ENDIF
      HPDF_SaveToFile( ::oPdf, ::cFileName )
      HPDF_Free( ::oPdf )
      RUN ( "cmd /c start " + ::cFileName )
   ENDIF
   RETURN NIL
   
METHOD SetInfo( cAuthor, cCreator, cTitle, cSubject ) CLASS PDFClass
   IF ::nType > 2
      RETURN NIL
   ENDIF
   cAuthor  := iif( cAuthor == NIL, "JPA Tecnologia", cAuthor )
   cCreator := iif( cCreator == NIL, "Harupdf", cCreator )
   cTitle   := iif( cTitle == NIL, "", cTitle )
   cSubject := iif( cSubject == NIL, cTitle, cSubject )
   HPDF_SetInfoAttr( ::oPDF, HPDF_INFO_AUTHOR, cAuthor )
   HPDF_SetInfoAttr( ::oPDF, HPDF_INFO_CREATOR, cCreator )
   HPDF_SetInfoAttr( ::oPDF, HPDF_INFO_TITLE, cTitle )
   HPDF_SetInfoAttr( ::oPdf, HPDF_INFO_SUBJECT, cSubject )
   HPDF_SetInfoDateAttr( Year( Date() ), Month( Date() ), Day( Date() ), Val( Substr( Time(), 1, 2 ) ), Val( Substr( Time(), 4, 2 ) ), Val( Substr( Time(), 7, 2 ) ), "+", 4, 0 )
   RETURN NIL

METHOD SetType( nType ) CLASS PDFClass
   IF nType != NIL
      ::nType := nType
   ENDIF
   ::nFontSize := iif( ::nType == 1, 9, 6 )
   RETURN NIL
   
METHOD AddPage() CLASS PDFClass
   IF ::nType < 3
      ::oPage := HPDF_AddPage( ::oPdf )
      HPDF_Page_SetSize( ::oPage, HPDF_PAGE_SIZE_A4, iif( ::nType == 2, HPDF_PAGE_PORTRAIT, HPDF_PAGE_LANDSCAPE ) )
      HPDF_Page_SetFontAndSize( ::oPage, HPDF_GetFont( ::oPdf, ::cFontName, ::cCodePage ), ::nFontSize )
   ENDIF
   ::nRow := 0
   RETURN NIL
   
METHOD Cancel() CLASS PDFClass
   IF ::nType < 3
      HPDF_Free( ::oPdf )
   ENDIF
   RETURN NIL  
   
METHOD DrawText( nRow, nCol, xValue, cPicture, nFontSize, cFontName, nAngle, anRGB ) CLASS PDFClass
   LOCAL nRadian , cTexto
   nFontSize := iif( nFontSize == NIL, ::nFontSize, nFontSize )
   cFontName := iif( cFontName == NIL, ::cFontName, cFontName )
   cPicture  := iif( cPicture == NIL, "", cPicture )
   nAngle    := iif( nAngle == NIL, ::nAngle, nAngle )
   cTexto    := Transform( xValue, cPicture )
   ::nCol := nCol + Len( cTexto )
   IF ::nType > 2
      @ nRow, nCol SAY cTexto
   ELSE
      nRow := ::RowToPDFRow( nRow )
      nCol := ::ColToPDFCol( nCol )
      HPDF_Page_SetFontAndSize( ::oPage, HPDF_GetFont( ::oPdf, cFontName, ::cCodePage ), nFontSize )
      IF anRGB != NIL
         HPDF_Page_SetRGBFill( ::Page, anRGB[ 1 ], anRGB[ 2 ], anRGB[ 3 ] )
         HPDF_Page_SetRGBStroke( ::Page, anRGB[ 1 ], anRGB[ 2], anRGB[ 3] )
      ENDIF
      HPDF_Page_BeginText( ::oPage )
      nRadian := ( nAngle / 180 ) * 3.141592
      HPDF_Page_SetTextMatrix( ::oPage, Cos( nRadian ), Sin( nRadian ), -Sin( nRadian ), Cos( nRadian ), nCol, nRow )
      HPDF_Page_ShowText( ::oPage, cTexto )
      HPDF_Page_EndText( ::oPage )
      IF anRGB != NIL
         HPDF_Page_SetRGBFill( ::Page, 0, 0, 0 )
         HPDF_Page_SetRGBStroke( ::Page, 0, 0, 0 )
      ENDIF
   ENDIF
   RETURN NIL

METHOD DrawLine( nRowi, nColi, nRowf, nColf, nPenSize ) CLASS PDFClass
   IF ::nType > 2
      nRowi := Round( nRowi, 0 )
      nColi := Round( nColi, 0 )
      @ nRowi, nColi SAY Replicate( "-", nColf - nColi )
      ::nCol := Col()
   ELSE
      nPenSize := iif( nPenSize == NIL, 0.2, nPenSize )
      nRowi := ::RowToPDFRow( nRowi )
      nColi := ::ColToPDFCol( nColi )
      nRowf := ::RowToPDFRow( nRowf )
      nColf := ::ColToPDFCol( nColf )
      HPDF_Page_SetLineWidth( ::oPage, nPenSize )
      HPDF_Page_MoveTo( ::oPage, nColi, nRowi )
      HPDF_Page_LineTo( ::oPage, nColf, nRowf )
      HPDF_Page_Stroke( ::oPage )
   ENDIF
   RETURN NIL

METHOD DrawImage( cJPEGFile, nRow, nCol, nWidth, nHeight ) CLASS PDFClass
   LOCAL oImage
   IF ::nType > 2
      RETURN NIL
   ENDIF
   nRow    := ::RowToPDFRow( nRow )
   nCol    := ::ColToPDFCol( nCol )
   nWidth  := Int( nWidth * ::nFontSize / 1.666 )
   nHeight := nHeight * ::nFontSize
   //IF ValType( cLogoFile ) == "C"
      oImage := HPDF_LoadJPEGImageFromFile( ::oPdf, cJPEGFile )
   //ELSE
   //   oImage := HPDF_LoadJPEGImageFromMem( cJPEGFile )
   //   oImage := HPDF_LoadRawImageFromMem() // testar
   //ENDIF
   HPDF_Page_DrawImage( ::oPage, oImage, nCol, nRow, nWidth, nHeight )
   RETURN NIL

METHOD DrawRetangle( nTop, nLeft, nWidth, nHeight, nPenSize, nFillType, anRGB ) CLASS PDFClass
   IF ::nType > 2
      RETURN NIL
   ENDIF
   nFillType := iif( nFillType == NIL, 1, nFillType )
   nPenSize  := iif( nPenSize == NIL, 0.2, nPenSize )
   nTop      := ::RowToPDFRow( nTop )
   nLeft     := ::ColToPDFCol( nLeft )
   nWidth    := ( nWidth ) * ::nFontSize / 1.666
   nHeight   := -( nHeight ) * :: nFontSize
   HPDF_Page_SetLineWidth( ::oPage, nPenSize )
   IF anRGB != NIL
      HPDF_Page_SetRGBFill( ::oPage, anRGB[ 1 ], anRGB[ 2 ], anRGB[ 3 ] )
      HPDF_Page_SetRGBStroke( ::oPage, anRGB[ 1 ], anRGB[ 2 ], anRGB[ 3 ] )
   ENDIF
   HPDF_Page_Rectangle( ::oPage, nLeft, nTop, nWidth, nHeight )
   IF nFillType == 1
      HPDF_Page_Stroke( ::oPage )     // borders only
   ELSEIF nFillType == 2
      HPDF_Page_Fill( ::oPage )       // inside only
   ELSE
      HPDF_Page_FillStroke( ::oPage ) // all
   ENDIF
   IF anRGB != NIL
      HPDF_Page_SetRGBStroke( ::oPage, 0, 0, 0 )
      HPDF_Page_SetRGBFill( ::oPage, 0, 0, 0 )
   ENDIF
   RETURN NIL

METHOD RowToPDFRow( nRow ) CLASS PDFClass
   RETURN HPDF_Page_GetHeight( ::oPage ) - ::nMargin - ( nRow * ::nFontSize * ::nLineHeight )

METHOD ColToPDFCol( nCol ) CLASS PDFClass
   RETURN nCol * ::nFontSize / 1.666 + ::nMargin

METHOD MaxRow() CLASS PDFClass
   LOCAL nPageHeight, nMaxRow
   IF ::nType > 2
      RETURN 63
   ENDIF
   nPageHeight := HPDF_Page_GetHeight( ::oPage ) - ( ::nMargin * 2 )
   nMaxRow     := Int( nPageHeight / ( ::nFontSize * ::nLineHeight )  )
   RETURN nMaxRow

METHOD MaxCol() CLASS PDFClass
   LOCAL nPageWidth, nMaxCol
   IF ::nType > 2
      RETURN 132
   ENDIF
   nPageWidth := HPDF_Page_GetWidth( ::oPage ) - ( ::nMargin * 2 )
   nMaxCol    := Int( nPageWidth / ::nFontSize * 1.666 )
   RETURN nMaxCol

METHOD PrnToPdf( cInputFile ) CLASS PDFClass
   LOCAL cTxtReport, cTxtPage, cTxtLine, nRow
   cTxtReport := MemoRead( cInputFile ) + Chr(12)
   TokenInit( @cTxtReport, Chr(12) )
   DO WHILE .NOT. TokenEnd()
      cTxtPage := TokenNEXT( cTxtReport ) + HB_EOL()
      IF Len( cTxtPage ) > 5
         IF Substr( cTxtPage, 1, 1 ) == Chr(13)
            cTxtPage := Substr( cTxtPage, 2 )
         ENDIF
         ::AddPage()
         nRow := 0
         DO WHILE At( HB_EOL(), cTxtPage ) != 0
            cTxtLine := Substr( cTxtPage, 1, At( HB_EOL(), cTxtPage ) - 1 )
            cTxtPage := Substr( cTxtPage, At( HB_EOL(), cTxtPage ) + 2 )
            ::DrawText( nRow++, 0, cTxtLine )
         ENDDO
      ENDIF
   ENDDO
   RETURN NIL

METHOD PageHeader() CLASS PDFClass
   LOCAL nCont
   ::nPdfPage    += 1
   ::nPageNumber += 1
   ::nRow        := 0
   ::nCol        := 0
   ::AddPage()
   IF Len( ::cHeader ) != 0
      ::DrawText( 0, 0, "EMPRESA DE TESTE" )
      ::DrawText( 0, ( ::MaxCol() - Len( ::cHeader ) ) / 2, ::cHeader )
      ::DrawText( 0, ::MaxCol() - 12, "Folha " + StrZero( ::nPageNumber, 6 ) )
      ::DrawLine( 0.5, 0, 0.5, ::MaxCol() )
      ::nRow := 2
      ::nCol := 0
   ENDIF
   RETURN NIL
     
METHOD MaxRowTest( nRows ) CLASS PDFClass
   nRows := iif( nRows == NIL, 0, nRows )
   IF ::nRow > ::MaxRow() - 2 - nRows
      ::PageHeader()
   ENDIF
   RETURN NIL

FUNCTION TxtSaida()
   RETURN { "PDF Paisagem", "PDF Retrato", "Matricial" }

FUNCTION MyTempFile( cExtensao )
   RETURN "temp." + cExtensao
 


João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7353
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Clase pdflib

Postby ruben Dario » Thu Sep 03, 2015 3:33 pm

Gracias, Karina

Baje PDFClass.zip

con este si construi el ejeutable, sin ningun problema.
Lo baje de este link
[url]
http://www.pctoledo.com.br/forum/viewto ... 5&start=30
[/url]
Lo hace con hbmk2. Quisiera construir una libreria con esta clase, tu lo has hecho.
si miras aparece un c.bat y un test.hbp , tu sabes como hacer usando make si usar hbmk2

Gracias
Ruben Dario Gonzalez
Cali-Colombia
rubendariogd@hotmail.com - rubendariogd@gmail.com
User avatar
ruben Dario
 
Posts: 1061
Joined: Thu Sep 27, 2007 3:47 pm
Location: Colombia

Re: Clase pdflib

Postby karinha » Thu Sep 03, 2015 3:42 pm

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7353
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 24 guests