Report PDF export function does not work HMG 3.3.1

Moderator: Rathinagiri

trmpluym
Posts: 192
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands
Has thanked: 4 times
Been thanked: 11 times

Re: Report PDF export function does not work HMG 3.3.1

Post by trmpluym » Thu Feb 09, 2017 11:14 pm

Pablo César wrote:
Thu Feb 09, 2017 10:38 pm
I would not say it worked for me without having tested your example ...
Sorry Pablo, i did not mend to offend you. I am always thankfull because you are allways very helpfull :oops:

The result is very interesting. Your PDF looks completely different than mine !

Here is the beginning of my PDF (with the original DBF).
PDF_1.png
PDF_1.png (13.59 KiB) Viewed 281 times
Now this is yours:
PDF_2.png
PDF_2.png (23.12 KiB) Viewed 281 times
See the difference ? Also the properties are quite different, here are mine:
PDF_3.png
PDF_3.png (6.09 KiB) Viewed 281 times
And your PDF:
PDF_4.png
PDF_4.png (7.04 KiB) Viewed 281 times
See the differences in size and dimensions.

Maybe the papersize of the selected printer does make the difference ?

Theo
Attachments
HMG_PrintFile.zip
(2.46 MiB) Downloaded 16 times

trmpluym
Posts: 192
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands
Has thanked: 4 times
Been thanked: 11 times

Post by trmpluym » Thu Feb 09, 2017 11:35 pm

Pablo,

The selected printer makes the difference. Can you install the 'HP LaserJet 2200 Series PCL 5' in your system (even if you do not own such a printer, it is only for testing). The driver is in the standard drivers of Windows 7. Select this printer when starting my demo. When installed by default the resolution of the printer preferences is 600dpi and the error i described will occur. Now change the printing preferences of the printer to 300dpi and run the demo again. The PDF can now be created (but is is very big).

PDF_5.png
PDF_5.png (15.59 KiB) Viewed 280 times
Probally your selected printer is a printer with a lower resolution than mine (and my customers).

Theo

User avatar
Pablo César
Posts: 4058
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 176 times

Post by Pablo César » Fri Feb 10, 2017 12:17 am

trmpluym wrote:
Thu Feb 09, 2017 11:14 pm
Sorry Pablo, i did not mend to offend you. I am always thankfull because you are allways very helpfull :oops:
No problem, my friend. You never offended me.
The result is very interesting. Your PDF looks completely different than mine !
Must be because I did tests with dot matrix printer. Many years ago, I do not print more ...
I have a new printer still in the box, without using ...
The selected printer makes the difference. Can you install the 'HP LaserJet 2200 Series PCL 5' in your system (even if you do not own such a printer, it is only for testing). The driver is in the standard drivers of Windows 7. Select this printer when starting my demo. When installed by default the resolution of the printer preferences is 600dpi and the error i described will occur. Now change the printing preferences of the printer to 300dpi and run the demo again. The PDF can now be created (but is is very big).
Yes probably. I will try the test you have indicated. But gimme more time. Tomorrow I will install it and test.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
Pablo César
Posts: 4058
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 176 times

Post by Pablo César » Sun Feb 12, 2017 8:29 pm

Hi Theo,

First of all, I want to ask for your forgiveness by I not having returned before. I was busy and recently I was able to see the installation of the HP LaserJet 2200 Series PCL 5 printer. :oops:

I installed, tested, and unlike my printer's drive, I suppose it requires more than the other. For the error appears eminently in all the times that I have tested. :|

I still can not solve it but I was able to reach a conclusion, alias thanks to this experience I was able to detect a failure in the IDE and Bos Taurus functions.

I left where everything starts ... in the _HMG_PRINTER_SavePages function of the h_controlmisc.prg file.

I started implementing persistence procedures to isolate problems where Boss Taurus functions significantly is working.

My first thought was in the function where I freed the BITMAPS handle from memory and the BT_BitmapRelease function does not give a logical return which is replaced by the same BT_BMP_RELEASE function in C.
As I said, the BT_BMP_RELEASE, BT_BitmapLoadEMF, and BT_BitmapSaveFile functions were enforced to work with persistence routines to ensure large-scale work (multiple pages / files to be converted).

The COPY FILE command (which has nothing to do with this) has been replaced with the FileCopy function that works with copied file checking and persistence.

The problem here is in the function BT_BitmapSaveFile that sometimes obeys, working fine and others not until it causes error of reading of the image by the function _HPDF_LOAD_JPG that soon precedes and that gives the infamous error:

Image

