Page 3 of 17

Re: PDF Viewer DLL?

Posted: Wed Feb 15, 2017 1:05 pm
by Roberto Lopez
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.

Re: PDF Viewer DLL?

Posted: Wed Feb 15, 2017 2:08 pm
by Roberto Lopez
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).

Re: PDF Viewer DLL?

Posted: Wed Feb 15, 2017 8:12 pm
by Roberto Lopez
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.

Re: PDF Viewer DLL?

Posted: Thu Feb 16, 2017 12:38 pm
by Roberto Lopez
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!

Re: PDF Viewer DLL?

Posted: Fri Feb 17, 2017 9:51 am
by Anand
Thanks Roberto Lopez,

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

Regards,

Anand

Re: PDF Viewer DLL?

Posted: Fri Feb 17, 2017 2:52 pm
by PeteWG
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

Re: PDF Viewer DLL?

Posted: Fri Feb 17, 2017 6:05 pm
by Rathinagiri
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?

Re: PDF Viewer DLL?

Posted: Sat Feb 18, 2017 1:39 am
by andyglezl
Hola

Hice algunas pruebas con el UPX y esto resulto...
UPX-VePDF.jpg
UPX-VePDF.jpg (46.62 KiB) Viewed 6731 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 !

Re: PDF Viewer DLL?

Posted: Sat Feb 18, 2017 11:36 am
by Roberto Lopez
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!

Re: PDF Viewer DLL?

Posted: Sat Feb 18, 2017 11:42 am
by Roberto Lopez
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 :)