print preview - PDFCreator

Moderator: Rathinagiri

Post Reply
User avatar
Carlos Reis
Posts: 16
Joined: Sat Oct 09, 2010 3:31 pm
Location: Portugal

print preview - PDFCreator

Post by Carlos Reis »

Hello all

How can I print a PDF file ?
I'm using the HMG 3.0.35 and I want to print a PDF file

for example:
.....
......
xfile :=" Teste.pdf"
......
......
START PRINTDOC

START PRINTPAGE


// commands for Print the "teste.pdf " file



END PRINTPAGE

END PRINTDOC

Return Nil
[u]Moderator Notes[/u] (Pablo César) wrote:This topic was splitted and moved from HMG Wishlist.
Best Regards
Carlos Reis, Portugal
39º 46' 47" N
08º 55' 45 W
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: print preview

Post by mol »

i think the best way in this time is to install PDFCreator and select it as printer...
I've tested some time ago a sample with pdf creating, but there were some problems (I don't remember what kind - something about positions... I think)
User avatar
gfilatov
Posts: 1057
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: print preview

Post by gfilatov »

mol wrote:i think the best way in this time is to install PDFCreator and select it as printer...
Hello,

I'm agree with your opinion.

Please take a look for the following simple sample of using PDFCreator for the printing:

Code: Select all

#include "minigui.ch"

*------------------------------------------------------------------------------*
Function Main()
*------------------------------------------------------------------------------*

//	AVAILABLE LIBRARY INTERFACE LANGUAGES

//	SET LANGUAGE TO ENGLISH (DEFAULT)
//	SET LANGUAGE TO SPANISH
//	SET LANGUAGE TO PORTUGUESE
//	SET LANGUAGE TO ITALIAN
//	SET LANGUAGE TO GERMAN
//	SET LANGUAGE TO FRENCH

	Private aColor [10]

	aColor [1] := YELLOW	
	aColor [2] := PINK	
	aColor [3] := RED	
	aColor [4] := FUCHSIA	
	aColor [5] := BROWN	
	aColor [6] := ORANGE	
	aColor [7] := GREEN	
	aColor [8] := PURPLE	
	aColor [9] := BLACK	
	aColor [10] := BLUE

	DEFINE WINDOW Win_1 ;
		AT 0,0 ;
		WIDTH 400 ;
		HEIGHT 400 ;
		TITLE 'MiniPrint Library Test' ;
		MAIN 

		DEFINE MAIN MENU 
			DEFINE POPUP 'File'
				MENUITEM 'Default Printer' ACTION PrintTest1()
				MENUITEM 'User Selected Printer' ACTION PrintTest2()
				MENUITEM 'User Selected Printer And Settings' ACTION PrintTest3()
				MENUITEM 'User Selected Printer And Settings (Preview)' ACTION PrintTest4()
			END POPUP
		END MENU

	END WINDOW

	MAXIMIZE WINDOW Win_1

	ACTIVATE WINDOW Win_1

Return
*------------------------------------------------------------------------------*
Procedure PrintTest1()
*------------------------------------------------------------------------------*
Local DefaultPrinterBak

	oPDFC := CreateObject( "PDFCreator.clsPDFCreator" )
	oPDFC:cVisible := .F.
	If oPDFC:cStart("/NoProcessingAtStartup") = .f. 
		If oPDFC:cStart("/NoProcessingAtStartup", .t.) = .f.
			msginfo("Init printer error!")
			return nil
	 	EndIf
	EndIf
	oPDFC:cOption('UseAutosave',1)
	oPDFC:cOption('UseAutosaveDirectory',1)
	oPDFC:cOption("AutosaveFormat",0) && PDF format
	DefaultPrinterBak := oPDFC:cDefaultprinter
	oPDFC:cDefaultprinter := "PDFCreator"
	oPDFC:cClearCache()
	oPDFC:cOption('AutosaveFilename',"test")
	oPDFC:cOption('AutosaveDirectory',GetTempFolder())

	SELECT PRINTER DEFAULT ;
		ORIENTATION	PRINTER_ORIENT_PORTRAIT ;
		PAPERSIZE	PRINTER_PAPER_LETTER ;
		QUALITY		PRINTER_RES_MEDIUM 

	PrintDoc()
	
	oPDFC:cPrinterStop := .f.
	oPDFC:cClearcache()
	oPDFC:cDefaultprinter := DefaultPrinterBak
	oPDFC:cClose()
	
MsgInfo('Print Finished')

Return
*------------------------------------------------------------------------------*
Procedure PrintTest2()
*------------------------------------------------------------------------------*
Local i 
Local cPrinter

	cPrinter := GetPrinter()

	If Empty (cPrinter)
		Return
	EndIf

	SELECT PRINTER cPrinter ;
		ORIENTATION	PRINTER_ORIENT_PORTRAIT ;
		PAPERSIZE	PRINTER_PAPER_LETTER ;
		QUALITY		PRINTER_RES_MEDIUM

	PrintDoc()

	MsgInfo('Print Finished')

Return
*------------------------------------------------------------------------------*
Procedure PrintTest3()
*------------------------------------------------------------------------------*
Local i 
Local lSuccess

	// Measure Units Are Millimeters

	SELECT PRINTER DIALOG TO lSuccess 

	If lSuccess == .T.
		PrintDoc()
		MsgInfo('Print Finished')
	EndIf

Return
*------------------------------------------------------------------------------*
Procedure PrintTest4()
*------------------------------------------------------------------------------*
Local i 
Local lSuccess

	SELECT PRINTER DIALOG TO lSuccess PREVIEW

	If lSuccess == .T.
		PrintDoc()
		MsgInfo('Print Finished')
	EndIf

Return
*------------------------------------------------------------------------------*
Procedure PrintDoc
*------------------------------------------------------------------------------*
Local i

	// Measure Units Are Millimeters

	START PRINTDOC

		FOR I := 1 TO 10

			START PRINTPAGE

				@ 20,20 PRINT RECTANGLE ;
					TO 50,190 ;
					PENWIDTH 0.1

				@ 25,25 PRINT IMAGE "hmg.jpg" ;
					WIDTH 20 ;
					HEIGHT 20 

				@ 30,85 PRINT "PRINT DEMO" ;
					FONT "Courier New" ;
					SIZE 24 ;
					BOLD ;
					COLOR aColor [i]

				@ 140,60 PRINT "Page Number :" + Str(i,2) ;
					FONT "Arial" ;
					SIZE 20 ;
					COLOR aColor [i]

				@ 260,20 PRINT LINE ;
					TO 260,190 ;
					PENWIDTH 0.1

			END PRINTPAGE

		NEXT I

	END PRINTDOC

Return
Hope that helps :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
Carlos Reis
Posts: 16
Joined: Sat Oct 09, 2010 3:31 pm
Location: Portugal

Re: print preview

Post by Carlos Reis »

mol wrote:i think the best way in this time is to install PDFCreator and select it as printer...
I've tested some time ago a sample with pdf creating, but there were some problems (I don't remember what kind - something about positions... I think)
Hi
Thanks for your reply.

The problem is that I need to print a document with a part of data from a table and another part from a pre-defenided document in PDF.
Best Regards
Carlos Reis, Portugal
39º 46' 47" N
08º 55' 45 W
User avatar
Carlos Reis
Posts: 16
Joined: Sat Oct 09, 2010 3:31 pm
Location: Portugal

Re: print preview

Post by Carlos Reis »

Thanks gfilatov for the sample.

I will test it to see if it serves my needs.

Thanks a lot.
Best Regards
Carlos Reis, Portugal
39º 46' 47" N
08º 55' 45 W
Post Reply