PDF Viewer DLL?

Moderator: Rathinagiri

User avatar
Roberto Lopez
HMG Founder
Posts: 3897
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 13 times
Been thanked: 132 times

Re: PDF Viewer DLL?

Post by Roberto Lopez » Wed Feb 15, 2017 1:05 pm

Claudio, Andrés, Pete,

Many thanks to all for your propossed solutions.

Apparently, my idea was not so crazy after all :)

Pete:

Regarding the size, Sumatra can be reduced by about 50% with UPX (using --best parameter).

And I have to test yet the '--ultra-brute' switch, that could reduce it even more.

Thanks again to all.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

User avatar
Roberto Lopez
HMG Founder
Posts: 3897
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 13 times
Been thanked: 132 times

Post by Roberto Lopez » Wed Feb 15, 2017 2:08 pm

Roberto Lopez wrote:
Wed Feb 15, 2017 1:05 pm
Pete:

Regarding the size, Sumatra can be reduced by about 50% with UPX (using --best parameter).

And I have to test yet the '--ultra-brute' switch, that could reduce it even more.
Using '--ultra-brute' switch Sumatra reduces to 2.5 MB (not such a big problem).
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

User avatar
Roberto Lopez
HMG Founder
Posts: 3897
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 13 times
Been thanked: 132 times

Post by Roberto Lopez » Wed Feb 15, 2017 8:12 pm

Well... this is my first try...

Code: Select all

*----------------------------------------------------------------------*
PROCEDURE VIEW_PDF(cFile)
*----------------------------------------------------------------------*                  
LOCAL cHwnd

	IF .NOT. FILE('SumatraPDF.exe')

		MSGSTOP('PDF Viewer Not Found!')
		RETURN

	ELSE

		DEFINE WINDOW PdfView ;
			AT 0,0 ;
			WIDTH 900 ;
			HEIGHT 700 ;
			TITLE cFile ;
			MODAL 
		
		END WINDOW

		Center Window PdfView

		cHwnd := ALLTRIM( STR( GETFORMHANDLE( 'PdfView' ) ) )

		EXECUTE FILE 'SumatraPDF.exe' PARAMETERS ' -lang es -plugin ' + cHwnd + ' ' + cFile

		Activate Window PdfView

	ENDIF

RETURN
'-lang es' sets the Sumatra UI to Spanish, so, You could change as required.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

User avatar
Roberto Lopez
HMG Founder
Posts: 3897
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 13 times
Been thanked: 132 times

Post by Roberto Lopez » Thu Feb 16, 2017 12:38 pm

This is the final code.

I'm using the Pete suggested method to embbed Sumatra, since I prefer to have as much as I can in source (prg) code, instead resources.

Code: Select all

#include "fileio.ch"

STATIC FUNCTION SumatraExe()
#pragma __binarystreaminclude "SumatraPDF.exe" | RETURN %s

*----------------------------------------------------------------------*
PROCEDURE VIEW_PDF(cFile)
*----------------------------------------------------------------------*                  
LOCAL cHwnd

	IF ! hb_vfExists( "SumatraPDF.exe" )
		hb_MemoWrit( "SumatraPDF.exe", SumatraExe() )
		// give OS a little time to "see"  the newly created file
		hb_IdleSleep( 0.5 ) 
		// hide the file from user's sight to protect it from "accidents"
		hb_vfAttrSet( "SumatraPDF.exe",  HB_FA_HIDDEN + HB_FA_READONLY + HB_FA_SYSTEM )
	ENDIF

	DEFINE WINDOW PdfView ;
		AT 0,0 ;
		WIDTH 900 ;
		HEIGHT 700 ;
		TITLE cFile ;
		MODAL 
		
	END WINDOW

	Center Window PdfView

	cHwnd := ALLTRIM( STR( GETFORMHANDLE( 'PdfView' ) ) )

	EXECUTE FILE 'SumatraPDF.exe' PARAMETERS ' -plugin ' + cHwnd + ' ' + cFile

	Activate Window PdfView

RETURN

As I've said, from some time ago, I'm creating all my reports straight to PDF and from now, for the preview at generating and revieweing stored versions, I'll use Sumatra this way.

Times are changing and PDF is becoming more important than paper... so... we must adapt :)

