Imprimir a PDF. ultimo codigo del ejemplo del hilo HPDF no f

HMG en Español

Moderator: Rathinagiri

Post Reply
paimar
Posts: 64
Joined: Wed May 23, 2012 8:52 pm

Imprimir a PDF. ultimo codigo del ejemplo del hilo HPDF no f

Post by paimar »

Hola.

He leido todo el hilo sobre HMG_HPDF - Export to PDF made easy... (New Version) y por lo que entiendo con esto se puede generar un listado en pdf sin mandarlo a la impresora verdad? (pretendo mandarlo por email sin vista previa). El caso es que el ultimo ejemplo que esta para descargar del hilo lo ejecuto en 3.2 y me da un monton de error redefinition y demas. Saben si ha cambiado algo para que ahora no funcione?


Lo muestro a continuacion, muchas gracias por adelantado.


#xcommand SET PRINTSYSTEM PDF ;
=>;
#include "hmg_hpdf.ch"

#include <hmg.ch>

Function Main

SET PRINTSYSTEM PDF

define window main at 0, 0 width 300 height 300 main title 'HMG HPDF Sample'

define button print
row 100
col 100
caption 'Create PDF'
action pdf_create()
end button

end window

main.center

main.activate

Return

function pdf_create

local lSuccess := .f.

SELECT PRINTER 'sample.pdf' TO lSuccess ;
PAPERSIZE PRINTER_PAPER_A4 ;
ORIENTATION PRINTER_ORIENT_LANDSCAPE ;
PREVIEW

SET PRINTDOC COMPRESS ALL

// Set if you wish a password for the generated file
// SET PRINTDOC PASSWORD OWNER 'owner' USER 'user'

if lSuccess
START PRINTDOC
START PRINTPAGE
@ 10, 60 PRINT 'This is sample Left Aligned'
@ 15, 20 PRINT 'This is sample Red Colored' color { 255, 0, 0 }
@ 15, 100 PRINT 'This is sample Another Fantastic Color' color { 150, 100, 100 }
@ 20, 60 PRINT 'This is sample Center Aligned' CENTER
@ 25, 60 PRINT 'This is sample Right Aligned' RIGHT
@ 30, 10 PRINT 'This is a small paragraph to be printed inside a rectangular area which is left aligned.' to 50, 60
@ 60, 10 PRINT 'This is a small paragraph to be printed inside a rectangular area which is center aligned.' to 80, 60 CENTER
@ 90, 10 PRINT 'This is a small paragraph to be printed inside a rectangular area which is right aligned.' to 110, 60 RIGHT
@ 120, 10 PRINT 'This is a small paragraph to be printed inside a rectangular area which is justify aligned.' to 140, 60 JUSTIFY
@ 150, 10 PRINT line to 160, 10
@ 150, 20 PRINT line to 160, 20 penwidth 0.5
@ 150, 30 PRINT line to 160, 30 penwidth 1 color { 0, 255, 0 }
END PRINTPAGE
START PRINTPAGE
@ 10, 60 PRINT 'This is Page 2'
@ 30, 20 PRINT rectangle to 60, 50
@ 40, 30 PRINT rectangle to 50, 40 penwidth 1 color { 0, 255, 0 }
@ 70, 20 PRINT rectangle to 90, 40 penwidth 1 color { 0, 255, 0 } filled
@ 100, 10 PRINT 'This is text in BIG size' size 30
@ 120, 10 PRINT 'This is in Times-Roman font' font 'Times-Roman' size 18
@ 140, 10 PRINT 'This is in Courier-BoldOblique font' font 'Courier-BoldOblique' size 18
@ 160, 10 PRINT 'This is in Times-Italic font' font 'Times-Italic' size 18
@ 180, 10 PRINT 'This is in Helvetica-Bold font' font 'Helvetica-Bold' size 18
@ 200, 10 PRINT 'This is in Courier font' font 'Courier' size 18
END PRINTPAGE
START PRINTPAGE
@ 10, 60 PRINT 'This is Page 3'
@ 20, 10 PRINT IMAGE 'peacock.png' width 140 height 106
END PRINTPAGE
START PRINTPAGE
@ 20, 20 PRINT CIRCLE RADIUS 10
@ 20, 45 PRINT CIRCLE RADIUS 10 color { 0, 255, 0 }
@ 20, 70 PRINT CIRCLE RADIUS 10 color { 255, 255, 0 } filled
@ 50, 20 PRINT ARC RADIUS 10 ANGLE FROM 0 TO 180 penwidth 2 color { 255, 0, 255 }
@ 50, 50 PRINT ELLIPSE HORIZONTAL RADIUS 10 VERTICAL RADIUS 20 penwidth 2 color { 255, 0, 255 }
@ 50, 90 PRINT ELLIPSE HORIZONTAL RADIUS 20 VERTICAL RADIUS 10 penwidth 2 color { 0, 0, 255 }
@ 50, 140 PRINT ELLIPSE HORIZONTAL RADIUS 20 VERTICAL RADIUS 10 penwidth 2 color { 0, 0, 255 } filled
// try rounded rectangle
@ 100, 70 PRINT CURVE FROM 70, 70 TO 70, 100
@ 70, 200 PRINT CURVE FROM 70, 230 TO 100, 230
@ 150, 70 PRINT CURVE FROM 180, 70 TO 180, 100
@ 180, 200 PRINT CURVE FROM 180, 230 TO 150, 230
@ 70, 100 PRINT LINE TO 70, 200
@ 100, 70 PRINT LINE TO 150, 70
@ 100, 230 PRINT LINE TO 150, 230
@ 180, 100 PRINT LINE TO 180, 200
END PRINTPAGE
END PRINTDOC
endif