I do not know what's wrong but I have no idea what the BT_BitmapSaveFile function would be missing.
In my opinion, the function could reinforce the check of the generated file is an image file.
Because as we know the fault generates a preview file of everything in black color.

You may notice by reviewing the last JPG file that is generated and causing failure.

I wish Claudio could understand me, because my English is certainly reviewed by Google Translator and this is a complicated issue to detect and maybe to solve.

I will continue my testing in search of a solution.

The IDE issue, I am announcing here in this other topic: http://www.hmgforum.com/viewtopic.php?p=49261#p49261
 
Pablo César wrote:
Tue Feb 07, 2017 9:22 pm
Rathinagiri wrote:
Sun Mar 13, 2016 12:43 pm
Sure we shall remove this option inside the print preview. Now you can directly print to pdf if you want to.

This is an old rude method saving the report pages as images. The size of pdf files would be huge if the number of pages are more.
Dear Rathi, are you replacing this feature with something improved or similar ? Because to export method is usefull too even for PDFs files.
Sorry dear friend Rathi to say... but please accept to review this, please  :!: :?:

Because IMHO, this is very hard to accept the cutting off of this feature, since that function you yourself did and that you said is rudimentary. In fact much of its implementation is very practical for last users, useful and yet should work very well.

The problem is something else ...
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
Pablo César
Posts: 4058
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 176 times

Post by Pablo César » Mon Feb 13, 2017 3:45 pm

Hello Claudio

I implemented the Persist function in the core HMG and altered the code for the purpose of identifying this problem.

There is not problem when we run (see Theo example file) with preview option in a dot matrix printer (Epson LX 300) and "save as" button for generating PDF file. But when I do the same test with the LaserJet 2200 Series PCL 5 printer ALWAYS gives an error and not generate any PDF at all.

In attached is the executable file with the library changed for testing.
 
reporttest.rar
Executable file (modified lib with Persist function)
(1.24 MiB) Downloaded 17 times
 
You will see that the problem originates in:
 
Screen92.png
Screen92.png (29.8 KiB) Viewed 192 times
 
Please note in the line of added While !Persist... is also added an identified message for identification.

I saw in the temp folder and the EMF file is OK, able and without error. But BT_BitmapLoadEMF it don want to load... :|

It seems It doesn't want to work properly in some files ok other not... And when start error, never all files is rejected... Why ?
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

User avatar
srvet_claudio
Posts: 1924
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 27 times
Been thanked: 99 times
Contact:

Post by srvet_claudio » Mon Feb 13, 2017 3:59 pm

I will check
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
Pablo César
Posts: 4058
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 176 times

Post by Pablo César » Mon Feb 13, 2017 5:18 pm

Ohhh I forgotten to put the modified code.

Please considere this code to be replaced with actual source code at end of function _HMG_PRINTER_SavePages ( h_controlmisc.prg ):

Code: Select all

cTempFolder := GetTempFolder()

nFiles := ADIR ( cTempFolder + _HMG_SYSDATA [ 379 ] + "_hmg_print_preview_*.Emf")

ASIZE ( aFiles , nFiles )

ADIR ( cTempFolder + _HMG_SYSDATA [ 379 ]  + "_hmg_print_preview_*.Emf" , aFiles )