Thanks to all for the help me on this!
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

User avatar
Anand
Posts: 184
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF
Has thanked: 16 times
Been thanked: 32 times

Post by Anand » Fri Feb 17, 2017 9:51 am

Thanks Roberto Lopez,

This is very useful for report in pdf and view solution.

Regards,

Anand
Image

User avatar
PeteWG
Posts: 102
Joined: Sun Mar 21, 2010 5:45 pm
Has thanked: 3 times
Been thanked: 23 times

Post by PeteWG » Fri Feb 17, 2017 2:52 pm

Roberto Lopez wrote:
Thu Feb 16, 2017 12:38 pm
This is the final code.
Nice and clean implementation!
Times are changing and PDF is becoming more important than paper... so... we must adapt :)
+1


regards,

---
Pete

User avatar
Rathinagiri
Posts: 5126
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 113 times
Been thanked: 114 times
Contact:

Post by Rathinagiri » Fri Feb 17, 2017 6:05 pm

Actually I can not adapt to PDF because it doesn't support our Unicode. :(

I use HTML instead and it works nice.

We can also consider using ePub, djvu formats along with Sumatra. Are there any libraries to export to these formats from Harbour?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
andyglezl
Posts: 835
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 7 times
Been thanked: 20 times
Contact:

Post by andyglezl » Sat Feb 18, 2017 1:39 am

Hola

Hice algunas pruebas con el UPX y esto resulto...
UPX-VePDF.jpg
UPX-VePDF.jpg (46.62 KiB) Viewed 366 times
---------------------------------------------------------------------------------------------------------------------------
El primer ejecutable, es una compilación normal y el sumatrapdf2.exe (6,339 kb) y pesa 10,251 kb.
(con mis bibliotecas predefinidas)

El segundo, es utilizando el UPX con el sumatrapdf2.exe con '--ultra-brute' switch. y pesa 7,048 kb.

El tercero, es utilizando el UPX '--ultra-brute' switch con el resultado de la compilación normal y pesa 5,084 kb

O sea, que utilizando directamente el UPX en la compilación normal, lo reduce más !.
--------------------------------------------------------------------------------------------------------------------------
The first executable, is a normal compilation and sumatrapdf2.exe (6,339 kb) and weighs 10.251 kb.
(With my predefined libraries)

The second is using UPX with sumatrapdf2.exe with '--ultra-brute' switch. And weighs 7.048 kb.

The third, is using the UPX '--ultra-brute' switch with the result of normal compilation and weighs 5.084 kb

That is, using the UPX directly in the normal compilation, reduce it more!


P.D. Gracias PeteWG y Roberto por el ejemplo !
Andrés González López
Desde Guadalajara, Jalisco. México.

User avatar
Roberto Lopez
HMG Founder
Posts: 3897
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 13 times
Been thanked: 132 times

Post by Roberto Lopez » Sat Feb 18, 2017 11:36 am

andyglezl wrote:
Sat Feb 18, 2017 1:39 am

That is, using the UPX directly in the normal compilation, reduce it more!
Very interesting info.

My first thinking was that the result could be nearly the same (compressing Sumatra before embedding or later along the final exe).

Thanks!
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

User avatar
Roberto Lopez
HMG Founder
Posts: 3897
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 13 times
Been thanked: 132 times

Post by Roberto Lopez » Sat Feb 18, 2017 11:42 am

Rathinagiri wrote:
Fri Feb 17, 2017 6:05 pm
Actually I can not adapt to PDF because it doesn't support our Unicode. :(
My knowledge about unicode is very poor, but I'm sure that some kind of conversion could be possible...

There is lots of small commandline utilities for each need, maybe that one of them, could convert HTML to PDF.

ie: In the case of scanner control I've ended using three different things (my requirement was to scan to PDF 1.4).

To achieve that I've used:

- EZTW32.DLL: For scanner acces. The result is one (or more) bmp file(s).

- JPG.dll: Converts bmp to jpg (I could use HMG, I know).

- jpeg2pdf.exe: Converts jpgs to PDF. It is able to join multiple jpg files in a single PDF document (one page per jpg file).

The point is that if you research deep enough, almost always a solution arises, even you need multiple utilities to achieve that :)
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

Post Reply