// You can open the generated file at any moment

// OPEN FILE 'sample.pdf'

// Or you can print it

// PRINT FILE 'sample.pdf'

return nil
Gipuzkoa - ESPAÑA
User avatar
CarlosRD
Posts: 63
Joined: Thu Jan 31, 2013 9:20 pm
Location: Orizaba, México

Re: Imprimir a PDF. ultimo codigo del ejemplo del hilo HPDF

Post by CarlosRD »

Hola paimar, buenas tardes desde México.

Te recomiendo que veas los ejemplos que vienen anexos en la carpeta SAMPLES.

A simple vista, para crear un PDF, debes utilizar los comandos como START HPDFDOC, START HPDFPAGE, HPDFPRINT, etc.

te anexo un extracto de uno de mis prgs, ojalá te pueda dar una referencia de como usar los comandos.

Saludos.

**************************

Hello paimar, good afternoon from mexico.

The good thing you can do is to see samples in SAMPLES folder.
To create a PDF file, you have to use START HPDFDOC, START HPDFPAGE, HPDFPRINT, etc., commands.
I add an extract from one of my prgs, hoping it can help you.
Regards.

Code: Select all

	titulo="Reporte de Captura de Renovado"
	reporte="reptcpr.pdf"
    SELECT HPDFDOC reporte TO lSuccess papersize HPDF_PAPER_LETTER
	if lSuccess
	START hpdfdoc
	SET HPDFDOC ENCODING TO "WinAnsiEncoding"
		start hpdfpage
			do while .not. eof()
				if rg=0 .or. rg>260
					if rg>260
						end hpdfpage
						start hpdfpage
					endif
					pg=pg+1
					@010,007 hpdfprint gpo font 'Times-Roman' size 9
					@010,180 hpdfprint 'Fecha: '+dtoc(date()) font 'Times-Roman' size 9
					@014,007 hpdfprint titulo+' del dia: '+entrada font 'Times-Roman' size 9
					@014,180 hpdfprint 'Página: '+transform(pg,'999') font 'Times-Roman' size 9

					@018,007 hpdfprint replicate('=',115) font 'Times-Roman' size 9
					@022,007 hpdfprint 'Orden' font 'Times-Roman' size 9
					@022,030 hpdfprint 'Zona' font 'Times-Roman' size 9
					@022,070 hpdfprint 'Medida' font 'Times-Roman' size 9
					@026,007 hpdfprint replicate('=',115) font 'Times-Roman' size 9

					rg=30
				endif
				mz=repcap->zona
				mm=repcap->medida
				do while !eof()
					if repcap->zona=mz .and. repcap->medida=mm
					    porllanta++
						skip
					else
						skip -1
						exit
					endif
				enddo