For i := 1 To nFiles
    cFileEMF := cTempFolder + aFiles [i]
	
    cPrintFileName := cPath + cName + "_" + StrZero ( i , 4 )
	
	MsgDebug(cFileEMF,cPrintFileName)
	
    IF HMG_UPPER (cExt) == ".EMF"
	   * COPY FILE(cFileEMF) TO (cPrintFileName + cExt)
	   While !Persist( {|| FileCopy(cFileEMF , cPrintFileName+cExt)==FileSize(cFileEMF)} ) .and. MsgYesNo("Try again ?"+CRLF+"BT_BitmapSaveFile 1 - "+cPrintFileName)=.T. ; EndDo
	   
    ELSE 

       // by Dr. Claudio Soto, April 2014
       * hBitmap := BT_BitmapLoadEMF( cFileEMF, WHITE )
	   While !Persist( {|| (hBitmap := BT_BitmapLoadEMF(cFileEMF, WHITE), (hBitmap>0))} ) .and. MsgYesNo("Try again ?"+CRLF+"BT_BitmapLoadEMF - "+cFileEMF)=.T. ; EndDo
	   
       IF hBitmap <> 0 .AND. flag_PDF == .F.
	      * BT_BitmapSaveFile (hBitmap, cPrintFileName + cExt, nType)
		  While !Persist( {|| BT_BitmapSaveFile(hBitmap, cPrintFileName + cExt, nType)=.T.} ) .and. MsgYesNo("Try again ?"+CRLF+"BT_BitmapSaveFile 2 - "+cPrintFileName)=.T. ; EndDo
		  
          * BT_BitmapRelease (hBitmap)
		  While !Persist( {|| BT_BMP_RELEASE( hBitmap )=.T.} ) .and. MsgYesNo("Try again ?"+CRLF+"BT_BMP_RELEASE - "+cPrintFileName)=.T. ; EndDo
		  
       ENDIF

       IF hBitmap <> 0 .AND. flag_PDF == .T.   // by Rathinagiri (May 2014)
         if i == 1 
            nDPI    := 300
            nWidth  := ( BT_BitmapWidth ( hBitmap ) / nDPI * 25.4 )  
            nHeight := ( BT_BitmapHeight( hBitmap ) / nDPI * 25.4 )
            _HMG_HPDF_INIT ( cPath + cName + ".PDF", 1, 256, nHeight, nWidth, .f. )
            _hmg_hpdf_startdoc()
            _HMG_HPDF_SetCompression( 'ALL' )
         endif

         _hmg_hpdf_startpage()
         * BT_BitmapSaveFile (hBitmap, cPrintFileName + ".JPG", BT_FILEFORMAT_JPG)
		 While !Persist( {|| BT_BitmapSaveFile(hBitmap, cPrintFileName + ".JPG", BT_FILEFORMAT_JPG)=.T.} ) .and. MsgYesNo("Try again ?"+CRLF+"BT_BitmapSaveFile 3 - "+cPrintFileName)=.T. ; EndDo
		 
         * BT_BitmapRelease (hBitmap)
		 While !Persist( {|| BT_BMP_RELEASE( hBitmap )=.T.} ) .and. MsgYesNo("Try again ?"+CRLF+"BT_BMP_RELEASE - "+cPrintFileName)=.T. ; EndDo
         
         _HMG_HPDF_IMAGE ( cPrintFileName + ".JPG", 0, 0, nHeight, nWidth, .t. , "JPG" )
         _hmg_hpdf_endpage()
         
         FERASE ( cPrintFileName + ".JPG" )

         if i == nFiles
            _hmg_hpdf_enddoc()
         endif

       ENDIF

    ENDIF
Next i
Return Nil

Function Persist(bCondition, nTryUpTo)
LOCAL nTries := 0, lRet := .F.

If !ValType(bCondition)="B"
   MsgStop("First parameter must be a CodeBlock with logical return","First parameter is not a CodeBlock")
   Return .F.
Endif

DEFAULT nTryUpTo := 10

Do While nTries < nTryUpTo
   If Eval(bCondition)
      lRet := .T.
	  nTries := nTryUpTo
   Endif
   nTries++
EndDo
Return lRet
Thank you Claudio.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

trmpluym
Posts: 192
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands
Has thanked: 4 times
Been thanked: 11 times

Post by trmpluym » Mon Feb 13, 2017 9:51 pm

Pablo César wrote:
Sun Feb 12, 2017 8:29 pm

First of all, I want to ask for your forgiveness by I not having returned before. I was busy and recently I was able to see the installation of the HP LaserJet 2200 Series PCL 5 printer. :oops:

I installed, tested, and unlike my printer's drive, I suppose it requires more than the other. For the error appears eminently in all the times that I have tested. :|
Pablo, no need for appologies ! I am very pleased you took the time to test with another printer and experienced the same problem :)

I do not have the knowledge to solve this problem, but i also hope Claudio, Rathi and maybe others can find a solution to fix this nasty bug !

Theo

User avatar
Pablo César
Posts: 4058
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 176 times

Post by Pablo César » Mon Feb 27, 2017 1:31 pm

Hi Theo,

It seems the _HMG_PRINTER_SavePages is working properlly now with this recently Claudio's PATCH. :)

I guess the problem was in Boss Taurus function. Probably was solved when this had been updated: viewtopic.php?p=46496#p46496

Is it working now for you Theo ? Can I remove HP printer ? :)
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

trmpluym
Posts: 192
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands
Has thanked: 4 times
Been thanked: 11 times

Post by trmpluym » Mon Feb 27, 2017 6:04 pm

Pablo,

You are the greatest :D

Thanks for taking my problem seriously ! Your effort pointing Claudio in the right direction was the key for solving this nasty bug.

Off course i also want to thank Claudio for the Boss Taurus fix.

Problem solved, let's remove the HP printers :lol:

Theo

Post Reply