Exemplos de recibos em PDF

Projeto [x]Harbour - Compilador de código aberto compatível com o Clipper.

Moderador: Moderadores

Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Exemplos de recibos em PDF

Mensagem por Itamar M. Lins Jr. »

Ola!
Procurando por leiaute/exemplos de recibos em PDF, eu faço com HTML, mas neste caso vou usar arquivos BMP, fica inviável.
Tipo carnê... com códigos de barras e assinatura.

Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Exemplos de recibos em PDF

Mensagem por Itamar M. Lins Jr. »

Ola!
Vendo a classe pdfclass, mas não achei nenhum exemplo atualizado.
Visualiza o PDF sem instalar leitor ? O visualizador está embutido na lib harupdf ?

Código: Selecionar todos

function main
report5()
inkey(0)
return nil

STATIC FUNCTION Report5()
   FOR nType = 1 TO 3
      oPDF := PDFClass():New()
      oPDF:SetType( 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:DrawBox( 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:DrawBox( 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:DrawImageSize( 20, 10, 40, 20, "harbour.jpg" )
      oPDF:End(.t.)
   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   
Já mudei algumas linhas DrawRetangle para DrawBox, comentei a função DrawImageSize(), pois não acontecia nada...

Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Exemplos de recibos em PDF

Mensagem por JoséQuintas »

Itamar M. Lins Jr. escreveu:Visualiza o PDF sem instalar leitor ? O visualizador está embutido na lib harupdf ?
Aí que está....
Tem evitado o Windows 10.
O Windows 10 tem leitor próprio de PDF, não precisa instalar nada.

Acabei separando a PDFClass meio na correria, porque o Pritpal Bedi queria acrescentar alterações, mas acabei nem avisando ele que tinha separado....

Terminando algumas coisas, e em seguida vou verificar com calma.

Entendi que queria modelos visuais de recibo, e não modelos de fonte.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Exemplos de recibos em PDF

Mensagem por Itamar M. Lins Jr. »

Ola!
Agora, estudando a pdfclass, estou procurando exemplos.
Tem umas coisas que não estão funcionando na pdfclass, não salva o nome do arquivo por exemplo. Fica sempre "report.pdf"

Código: Selecionar todos

      oPDF:SetType( nType ) 
      oPDF:cFileName := "TEST5-" + Str( nType, 1 ) + "." + iif( nType < 3, "pdf", "lst" )
Já modificado pq tava dando erro no fonte, fora os links que não existem mais. Isso lá na seção "Dicas e Contribuições"
O Windows 10 tem leitor próprio de PDF, não precisa instalar nada.
Eu uso o win10, mas os clientes...2Gib de RAM, fica difícil. O firefox visualiza PDF "automagicamente"

Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Exemplos de recibos em PDF

Mensagem por JoséQuintas »

Usando a API do Windows vai abrir o aplicativo associado a PDF, seja qual for.
ShellExecute() ou algo assim.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Exemplos de recibos em PDF

Mensagem por Itamar M. Lins Jr. »

Ola!
Essa classe imprime em bobina ?
A principio é um recibo em A4.
E aproveitando posso usar também para bobina. Pq a winprn tem um bug não imprime em bobina corta o texto.
Parece que a tal

Código: Selecionar todos

oPrn :FormType    := WIN_DMPAPER_USER
não está funcionando.
Ou é falha no calculo das linhas...

Código: Selecionar todos

oPrn :PaperLength := 11*25.4*nTL
oPrn :PaperWidth  := 3*25.4*10
Sempre corta o papel(bobina) com 30cm e perde a impressão.

Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Exemplos de recibos em PDF

Mensagem por Itamar M. Lins Jr. »

Ola!
Não tem nada na classe. Metodo pdfrun, pdfpreview estão vazios.

Código: Selecionar todos

METHOD PDFRun( cFileName ) INLINE cFileName, cFileName 
METHOD Preview( cFileName, lCompress ) INLINE cFileName, lCompress
Deveria ter o winapi...shellexecute... mas ai dependeria da HbWin, linkada junto.

O problema principal é nome do PDF que a classe não está pegando.

Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
MSDN
Usuário Nível 4
Usuário Nível 4
Mensagens: 741
Registrado em: 28 Nov 2003 15:55
Localização: CWB
Contato:

Exemplos de recibos em PDF

Mensagem por MSDN »

Itamar, o Quintas já tinha até feito um exemplo anos atrás, veja :

http://pctoledo.com.br/forum/viewtopic. ... te#p118513

Só que quando clica não aparece nada, página não encontrada, talvez ele tenha backup disso, ou esteja em outra pasta no Git.
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7928
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

Exemplos de recibos em PDF

Mensagem por Itamar M. Lins Jr. »

Ola!
Pois é... Eu uso HTML faço tudo em HTML, porém alguns emails não aceitam JPG, BMP, embutido no HTML.
Como vamos fazer para enviar esses relatórios com imagens para o email ? Parece que o padrão é o PDF. A não ser uma foto da tela, mas a impressão fica a desejar.

Saudações,
Itamar M. Lins Jr.
Saudações,
Itamar M. Lins Jr.
MSDN
Usuário Nível 4
Usuário Nível 4
Mensagens: 741
Registrado em: 28 Nov 2003 15:55
Localização: CWB
Contato:

Exemplos de recibos em PDF

Mensagem por MSDN »

Estava pesquisando rapidamente sobre esse assunto, e vi que o Quintas falou sobre o Pritpal estar vendo a classe tbem para geração de PDF, se ficasse como parte do projeto Harbour seria uma boa, e pensando mais além, eu que estudo Flutter, pensei, se o Harbour gera binários para vários SO's, se fosse criada uma classe principal ( TObject ) e algumas outras classes para coisas básicas, janela, botão, grid, etc, seria o ideal para programar graficamente em Windows, Linux, Unix, Mac, Android, Ios, etc..., e se quem tem conhecimento a fundo no Harbour ( Viktor por exemplo ) implementasse a arquitetura REST, imagina o que teríamos !
Fernando queiroz
Usuário Nível 4
Usuário Nível 4
Mensagens: 779
Registrado em: 13 Nov 2014 00:41
Localização: Porto Alegre/RS

Exemplos de recibos em PDF

Mensagem por Fernando queiroz »

Código: Selecionar todos

/*
ZE_PDFCLASS - GERACAO DE PDF
José Quintas
*/

// Calculo da folha: cm * 0.03937 * 72
// onde cm = medida em cm
// 0.03937 = fator de conversao de mm para polegadas
// 72 = resolucao DPI default do PDF
// HPDF_Page_SetWidth( oPage, nResultado )
// HPDF_Page_SetHeight( oPage, nResultado )
// TODO: As medidas da página só estão disponíveis após existir uma página

#require "hbhpdf.hbc"
#require "hbct.hbc"


#include "hbclass.ch"
#include "inkey.ch"
#include "hwgui.ch"

#define PDFCLASS_DRAWMODE_ROWCOL     1
#define PDFCLASS_DRAWMODE_CENTIMETER 2
#define PDFCLASS_DRAWMODE_PIXEL      3

#define PDFCLASS_PORTRAIT  1
#define PDFCLASS_LANDSCAPE 2
#define PDFCLASS_TXT       3
#define PDFCLASS_ROLLS     4

#define PDFCLASS_PENSIZE 0.5

CREATE CLASS PDFClass

   VAR    oPdf
   VAR    oPage
   VAR    nPageWidth        INIT 595.28  // A4
   VAR    nPageHeight       INIT 841.89  // A4
   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    nTopMargin        INIT 25
   VAR    nLeftMargin       INIT 25
   VAR    nBottomMargin     INIT 25
   VAR    nRightMargin      INIT 25
   VAR    nPrinterType      INIT PDFCLASS_PORTRAIT
   VAR    nPdfPage          INIT 0
   VAR    nPageNumber       INIT 0
   VAR    acHeader          INIT {}
   VAR    cCodePage         INIT "WinAnsiEncoding" // "CP1252"
   VAR    nDrawMode         INIT PDFCLASS_DRAWMODE_ROWCOL
   VAR    lDrawZebrado      INIT .F.
   VAR    cAppEmpresaNome   INIT ""
   VAR    cDefaultPrinter   INIT WIN_PRINTERGETDEFAULT()
   
   METHOD AddPage()
   METHOD RowToPDFRow( nValue )
   METHOD ColToPDFCol( nValue )
   METHOD MaxRow()
   METHOD MaxCol()
   METHOD Row( nAddRows )
   METHOD Col( nAddCols )
   METHOD DrawBoxTitleText( nTop, nLeft, nBottom, nRight, cTitle, cText, cPicture, nAlign, nFontSizeText, cFontNameText, nFontSizeTitle, cFontNameTitle )
   METHOD DrawText( nTop, nLeft, xValue, cPicture, nFontSize, cFontName, nAngle, anRGB )
   METHOD DrawLine( nTop, nLeft, nBottom, nRight, nPenSize )
   METHOD DrawBox( nTop, nLeft, nBottom, nRight, nPenSize, nFillType, anRGB )
   METHOD DrawBoxSize( nTop, nLeft, nHeight, nWidth, nPenSize, nFillType, anRGB )
   METHOD DrawImageBox( nTop, nLeft, nBottom, nRight, cJPEGFile )
   METHOD DrawImageSize( nRow, nCol, nHeight, nWidth, cJPEGFile )
   METHOD DrawMemImageBox( nTop, nLeft, nBottom, nRight, cJPEGMem )
   METHOD DrawMemImageSize( nRow, nCol, nHeight, nWidth, cJPEGMem )
   METHOD Cancel()
   METHOD PrnToPdf( cInputFile )
   METHOD SetType( nPrinterType )
   METHOD PageHeader()
   METHOD PageFooter()
   METHOD MaxRowTest( nRows )
   METHOD SetInfo( cAuthor, cCreator, cTitle, cSubject )
   METHOD Begin()
   METHOD End( lPreview )
   METHOD DrawZebrado( nNivel, lDraw )
   METHOD SelectPrinterType( nPrinterType )
   METHOD PrintOptions(  )
   METHOD PrintPreview(  )

   ENDCLASS

METHOD Row( nAddRows ) CLASS PDFCLass

   IF nAddRows != NIL
      ::nRow += nAddRows
      ::MaxRowTest()
   ENDIF

   RETURN ::nRow

METHOD Col( nAddCols ) CLASS PDFClass

   IF nAddCols != NIL
      ::nCol += nAddCols
   ENDIF

   RETURN ::nCol

METHOD Begin() CLASS PDFClass

   IF ::nPrinterType == PDFCLASS_TXT
//      ::cFileName := MyTempFile( "LST" )
      SET PRINTER TO ( ::cFileName )
      SetPrc( 0, 0 )
      SET DEVICE TO PRINT
   ELSE
//      ::cFileName := MyTempFile( "PDF" )
      ::oPdf := HPDF_New()
      HPDF_SetCompressionMode( ::oPDF, HPDF_COMP_ALL )
      HPDF_SetCurrentEncoder( ::oPDF, ::cCodePage )
      //HPDF_SetPassword( ::oPDF, "owner", "" )
      //HPDF_SetPermission( ::oPDF, HPDF_ENABLE_READ + HPDF_ENABLE_PRINT ) // + HPDF_ENABLE_EDIT_ALL + HPDF_ENABLE_COPY + HPDF_ENABLE_EDIT )
      ::SetInfo()
   ENDIF

   RETURN NIL

METHOD End( lPreview ) CLASS PDFClass

   hb_Default( @lPreview, .T. )
   ::PageFooter()
//   Mensagem()
   IF ::nPrinterType == PDFCLASS_TXT
      SET PRINTER TO
      SET DEVICE TO SCREEN
      SetPrc(0,0)
      IF lPreview
//         PrintPreview( ::cFileName, ( ::nPageWidth == 132 ) ) // compress=true for 132 cols
         fErase( ::cFileName )
      ELSE
         PrintBegin()
         @ 0,0 SAY MemoRead( ::cFileName )
         PrintEnd()
         fErase( ::cFileName )
      ENDIF
   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 )
//      ShellExecuteOpen( ::cFileName )
//	  WAPI_ShellExecute( NIL, "OPEN", ::cFileName , NIL,, NIL )
   ENDIF

   RETURN NIL

METHOD SetInfo( cAuthor, cCreator, cTitle, cSubject ) CLASS PDFClass

   IF ::nPrinterType == PDFCLASS_TXT
      RETURN NIL
   ENDIF
   hb_Default( @cAuthor, "SGC Sistemas" )
   hb_Default( @cCreator, "Harupdf" )
   hb_Default( @cTitle, "SGC" )
   hb_Default( @cSubject, cTitle )
   IF ! Empty( cAuthor )
      HPDF_SetInfoAttr( ::oPDF, HPDF_INFO_AUTHOR, cAuthor )
   ENDIF
   IF ! Empty( cCreator )
      HPDF_SetInfoAttr( ::oPDF, HPDF_INFO_CREATOR, cCreator )
   ENDIF
   IF ! Empty( cTitle )
      HPDF_SetInfoAttr( ::oPDF, HPDF_INFO_TITLE, cTitle )
   ENDIF
   IF ! Empty( cSubject )
      HPDF_SetInfoAttr( ::oPdf, HPDF_INFO_SUBJECT, cSubject )
   ENDIF
   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( nPrinterType ) CLASS PDFClass

   IF nPrinterType != NIL
      ::nPrinterType := nPrinterType
   ENDIF
   DO CASE
   CASE ::nPrinterType == PDFCLASS_PORTRAIT
      ::nFontSize   := 9
      ::nPageWidth  := 841.89 // A4
      ::nPageHeight := 595.28 // A4
   CASE ::nPrinterType == PDFCLASS_LANDSCAPE
      ::nFontSize   := 6
      ::nPageWidth  := 595.28 // A4
      ::nPageHeight := 841.89 // A4
   CASE ::nPrinterType == PDFCLASS_TXT
      ::nPageWidth  := 132
      ::nPageHeight := 66
	CASE ::nPrinterType ==  PDFCLASS_ROLLS
      ::nFontSize   	:= 9
      ::nPageWidth  	:= 226.77 // ROLLS
      ::nPageHeight 	:= 836.22 // ROLLS
	  ::nLeftMargin 	:= 10
	  ::nRightMargin	:= 10
	  ::nTopMargin		:= 7
	  ::nBottomMargin 	:= 7
   ENDCASE

   RETURN NIL

   /*
   Note: rotate page is bad for screen, better to use automatic adjust when print
   */

METHOD AddPage() CLASS PDFClass

   IF ::nPrinterType != PDFCLASS_TXT
      ::oPage := HPDF_AddPage( ::oPdf )
      //      // HPDF_Page_SetSize( ::oPage, HPDF_PAGE_SIZE_A4, iif( ::nPrinterType == PDFCLASS_LANDSCAPE, HPDF_PAGE_PORTRAIT, HPDF_PAGE_LANDSCAPE ) )
      //      IF ::nPrinterType == PDFCLASS_PORTRAIT
      //         HPDF_Page_SetWidth( ::oPage, ::nPageHeight )
      //         HPDF_Page_SetHeight( ::oPage, ::nPageWidth )
      //         //HPDF_Page_SetRotate( ::oPage, iif( ::nPrinterType == PDFCLASS_LANDSCAPE, 0, 90 ) )
      //      ELSE
      HPDF_Page_SetWidth( ::oPage, ::nPageWidth )
      HPDF_Page_SetHeight( ::oPage, ::nPageHeight )
      //      ENDIF
      HPDF_Page_SetFontAndSize( ::oPage, HPDF_GetFont( ::oPdf, ::cFontName, ::cCodePage ), ::nFontSize )
   ENDIF
   ::nRow := 0

   RETURN NIL

METHOD Cancel() CLASS PDFClass

   IF ::nPrinterType != PDFCLASS_TXT
      HPDF_Free( ::oPdf )
   ENDIF

   RETURN NIL

METHOD DrawBoxTitleText( nTop, nLeft, nBottom, nRight, cTitle, cText, cPicture, nAlign, nFontSizeText, cFontNameText, nFontSizeTitle, cFontNameTitle ) CLASS PDFClass

   hb_Default( @nFontSizeTitle, 6 )
   hb_Default( @cFontNameTitle, ::cFontName )
   hb_Default( @nFontSizeText, ::nFontSize )
   hb_Default( @cFontNameText, ::cFontName )
   hb_Default( @cPicture, "" )
   hb_Default( @nAlign, HPDF_TALIGN_LEFT )

   ::DrawBox( nTop, nLeft, nBottom, nRight )
   cText   := Transform( cText, cPicture )
   ::nCol  := nRight
   nTop    := ::RowToPDFRow( nTop )
   nLeft   := ::ColToPDFCol( nLeft )
   nBottom := ::RowToPDFRow( nBottom )
   nRight  := ::ColToPDFCol( nRight )

   HPDF_Page_SetFontAndSize( ::oPage, HPDF_GetFont( ::oPDF, cFontNameTitle, ::cCodePage ), nFontSizeTitle )
   HPDF_Page_BeginText( ::oPage )
   HPDF_Page_TextRect( ::oPage, nLeft + 2, nTop, nRight - 2, nBottom, cTitle, nAlign, NIL )
   HPDF_Page_EndText( ::oPage )

   HPDF_Page_SetFontAndSize( ::oPage, HPDF_GetFont( ::oPDF, cFontNameText, ::cCodePage ), nFontSizeText )
   HPDF_Page_BeginText( ::oPage )
   HPDF_Page_TextRect( ::oPage, nLeft + 2, nTop - nFontSizeTitle - 1, nRight - 2, nBottom, cText, nAlign, NIL )
   HPDF_Page_EndText( ::oPage )

   RETURN NIL

METHOD DrawText( nTop, nLeft, xValue, cPicture, nFontSize, cFontName, nAngle, anRGB ) CLASS PDFClass

   LOCAL nRadian , cTexto

   hb_Default( @nFontSize, ::nFontSize )
   hb_Default( @cFontName, ::cFontName )
   hb_Default( @cPicture, "" )
   hb_Default( @nAngle, ::nAngle )

   cTexto  := Transform( xValue, cPicture )
   ::nCol  := nLeft + Len( cTexto )
   IF ::nPrinterType == PDFCLASS_TXT
      @ nTop, nLeft SAY cTexto
   ELSE
      nTop  := ::RowToPDFRow( nTop )
      nLeft := ::ColToPDFCol( nLeft )
      HPDF_Page_SetFontAndSize( ::oPage, HPDF_GetFont( ::oPdf, cFontName, ::cCodePage ), nFontSize )
      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_BeginText( ::oPage )
      nRadian := ( nAngle / 180 ) * 3.141592
      HPDF_Page_SetTextMatrix( ::oPage, Cos( nRadian ), Sin( nRadian ), -Sin( nRadian ), Cos( nRadian ), nLeft, nTop )
      HPDF_Page_ShowText( ::oPage, cTexto )
      HPDF_Page_EndText( ::oPage )
      IF anRGB != NIL
         HPDF_Page_SetRGBFill( ::oPage, 0, 0, 0 )
         HPDF_Page_SetRGBStroke( ::oPage, 0, 0, 0 )
      ENDIF
   ENDIF

   RETURN NIL

METHOD DrawLine( nTop, nLeft, nBottom, nRight, nPenSize ) CLASS PDFClass

   IF ::nPrinterType == PDFCLASS_TXT
      IF nTop == nBottom // Matrix can draw line in a single row
         nTop  := Round( nTop, 0 )
         nLeft := Round( nLeft, 0 )
         @ nTop, nLeft SAY Replicate( "-", nRight - nLeft )
         ::nCol := Col()
      ENDIF
   ELSE
      hb_Default( @nPenSize, PDFCLASS_PENSIZE )
      nTop     := ::RowToPDFRow( nTop )
      nLeft    := ::ColToPDFCol( nLeft )
      nBottom  := ::RowToPDFRow( nBottom )
      nRight   := ::ColToPDFCol( nRight )
      HPDF_Page_SetLineWidth( ::oPage, nPenSize )
      HPDF_Page_MoveTo( ::oPage, nLeft, nTop )
      HPDF_Page_LineTo( ::oPage, nRight, nBottom )
      HPDF_Page_Stroke( ::oPage )
   ENDIF

   RETURN NIL

METHOD DrawImageBox( nTop, nLeft, nBottom, nRight, cJPEGFile ) CLASS PDFClass

   LOCAL oImage, nWidth, nHeight

   IF ::nPrinterType == PDFCLASS_TXT // .OR. ! File( cJPEGFile )
      RETURN NIL
   ENDIF
   nWidth  :=  ::ColToPdfCol( nRight - nLeft ) - ::ColToPdfCol( 0 )
   nHeight := ( ::RowToPdfRow( 0 ) - ::RowToPdfRow( nBottom - nTop ) )
   nBottom := ::RowToPDFRow( nBottom )
   nLeft   := ::ColToPdfCol( nLeft )
   oImage  := HPDF_LoadJPEGImageFromFile( ::oPdf, cJPEGFile )
   HPDF_Page_DrawImage( ::oPage, oImage, nLeft, nBottom, nWidth, nHeight )

   RETURN NIL

METHOD DrawImageSize( nRow, nCol, nHeight, nWidth, cJPEGFile ) CLASS PDFClass

   ::DrawImageBox( nRow, nCol, nRow + nHeight, nCol + nWidth, cJPEGFile )

   RETURN NIL

METHOD DrawMemImageBox( nTop, nLeft, nBottom, nRight, cJPEGMem ) CLASS PDFClass

   LOCAL oImage, nWidth, nHeight

   IF ::nPrinterType == PDFCLASS_TXT
      RETURN NIL
   ENDIF
   IF cJPEGMem == NIL
      RETURN NIL
   ENDIF
   nWidth  :=  ::ColToPdfCol( nRight - nLeft ) - ::ColToPdfCol( 0 )
   nHeight := ( ::RowToPdfRow( 0 ) - ::RowToPdfRow( nBottom - nTop ) )
   nBottom := ::RowToPDFRow( nBottom )
   nLeft   := ::ColToPdfCol( nLeft )
   oImage  := HPDF_LoadJPEGImageFromMem( ::oPDF, cJPEGMem, Len( cJPEGMem ) )
   HPDF_Page_DrawImage( ::oPage, oImage, nLeft, nBottom, nWidth, nHeight )

   RETURN NIL

METHOD DrawMemImageSize( nRow, nCol, nHeight, nWidth, cJPEGMem ) CLASS PDFClass

   ::DrawMemImageBox( nRow, nCol, nRow + nHeight, nCol + nWidth, cJPEGMem )

   RETURN NIL

METHOD DrawBox( nTop, nLeft, nBottom, nRight, nPenSize, nFillType, anRGB ) CLASS PDFClass

   LOCAL nWidth, nHeight

   IF ::nPrinterType == PDFCLASS_TXT
      RETURN NIL
   ENDIF
   hb_Default( @nFillType, 1 )
   hb_Default( @nPenSize, PDFCLASS_PENSIZE )
   nWidth    := nRight - nLeft
   nHeight   := nBottom - nTop
   nTop      := ::RowToPDFRow( nTop )
   nLeft     := ::ColToPDFCol( nLeft )
   nWidth    := ::ColToPdfCol( nWidth ) - ::ColToPdfCol( 0 )
   nHeight   := -( ::RowToPdfRow( 0 ) - ::RowToPdfRow( nHeight ) )
   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 DrawBoxSize( nTop, nLeft, nHeight, nWidth, nPenSize, nFillType, anRGB ) CLASS PDFClass

   ::DrawBox( nTop, nLeft, nTop + nHeight, nLeft + nWidth, nPenSize, nFillType, anRGB )

   RETURN NIL

METHOD RowToPDFRow( nValue ) CLASS PDFClass

   DO CASE
   CASE ::nDrawMode == PDFCLASS_DRAWMODE_ROWCOL
      nValue := ::nPageHeight - ::nBottomMargin - ( nValue * ::nFontSize * ::nLineHeight )
   CASE ::nDrawMode == PDFCLASS_DRAWMODE_CENTIMETER
      nValue := ::nPageHeight - ( nValue * 2.83464 )
   CASE ::nDrawMode == PDFCLASS_DRAWMODE_PIXEL
      nValue := ::nPageHeight - nValue
   ENDCASE

   RETURN nValue

METHOD ColToPDFCol( nValue ) CLASS PDFClass

   DO CASE
   CASE ::nDrawMode == PDFCLASS_DRAWMODE_ROWCOL
      nValue := nValue * ::nFontSize / 1.666 + ::nLeftMargin
   CASE ::nDrawMode == PDFCLASS_DRAWMODE_CENTIMETER
      nValue := nValue * 2.83464 // 72 * 0.03937
   CASE ::nDrawMode == PDFCLASS_DRAWMODE_PIXEL
      // Nothing to do
   ENDCASE

   RETURN nValue

METHOD MaxRow() CLASS PDFClass

   LOCAL nPageHeight, nMaxRow

   IF ::nPrinterType == PDFCLASS_TXT
      RETURN 63
   ENDIF
   nPageHeight := ::nPageHeight - ::nTopMargin - ::nBottomMargin
   nMaxRow     := Int( nPageHeight / ( ::nFontSize * ::nLineHeight )  )

   RETURN nMaxRow

METHOD MaxCol() CLASS PDFClass

   LOCAL nPageWidth, nMaxCol

   IF ::nPrinterType == PDFCLASS_TXT
      RETURN ::nPageWidth
   ENDIF
   nPageWidth := ::nPageWidth - ::nRightMargin - ::nLeftMargin
   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 ! 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

   IF Len( ::acHeader ) > 0
      IF ::nPageNumber != 0 .AND. ::nRow != 0 .AND. ::nPdfPage != 0
         ::PageFooter()
      ENDIF
   ENDIF
   ::nPdfPage    += 1
   ::nPageNumber += 1
   ::nRow        := 0
//   Mensagem( "Impressão em andamento, folha " + StrZero( ::nPageNumber, 7 ) )
   ::AddPage()
   IF Len( ::acHeader ) > 0
      ::DrawText( 0, 0, ::cAppEmpresaNome )
      ::DrawText( 0, ( ::MaxCol() - Len( ::acHeader[ 1 ] ) ) / 2, ::acHeader[ 1 ] )
      ::DrawText( 0, ::MaxCol() - 12, "Folha " + StrZero( ::nPageNumber, 6 ) )
      ::DrawLine( 0.5, 0, 0.5, ::MaxCol() )
      ::nRow := 2
      IF Len( ::acHeader ) > 1
         FOR nCont = 2 TO Len( ::acHeader )
            IF ! Empty( ::acHeader[ nCont ] )
               IF nCont == 2
                  ::DrawText( ::nRow++, 0, Padc( AllTrim( ::acHeader[ 2 ] ), ::MaxCol() ) )
               ELSE
                  ::DrawText( ::nRow++, 0, ::acHeader[ nCont ] )
               ENDIF
            ENDIF
         NEXT
         ::DrawLine( ::nRow - 0.5, 0, ::nRow++ - 0.5, ::MaxCol() )
         ::nRow++
      ENDIF
   ENDIF
   ::nCol := 0

   RETURN NIL

METHOD PageFooter() CLASS PDFClass

   LOCAL cTxt
   MEMVAR m_Prog

   IF Len( ::acHeader ) != 0 .AND. ::nPdfPage != 0 // adicionada checagem de nPdfPage
      cTxt := "JPA/" + m_Prog + "/" + Right( Dtos( Date() ), 6 ) + SoNumeros( Time() )
      ::DrawLine( ::MaxRow(), 0, ::MaxRow(), ::MaxCol() - Len( cTxt ) )
      ::DrawText( ::MaxRow(), ::MaxCol() - Len( cTxt ), cTxt )
   ENDIF

   RETURN NIL

METHOD MaxRowTest( nRows ) CLASS PDFClass

   hb_Default( @nRows, 0 )
   IF ::nRow > ::MaxRow() - 2 - nRows
      ::PageHeader()
   ENDIF

   RETURN NIL

METHOD DrawZebrado( nNivel, lDraw ) CLASS PDFClass

   LOCAL nColor

   hb_Default( @nNivel, 1 )
   hb_Default( @lDraw, .F. )
   nNivel := iif( nNivel < 1, 1, iif( nNivel > 5, 5, nNivel ) )
   nColor := ( 10 - nNivel ) / 10   // 0.9, 0.8, 0.7, 0.6
   IF nNivel != 1 .OR. ::lDrawZebrado .OR. lDraw
      ::DrawBox( ::nRow - 1 + 0.3, 0, ::nRow + 0.3, ::MaxCol(), 0.2, 2, { nColor, nColor, nColor } )
   ENDIF
   IF ! lDraw
      ::lDrawZebrado := ! ::lDrawZebrado
   ENDIF

   RETURN NIL

METHOD SelectPrinterType( nPrinterType ) CLASS PDFClass

//   wAchoice( 5, 10, txtSaida(), @nPrinterType, "Formato de Saída" )
   ::SetType( nPrinterType )

   RETURN ( LastKey() != K_ESC )

FUNCTION TxtSaida()

   RETURN { "PDF Paisagem", "PDF Retrato", "Matricial" }

FUNCTION ConfirmaImpressao()

   LOCAL lPrint

   lPrint := hwg_MsgYesNo( "Confirma a impressão?" )
//   IF lPrint
//      Mensagem( "Relatório sendo efetuado... ESC interrompe" )
//   ENDIF

   RETURN lPrint

FUNCTION PrintSelect( cImpressora )

   LOCAL acPrinterList, nOpc := 1, lOk, nCont

   acPrinterList := Win_PrinterList()
   FOR nCont = 1 TO Len( acPrinterList )
      IF acPrinterList[ nCont ] == Win_PrinterGetDefault()
         nOpc := nCont
         EXIT
      ENDIF
   NEXT
//   WAchoice( 6, Int( MaxCol() / 4 ), acPrinterList, @nOpc, "Impressora" )
   lOk := ( LastKey() != K_ESC )
   IF lOk
      cImpressora := acPrinterList[ nOpc ]
      hwg_Exclamation( cImpressora )
      // Win_PrinterSetDefault( acPrinterList[ nOpc ] )
   ENDIF

   RETURN lOk

   /*
   STATIC FUNCTION PrintRaw( cFileTxt, cReportName )

   LOCAL cPrinter := ""

   hb_Default( @cReportName, "win_PrintFileRaw" )
   cPrinter := Win_PrintDlgDc( @cPrinter,,, )
   IF ! Empty( cPrinter )
   Win_PrintFileRaw( cPrinter, cFileTxt, cReportName )
   ENDIF

   RETURN NIL
   */

FUNCTION AppPrinterType( xValue )

   STATIC AppPrinterType := PDFCLASS_PORTRAIT

   IF xValue != NIL .AND. xValue > 0 .AND. xValue <= Len( TxtSaida() )
      AppPrinterType := xValue
   ENDIF

   RETURN AppPrinterType
   
   
FUNCTION PrintBegin()

   SET DEVICE TO PRINT
   SetPRC( 0, 0 )

   RETURN NIL

FUNCTION PrintEnd()

   SET DEVICE TO SCREEN
   SET PRINTER TO
   SetPRC( 0, 0 )

   RETURN NIL
   
METHOD PrintPreview(  ) CLASS PDFClass
	IF ! EMPTY(::cDefaultPrinter)
		WAPI_ShellExecute(NIL, 'OPEN', hb_Dirbase()+'SUMATRA\SumatraPDF.EXE', '"' + ::cFileName + '" -print-to "' + ::cDefaultPrinter + '"',, NIL )
//		WAPI_ShellExecute(NIL, 'PRINT', '"' + ::cFileName + '"', '"'  + ::cDefaultPrinter + '"',, NIL )
	ELSE
		WAPI_ShellExecute( NIL, "OPEN", ::cFileName , NIL,, NIL )	
	ENDIF
return nil



METHOD PrintOptions(  ) CLASS PDFClass

LOCAL oDlg;
	, oLabel1;
	, oCombo1, oCombo2;
	, vCombo1;
	, nCombo2;
	, oLabel2;
	, oOwnerbutton2, oOwnerbutton1 ;
	, aPrn := Win_PrinterList( .t., .f. );
	, iCarga;
	, oBitmap1; 
	, oLabel3;
	

//	IF Empty( aPrn )
//		IF hwg_MsgYesNo( "ATENÇÃO !!! Não foi possivel localizar Nenhuma impressora Instalada no Windows, Deseja Instalar uma Agora ?", "Aviso do Sistema" )
//			RunApplet_imp( "AddPrinter" )
//		ENDIF
//		RETURN nil
//	ENDIF
	for iCarga=1 to len(aPrn)
		IF aPrn[iCarga,1] = WIN_PRINTERGETDEFAULT()
			::cDefaultPrinter := WIN_PRINTERGETDEFAULT()
			vCombo1:=iCarga
			exit
		ENDIF
	next


 
	INIT DIALOG oDlg TITLE "Impressão de Relatórios"  ;
		ICON HIcon():Addresource('SGC_ICON')  ;
		AT 0,0 SIZE 658,215 CLIPPER  NOEXIT  
		
	@ 21,48 BITMAP oBitmap1  SHOW 'REL_PRINT' FROM RESOURCE TRANSPARENT STRETCH 0  ;
         SIZE 90,90
	@ 18,6 SAY oLabel1 CAPTION "INFORME AS OPÇÕES DE IMPRESSÃO"  SIZE 644,22 ;
        STYLE SS_CENTER    ;
        FONT HFont():Add( '',0,-16,700,,,) 

	@ 120,50 SAY oLabel3 CAPTION "Impressora:"  SIZE 118,24 ;
		STYLE SS_CENTER +WS_DLGFRAME 	

	@ 252,50 GET COMBOBOX oCombo1 VAR vCombo1  ITEMS aPRN  SIZE 375,24 ;
			ON CHANGE {|| ::cDefaultPrinter := Alltrim(aPrn[vCombo1,1] ) }


	@ 252,85 GET COMBOBOX oCombo2 VAR nCombo2 ;
        ITEMS {"Relatório Bobina (40 col)","Relatório A4 (80 col)"}  SIZE 226,24 
 		
	@ 120,85 SAY oLabel2 CAPTION "Formato:"  SIZE 118,24 ;
		STYLE SS_CENTER +WS_DLGFRAME 	

	@ 404,145 OWNERBUTTON oOwnerbutton1  SIZE 98,32   ;
        TEXT 'Visualizar'  ;
        COORDINATES 28, 0, 0, 0  ;
        BITMAP 'print_preview' FROM RESOURCE TRANSPARENT;
        COORDINATES 5, 0, 0, 0;
		ON CLICK {|| IIF(nCombo2 = 1, ::SetType( PDFCLASS_ROLLS ), ::SetType( PDFCLASS_LANDSCAPE )),hwg_Enddialog(), oDlg:lresult:=.T., ::cDefaultPrinter := ""  }

   
	@ 525,145 OWNERBUTTON oOwnerbutton2  SIZE 98,32   ;
        TEXT 'Imprimir'  ;
        COORDINATES 30, 0, 0, 0  ;
        BITMAP 'print_impressora' FROM RESOURCE TRANSPARENT;
        COORDINATES 5, 0, 0, 0;
		ON CLICK {|| IIF(nCombo2 = 1, ::SetType( PDFCLASS_ROLLS ), ::SetType( PDFCLASS_LANDSCAPE )),hwg_Enddialog(), oDlg:lresult:=.T. }

	ACTIVATE DIALOG oDlg CENTER


RETURN oDlg:lresult

ITAMAR fiz as alterações para funcionar com bobina , ta redondinha, tem alguns ajustes pessoais mas da para usar
HARBOUR 3.2, HWGUI 2.23 B3, SEFAZCLASS, PDFClass, ADO + MariaDB/MySQL, RMChart
Fernando queiroz
Usuário Nível 4
Usuário Nível 4
Mensagens: 779
Registrado em: 13 Nov 2014 00:41
Localização: Porto Alegre/RS

Exemplos de recibos em PDF

Mensagem por Fernando queiroz »

Código: Selecionar todos

#define PDFCLASS_PORTRAIT  1
#define PDFCLASS_LANDSCAPE 2
#define PDFCLASS_TXT       3
#define PDFCLASS_ROLLS     4
************************************************************
STATIC FUNCTION RELATORIO_PRODUTOS_1( )
************************************************************ 


	oPDF := PDFClass()
	IF oPDF == NIL
		hwg_msginfo("Falha da criação do objeto PDF")
		RETURN .F.
	ENDIF
	oPDF:cFileName 	:= "C:\TEMP\PRODUTOS"+strzero(HB_RandomInt(1, 99999999),8,0)+'.PDF'
	IF ! oPDF:PrintOptions(  ); RETURN NIL; ENDIF 
	
	DBSELECTAREA("PRODUTOS")
	Ordsetfocus(2)
	PRODUTOS->( DBGOTOP() )
	
	
	IF  oPDF:nPrinterType ==  PDFCLASS_LANDSCAPE
		
		oPDF:Begin()

		nLinha	:= 100
		nPagina := 1
		
		DO WHILE ! EOF()
			IF 	nLinha	> 96
				oPDF:AddPage()
				
				nMaxCol := oPDF:MaxCol()
				nMaxRow := oPDF:MaxRow()

				oPDF:DrawBox( 0, 0, 9, 41, Nil, Nil, Nil )                 // box esquerdo
				oPDF:DrawImageSize( 0.5, 0.5, 8, 39, "logotipo.jpg" )             // logotipo

				oPDF:DrawBox( 0, 41, 9, 117, Nil, Nil, Nil )  // box centro
				oPDF:DrawText( 2.0, 42, RTRIM(FLAG->n_xNome), nil, 10, "Helvetica-Bold", Nil, Nil )
				oPDF:DrawText( 3.5, 42, RTRIM(FLAG->n_xLgr) + ', ' + RTRIM(FLAG->n_nro), Nil, 8, "Helvetica", Nil, Nil )
				oPDF:DrawText( 5.0, 42,'BAIRRO - ' + RTRIM(FLAG->n_xBairro), Nil, 8, "Helvetica", Nil, Nil )
				oPDF:DrawText( 6.4, 42, "CEP " +FLAG->n_CEP + ' - ' + RTRIM(FLAG->n_xMun) + ' - ' + FLAG->n_xUF + " - FONE: " +FLAG->n_fone, Nil, 8, "Helvetica", Nil, Nil )
				oPDF:DrawText( 8.0, 42, 'CNPJ-'+RTRIM(FLAG->n_CNPJ) + '   Insc.Est.-' + RTRIM(FLAG->n_IE) , Nil, 8, "Helvetica-Bold", Nil, Nil )

				oPDF:DrawBox( 0, nMaxCol, 9, 41, Nil, Nil, Nil )  // box direito
				oPDF:DrawText( 2, 120, "CAD.PRODUTOS", Nil, 10, "Helvetica", Nil, Nil )
				oPDF:DrawText( 4, 120, "PAGINA Nr.: " + STRZERO(nPagina,4,0), Nil, 10, "Helvetica", Nil, Nil )
				oPDF:DrawText( 6, 120, "DATA: " + DTOC(DAT_HOJE), Nil, 10, "Helvetica", Nil, Nil )
				oPDF:DrawText( 8, 120, "HORA: " + TIME(), Nil, 10, "Helvetica", Nil, Nil )

				oPDF:DrawBox( 9, 0, 12, nMaxCol, Nil, Nil, Nil )  


				nLinha := 11
				nPagina += 1
				nHightLin:=3

				nLenItem := 20
				nLenUnit := 22
				nLenVlrUni := 27
				nLenDescri := ( nMaxCol - ( nLenItem + nLenUnit +  nLenVlrUni ) )
				
				oPDF:DrawText( nLinha, 1, "Item", Nil, 10, "Helvetica", Nil, Nil )
				oPDF:DrawText( nLinha, nLenItem+1, "Descrição", Nil, 10, "Helvetica", Nil, Nil )
				oPDF:DrawText( nLinha, nLenItem+nLenDescri+1, "Unid.", Nil, 10, "Helvetica", Nil, Nil )
				oPDF:DrawText( nLinha, nLenItem+nLenDescri+nLenUnit+6, "Valor Unit.", Nil, 10, "Helvetica", Nil, Nil )

				nLinha += 3

			ENDIF
			
			
			oPDF:DrawText( nLinha, 1, PRODUTOS->CODPRO, "@R 999999-9", 12, "Courier-Bold", Nil, Nil )
			oPDF:DrawText( nLinha, nLenItem+1, SUBSTR(PRODUTOS->DESPRO,1,45), Nil, 10, "Helvetica", Nil, Nil )
			oPDF:DrawText( nLinha, nLenItem+nLenDescri+0.5, PRODUTOS->TIPUNI, Nil, 10, "Helvetica", Nil, Nil )
			oPDF:DrawText( nLinha, nLenItem+nLenDescri+nLenUnit+0.5, PRODUTOS->PREVEN,"@R 99,999.99", 12, "Courier-Bold", Nil, Nil )
			nLinha += 2
			DBSKIP()
		ENDDO   
		
		oPDF:DrawLine( nLinha, 0, nLinha, nMaxCol, 1 ) 
		
		oPDF:End(  )
		
	ELSE  
	
		DBSELECTAREA("PRODUTOS")
		Ordsetfocus(2)
		PRODUTOS->( DBGOTOP() )
	
		oPDF:nPrinterType :=  WIN_PRINTERGETDEFAULT()
		oPDF:SetType( PDFCLASS_ROLLS )
		oPDF:Begin()
		oPDF:nPageHeight := 841.89
		oPDF:AddPage()
		nMaxCol := oPDF:MaxCol()

		oPDF:DrawImageSize( 0, 0, 4, 19, "logotipo.jpg" )             // logotipo

		oPDF:DrawText( 5, 0, RTRIM(FLAG->n_xNome), nil, 10, "Helvetica-Bold", Nil, Nil )
		oPDF:DrawText( 6, 0, RTRIM(FLAG->n_xLgr) + ', ' + RTRIM(FLAG->n_nro), Nil, 8, "Helvetica", Nil, Nil )
		oPDF:DrawText( 7, 0,'BAIRRO - ' + RTRIM(FLAG->n_xBairro), Nil, 8, "Helvetica", Nil, Nil )
		oPDF:DrawText( 8, 0, "CEP " +FLAG->n_CEP + ' - ' + RTRIM(FLAG->n_xMun) + ' - ' + FLAG->n_xUF + " - FONE: " +FLAG->n_fone, Nil, 8, "Helvetica", Nil, Nil )
		oPDF:DrawText( 9, 0, 'CNPJ-'+RTRIM(FLAG->n_CNPJ) + '   Insc.Est.-' + RTRIM(FLAG->n_IE) , Nil, 8, "Helvetica-Bold", Nil, Nil )
		oPDF:DrawLine( 10, 0, 10, nMaxCol, 1 ) 
		oPDF:DrawText( 11.5, 0, "Descrição   Codigo           Unid.               Valor", Nil, 10, "Helvetica", Nil, Nil )	
		oPDF:DrawLine( 12, 0, 12, nMaxCol, 1 )
		
		
		nLinha 	 := 13
		nLenItem := 20
		nLenUnit := 7
		nLenVlrUni := 19
		nLenDescri := ( nMaxCol - ( nLenItem + nLenUnit +  nLenVlrUni ) )
			
		DO WHILE ! EOF()	
		
			IF 	nLinha	> 70
				oPDF:AddPage()
				nLinha	:= 0
			ENDIF
			
			oPDF:DrawText( nLinha  , 0, SUBSTR(PRODUTOS->DESPRO,1,58), Nil, 08, "Helvetica", Nil, Nil )
			oPDF:DrawText( ++nLinha, 10, PRODUTOS->CODPRO, "@R 999999-9", 08, "Courier-Bold", Nil, Nil )
			oPDF:DrawText( nLinha  , nLenItem+1, PRODUTOS->TIPUNI, Nil, 08, "Helvetica", Nil, Nil )
			oPDF:DrawText( nLinha  , nLenItem+nLenUnit+1, PRODUTOS->PREVEN,"@R 999,999.99", 08, "Courier-Bold", Nil, Nil )
			oPDF:DrawLine( nLinha+0.3, 0,nLinha+0.3, nMaxCol, 1 )		
			DBSKIP()
			nLinha 	 += 1
			
		ENDDO   

		oPDF:End(  )	

	ENDIF
	
	
	oPDF:PrintPreview(  )

RETURN NIL	
relatório exemplo com impressão em bobina e A4

obs: uma dica não se preocupe com o tamanho do relatório em bobina, so tem de fazer quebra de pagina e continuar , no final a impressora corta no tamanho certo mesmo ficando uma parte em branco
HARBOUR 3.2, HWGUI 2.23 B3, SEFAZCLASS, PDFClass, ADO + MariaDB/MySQL, RMChart
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Exemplos de recibos em PDF

Mensagem por JoséQuintas »

O problema foi ter que deixar disponível também pra LINUX, não poderia ter comandos Windows.
Então alguns métodos acabaram ficando vazios, pra não depender de sistema operacional.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

Exemplos de recibos em PDF

Mensagem por JoséQuintas »

A configuração de tamanho, inicialmente se configura pra relatórios comuns/tamanho de fonte/etc.
Passada essa "inicialização", pode ser configurada manualmente.

Mas terei que relembrar, e estou na transição do MySQL, a plena carga.
Alguns probleminhas eventuais pra corrigir, no geral erro de programador.... rs
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
Fernando queiroz
Usuário Nível 4
Usuário Nível 4
Mensagens: 779
Registrado em: 13 Nov 2014 00:41
Localização: Porto Alegre/RS

Exemplos de recibos em PDF

Mensagem por Fernando queiroz »

Fiz o PrintPreview bem simples

METHOD PrintPreview( ) CLASS PDFClass
IF ! EMPTY(::cDefaultPrinter)
WAPI_ShellExecute(NIL, 'OPEN', hb_Dirbase()+'SUMATRA\SumatraPDF.EXE', '"' + ::cFileName + '" -print-to "' + ::cDefaultPrinter + '"',, NIL )
// WAPI_ShellExecute(NIL, 'PRINT', '"' + ::cFileName + '"', '"' + ::cDefaultPrinter + '"',, NIL )
ELSE
WAPI_ShellExecute( NIL, "OPEN", ::cFileName , NIL,, NIL )
ENDIF
return nil

:)) :))
HARBOUR 3.2, HWGUI 2.23 B3, SEFAZCLASS, PDFClass, ADO + MariaDB/MySQL, RMChart
Responder