Page 2 of 2

Re: PDF CONVERTIR

Posted: Sun May 12, 2019 10:15 am
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

Re: PDF CONVERTIR

Posted: Mon May 20, 2019 10:39 am
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.

Re: PDF CONVERTIR

Posted: Mon May 20, 2019 2:12 pm
by mustafa
+1

Re: PDF CONVERTIR

Posted: Wed May 22, 2019 1:24 pm
by EduardoLuis
Hi EDK

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