*				@rg,007 hpdfprint transform(repcap->orden,'9999999') font 'Times-Roman' size 9
*				@rg,030 hpdfprint repcap->zona font 'Times-Roman' size 9
*				@rg,070 hpdfprint repcap->medida font 'Times-Roman' size 9
				@rg,030 hpdfprint mz font 'Times-Roman' size 9
				@rg,070 hpdfprint mm font 'Times-Roman' size 9
				@rg,100 hpdfprint transform(porllanta,"9999") font 'Times-Roman' size 9
				rg=rg+4
				cuantos=cuantos+porllanta
				porllanta=0
				skip
			enddo
			@rg+4,007 hpdfprint 'Registros impresos: '+transform(cuantos,'999') font 'Times-Roman' size 9
		end hpdfpage
	end hpdfdoc
	endif
	use
	execute file reporte
Todo en el Nombre de Jesus / All in the name of Jesus
Carlos RD
User avatar
mustafa
Posts: 1172
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: Imprimir a PDF. ultimo codigo del ejemplo del hilo HPDF

Post by mustafa »

Hola paimar
si rectificas como indica el amigo carlosRD
el resultado es OK
tambien hay que agregar hfcl.ch y anular
hmg_hpdf.ch

Code: Select all

*-----------------------------------*
#xcommand SET PRINTSYSTEM PDF ;
=>;
#include <hmg.ch>
#include "hfcl.ch"            // <---sustituir
*#include "hmg_hpdf.ch"   // <--- anular

Function Main

SET PRINTSYSTEM PDF

define window main at 0, 0 width 300 height 300 main title 'HMG HPDF Sample'

define button print
row 100
col 100
caption 'Create PDF'
action pdf_create()
end button

end window

main.center

main.activate

Return

function pdf_create

local lSuccess := .f.

   titulo="Reporte de Captura de Renovado"
   reporte="sample.pdf"
   SELECT HPDFDOC reporte TO lSuccess papersize HPDF_PAPER_LETTER


   START hpdfdoc
   SET HPDFDOC ENCODING TO "WinAnsiEncoding"

// Set if you wish a password for the generated file
// SET PRINTDOC PASSWORD OWNER 'owner' USER 'user'

if lSuccess

START hpdfdoc
start hpdfpage


@  10,  60 hpdfprint 'This is sample Left Aligned' 
@  15,  20 hpdfprint 'This is sample Red Colored' color { 255, 0, 0 }
@  15, 100 hpdfprint 'This is sample Another Fantastic Color' color { 150, 100, 100 } 
@  20,  60 hpdfprint 'This is sample Center Aligned' CENTER
@  25,  60 hpdfprint 'This is sample Right Aligned' RIGHT
@  30,  10 hpdfprint 'This is a small paragraph to be printed inside a rectangular area which is left aligned.' to 50, 60 
@  60,  10 hpdfprint 'This is a small paragraph to be printed inside a rectangular area which is center aligned.' to 80, 60 CENTER
@  90,  10 hpdfprint 'This is a small paragraph to be printed inside a rectangular area which is right aligned.' to 110, 60 RIGHT
@ 120,  10 hpdfprint 'This is a small paragraph to be printed inside a rectangular area which is justify aligned.' to 140, 60 JUSTIFY
@ 150,  10 hpdfprint line to 160, 10
@ 150,  20 hpdfprint line to 160, 20 penwidth 0.5
@ 150,  30 hpdfprint line to 160, 30 penwidth 1 color { 0, 255, 0 }
 end hpdfpage


 start hpdfpage
