PDF CONVERTIR

HMG en Español

Moderator: Rathinagiri

User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: PDF CONVERTIR

Post by SALINETAS24 »

Hola, he estado haciendo pruebas y no consigo avanzar.., pero si que he llegado a una conclusión. Igual alguien puede ayudar.

Al programa de Andrés, le he añadido 3 posibilidades de cambiar un fichero formato RTF a PDF (las tres que conozco y que solo funciona la última).

La primera, si pones más de una linea no funciona.
La segunda, no hace los saldos de linea ni tiene en cuenta los caracteres especial.
La tercera....., si que funciona pero porque hace un PREVIEW... osease que si el documento se "pre visualiza previavente" si que se puede guardar en PDF. He estado mirando la función en "c" HB_FUNC( _HMG_PRINTER_STARTPAGE_PREVIEW ), pero mis conocimientos son limitados y me pierdo, no obstante entiendo que es posible hacerlo ya que HMG lo hace.
Lo que pretendo es hacer lo que hace el PREVIEW y el SAVE a PDF sin intervención del usuario, osea convertir un fichero ".rtf" en ".pdf".

¿alguien sabe donde esta la función que previsualiza el documento...?, quizás utilizando esta se podría realizar el proceso.


Cualquier ayuda será bienvenida..., muchas gracias.

Code: Select all

* CONVERTIR RTF A PDF


/*_______________________________________________________________________________________________________*/
/*[•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•.•]*/
/*¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯*/
#include "hmg.ch"

FUNCTION Main() 

		DEFINE WINDOW xForm AT 000,000 WIDTH 800 HEIGHT 600 MAIN TITLE "GRABA a PDF" BACKCOLOR { 51, 156, 255 } 

			@ 005,010 BUTTON LB_Tx  OF xForm CAPTION "RTF a PDF - Opc 1 "  WIDTH 200 HEIGHT 22 FONT "Consolas" SIZE 12  ;
					  ACTION PrintREB(1  ) 
					  
			@ 005,310 BUTTON LB_Tx2  OF xForm CAPTION "RTF a PDF - Opc 2"  WIDTH 200 HEIGHT 22 FONT "Consolas" SIZE 12  ;
					  ACTION PrintREB(2  ) 
					  
			@ 005,610 BUTTON LB_Tx3  OF xForm CAPTION "RTF a PDF - Opc 3"  WIDTH 200 HEIGHT 22 FONT "Consolas" SIZE 12  ;
					  ACTION PrintREB(3  ) 
	
			@ 030, 000 RICHEDITBOX EDB_x WIDTH 800 HEIGHT 570 VALUE ""
			xForm.EDB_x.RTFTextMode := .T. 

		END WINDOW
		CENTER WINDOW xForm  
		ACTIVATE WINDOW xForm
RETURN Nil	   
**********************************************************
FUNCTION PrintREB( nOpc )
	LOCAL lSuccess, nRow := 55, nCol := 70, nPag := 0
	LOCAL mspreh, msposth, cVar
	LOCAL PrintPageCodeBlock := { || @ nRow , nCol PRINT "Pag. " + HB_NTOS( nPag++ ) CENTER }

 
	xForm.EDB_x.RTFSaveFile ( "PROBA.rtf", 4, .F.)
	xForm.EDB_x.RTFLoadFile ( "PROBA.rtf", 4, .F.)
	
	DO CASE
		CASE nOPc=1
			SELECT HPDFDOC 'Opc1.pdf' TO lSuccess papersize HPDF_PAPER_A4
			SET HPDFDOC COMPRESS ALL
			SET HPDFDOC PAGEMODE TO OUTLINE
			if lSuccess
				START HPDFDOC
				SET HPDFDOC ENCODING TO "WinAnsiEncoding"
					START HPDFPAGE
						Print_Content( xForm.EDB_x.Value )
					END HPDFPAGE   
				END HPDFDOC
			endif
		
		CASE nOpc=2
			SELECT PRINTER PDF 'Opc2.pdf' TO lSuccess 
			IF lSuccess
				START PRINTDOC
					START PRINTPAGE
						@ 0,0 PRINT xForm.EDB_x.Value
					END PRINTPAGE
				END PRINTDOC
			ENDIF
		
		CASE nOpc=3
			
			SELECT PRINTER DEFAULT TO lSuccess SAVEAS "Opc3.PDF" 
			IF lSuccess
				xForm.EDB_x.RTFPrint( { 0, -1 } , 20 , 20 , 20 , 20 , PrintPageCodeBlock )
		    ENDIF
		
	ENDCASE
	
	
RETURN nil


function Print_Content( cContent) 
   @  50,  10 HPDFPRINT  cContent TO 120, 200 JUSTIFY
return nil
Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: PDF CONVERTIR

Post by edk »

Hi.
Based on HMG sources, I made export from RTF to PDF.
Exported pages are saved in the PDF as images, so it is not a native conversion. In carrying out this task I based on the use of Device Context. I was a bit groping because my knowledge of C and English is poor, so please forgive me if I made mistakes somewhere. After all, I hope that this code can be a bit useful.
In the given sample (based on RichEditBox), export to PDF takes place when saving the file (please indicate the file format as PDF). There are two options of creating PDF (basically images that are embedded in PDF):
Option 1 - the quality of the screen (96 DPI)
Option 2 - the quality of the default printer (DPI dependent on the default printer)
Look for the ExportToPDF and its related functions in the source.
Attachments
RichEditBox.zip
(32.99 KiB) Downloaded 163 times
User avatar
mustafa
Posts: 1158
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: PDF CONVERTIR

Post by mustafa »

+1
EduardoLuis
Posts: 682
Joined: Tue Jun 04, 2013 6:33 pm
Location: Argentina

Re: PDF CONVERTIR

Post by EduardoLuis »

Hi EDK

As allways you give all of us excellent solutions.-
Thanks for share with all of us.-
With regards.
Eduardo
Post Reply