@  10,  60 hpdfprint 'This is Page 2' 
@  30,  20 hpdfprint rectangle to 60, 50
@  40,  30 hpdfprint rectangle to 50, 40 penwidth 1 color { 0, 255, 0 }
@  70,  20 hpdfprint rectangle to 90, 40 penwidth 1 color { 0, 255, 0 } filled
@ 100,  10 hpdfprint 'This is text in BIG size' size 30
@ 120,  10 hpdfprint 'This is in Times-Roman font' font 'Times-Roman' size 18
@ 140,  10 hpdfprint 'This is in Courier-BoldOblique font' font 'Courier-BoldOblique' size 18
@ 160,  10 hpdfprint 'This is in Times-Italic font' font 'Times-Italic' size 18
@ 180,  10 hpdfprint 'This is in Helvetica-Bold font' font 'Helvetica-Bold' size 18
@ 200,  10 hpdfprint 'This is in Courier font' font 'Courier' size 18
 end hpdfpage
 start hpdfpage
@  10,  60 hpdfprint 'This is Page 3' 
@  20,  10 hpdfprint IMAGE 'peacock.png' width 140 height 106
 end hpdfpage

 start hpdfpage
@  20,  20 hpdfprint CIRCLE RADIUS 10
@  20,  45 hpdfprint CIRCLE RADIUS 10 color { 0, 255, 0 } 
@  20,  70 hpdfprint CIRCLE RADIUS 10 color { 255, 255, 0 } filled
@  50,  20 hpdfprint ARC RADIUS 10 ANGLE FROM 0 TO 180 penwidth 2 color { 255, 0, 255 }
@  50,  50 hpdfprint ELLIPSE HORIZONTAL RADIUS 10 VERTICAL RADIUS 20 penwidth 2 color { 255, 0, 255 }
@  50,  90 hpdfprint ELLIPSE HORIZONTAL RADIUS 20 VERTICAL RADIUS 10 penwidth 2 color { 0, 0, 255 }
@  50, 140 hpdfprint ELLIPSE HORIZONTAL RADIUS 20 VERTICAL RADIUS 10 penwidth 2 color { 0, 0, 255 } filled
// try rounded rectangle
@ 100,  70 hpdfprint CURVE FROM 70, 70 TO 70, 100
@  70, 200 hpdfprint CURVE FROM 70, 230 TO 100, 230
@ 150,  70 hpdfprint CURVE FROM 180, 70 TO 180, 100
@ 180, 200 hpdfprint CURVE FROM 180, 230 TO 150, 230
@  70, 100 hpdfprint LINE TO 70, 200
@ 100,  70 hpdfprint LINE TO 150, 70
@ 100, 230 hpdfprint LINE TO 150, 230
@ 180, 100 hpdfprint LINE TO 180, 200

   end hpdfpage
   end hpdfdoc


endif 

 execute file 'sample.pdf'

// You can open the generated file at any moment

// OPEN FILE 'sample.pdf' 

// Or you can print it 

// PRINT FILE 'sample.pdf' 

return nil

*------------------------------------------------------------------*
un saludo
Mustafa
Last edited by mustafa on Fri Feb 14, 2020 9:39 am, edited 1 time in total.
paimar
Posts: 64
Joined: Wed May 23, 2012 8:52 pm

Re: Imprimir a PDF. ultimo codigo del ejemplo del hilo HPDF

Post by paimar »

Gracias Mustafa !!

Asi funciona perfecto!!

Un saludo desde Irun (Gipuzkoa)
Gipuzkoa - ESPAÑA
Post Reply