Rpreview issues - PDF

Re: Rpreview issues - PDF

Postby nageswaragunupudi » Wed May 08, 2019 11:53 am

image2pdf embeds images only. How does it do in such a small size?
How is MSWord doing it?
Let us not rule out.
It is just that we do not know how they are doing it.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Rpreview issues - PDF

Postby AntoninoP » Wed May 08, 2019 12:37 pm

I think image2pdf do the same think of my code but: without libharu and removing the redundant and unused commands, may be should be interesting compare the PDF result, almost the not binary part...
And I think that MSWord convert the EMF in word (lines, text-box) and then the word is converted in PDF (It would explain the bigger size)
obviously they are IMHO

For images, there is a support, I tried some files from http://frazmitic.free.fr/emfexplorer/downloads.htm#_Resources some works others no :) for example the tiger works :lol:

I'd be curious about the "LISTADO DE ARTICULOS" of Mastintin, can you send a emf to antonino.perricone_AT_yahoo_DOT_it ?
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: Rpreview issues - PDF

Postby mastintin » Wed May 08, 2019 2:19 pm

mail send. :-)
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Rpreview issues - PDF

Postby nageswaragunupudi » Wed May 08, 2019 2:21 pm

Mr. Antonio

Thanks for the explanation.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Rpreview issues - PDF

Postby hmpaquito » Wed May 08, 2019 5:10 pm

Very interesting conversation
Very interesting previous conversation http://fivetechsupport.com/forums/viewt ... 15#p212073
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Rpreview issues - PDF

Postby TimStone » Wed May 08, 2019 5:59 pm

I've been away from this for awhile ( traveling ) but saw the recent update to comments. As the originator of the thread I wanted to share my ultimate resolution.

I have used Img2Pdf for many years and it has been very good. However, I was not using color in any of my printouts. They are all directly coded with the tPrinter class and have worked quite well. The PDF's created with Img2Pdf were small and created quickly.

When I decided to add color, I had some problems. So I used SayText( ) instead of Say( ) method and this created problems with my older version of Img2Pdf. Those issues were improved with the newer release of that library, but some still existed. For example, the Box( ) method required enlargement or text within the box, though fine on the preview, would cut off lines in the PDF. In addition, the length of the SayText( ) would have to be defined to fit inside of any other boxes/shading or they would cut off the graphic in the PDF. Finally, I used a watermark on the document ( invoice ), using SayImage( ) and it would not display at all.

If I used the native FWH output, I did not need to make any changes to my coding, and the PDF's were perfect copies of the preview and the printed document. Although the documents were larger, they were still acceptable for emailing.

As a result of this, for invoices, which were the only documents I was using color / graphics, I have the system set to use the native FWH PDF generation, and for all of the report documents that remain simply text without graphics I continue to use the Img2Pdf.

This topic has created interest in providing the best PDF's within FWH and I will be happy to test any options that people may provide. I know people always like samples, but my invoice printout is quite detailed, and involves about 1500 lines of code, so it would be a bit difficult to "condense" into a testable size.

I look forward to the further discussions on this topic.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Rpreview issues - PDF

Postby AntoninoP » Thu May 09, 2019 7:22 am

If you want, I can test your emf with my code, I wrote my email some post ago
During the preview, you can find the EMF inside %temp%, you can write it in explorer address bar:
Image
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: Rpreview issues - PDF

Postby nageswaragunupudi » Thu May 09, 2019 10:54 am

Now that all the experts are here, this appears to be the best place for me to learn from them.

I downloaded Mr. Antonio's emf2pdf.prg from this link:
https://github.com/APerricone/emf2pdf

In case this is not the final version, I would be grateful if I am directed to the final version.

This is my test program
Code: Select all  Expand view

#include "fivewin.ch"

REQUEST DBFCDX

//----------------------------------------------------------------------------//

function Main()

   USE CUSTOMER VIA "DBFCDX"
   SET FILTER TO RECNO() < 20
   GO TOP

   TPreview():bSaveAsPDF := { |oPreview| TestPDF( oPreview ) }

   XBROWSER "CUSTOMER" COLUMNS "FIRST", "CITY", "SALARY"

return nil

function TestPDF( oPreview )

   CreatePDF( "newtest.pdf", oPreview:oDevice:aMeta ) // emf2pdf.prg
   ShellExecute( 0, "open", "newtest.pdf" )

return nil
 


I added emf2pdf.prg to the link list, after making these minor modifications:
1) Commented out the function Main()
2) Added call to function GetFonts() at the beginning of the function CreatePDF(...)
3) The function CreatePDF() expects directory of emf files whereas I am passing an array of emf files. Therefore I modified this line
Code: Select all  Expand view

    for each f in aMetas
//        hMeta := GetEnhMetaFile(f[1])
        hMeta := GetEnhMetaFile(f)
 

4) Got two undeclared symbols and so I added these two local variable declarations
(i)
Code: Select all  Expand view

static proc pdf_Header(pdf,pRecord,pTable)
   local page // GNR
 

(ii)
Code: Select all  Expand view

static proc pdf_TextOut(page,pRecord)
LOCAL i // GNR
 

These are the only changes I made.

Used "harupdf.ch" from \harbour\contrib\hbhpdf\ folder

Linked \harbour\lib\hbhpdf.lib

Linked libhpdf.lib provided to by Mr. Cristobal saying this to be the libharu.lib.

Built and executed. The pdf file generation was instantaneous.

This is my preview:
Image
This is the pdf generated:
Image


Looks like I am doing something wrong. I sincerely request the experts to guide me the correct way.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Rpreview issues - PDF

Postby AntoninoP » Thu May 09, 2019 12:54 pm

You did it wrong, emf2pdf.prg is a very old version where I tried to do the conversion in harbour, after I am passed to C++.

You must add Emf2Pdf.cpp to your project, adding the define __HARBOUR__ to c compiler (with command line -D__HARBOUR__) in this way this piece of code at end of emf2pdf.cpp will be compiled:
Code: Select all  Expand view
#ifdef __HARBOUR__

#include <hbapi.h>
#include <hbhpdf.h>

HB_FUNC(HPDF_ADDEMF) // pdf (Pointer), cEMFFIle (stringa)
{
    HPDF_Doc pdf = hb_HPDF_Doc_par(1);
    if (pdf == 0)
    {
        hb_ret();
        return;
    }
    Emf2Pdf conv(pdf);
    conv.AddEMF(hb_parc(2));
    hb_ret();
}

#endif


so the code to use are (fromhttps://github.com/APerricone/emf2pdf/blob/master/FWH_Test/main.prg)
Code: Select all  Expand view
TPreview():bSaveAsPDF := {|o| TPrinter2PDF(o:oDevice)}

and
Code: Select all  Expand view
PROC TPrinter2PDF(oPrn, cFile)
   LOCAL i, oPdf := HPDF_New()
   DEFAULT cFile := cGetFile( "(*.pdf)|*.pdf|", "Select PDF File to Save",, CurDir(), .T. )
   //if !empty(oPrn:aMeta)
   //   ? oPrn:aMeta[1]
   //endif
   for i:=1 to len(oPrn:aMeta)
      HPDF_ADDEMF(oPdf, oPrn:aMeta[i])
   next
   HPDF_SaveToFile( oPdf, cFile)
return


edit: removed debug code from sample
Last edited by AntoninoP on Thu May 09, 2019 2:22 pm, edited 1 time in total.
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: Rpreview issues - PDF

Postby nageswaragunupudi » Thu May 09, 2019 2:05 pm

Mr. Antonio

Thank you. I will try.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Rpreview issues - PDF

Postby mastintin » Thu May 09, 2019 4:55 pm

I have tried with "Microsoft Print to PDF" and it gives a great result.
This code to test ( you have to have win10 and the printer installed. )
Code: Select all  Expand view

 
  TPreview():bSaveAsPDF := { |o| SaveMSPdf( o ) }

Function SaveMSPdf( oPreview )
   local cPrnName := "Microsoft Print to PDF"

      If AScan( aGetPrinters(), cPrnName ) > 0
         oPreview:SelPrinter( cPrnName )
         oPreview:PrintPage()
      else
         Msginfo( "impresora "+ cPrnName + " no encontrada" )
      endif

Return nil
 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Rpreview issues - PDF

Postby hmpaquito » Thu May 09, 2019 5:34 pm

mastintin wrote:I have tried with "Microsoft Print to PDF" and it gives a great result.
This code to test ( you have to have win10 and the printer installed. )
Code: Select all  Expand view

 
  TPreview():bSaveAsPDF := { |o| SaveMSPdf( o ) }

Function SaveMSPdf( oPreview )
   local cPrnName := "Microsoft Print to PDF"

      If AScan( aGetPrinters(), cPrnName ) > 0
         oPreview:SelPrinter( cPrnName )
         oPreview:PrintPage()
      else
         Msginfo( "impresora "+ cPrnName + " no encontrada" )
      endif

Return nil
 



Microsoft Print to PDF use is limited.

Only Windows 10.
How to silent mode ?
How to configure ?
How to assignt pdf full file path name ?

Limited, I think.

Regards.
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Rpreview issues - PDF

Postby mastintin » Thu May 09, 2019 6:11 pm

hmpaquito wrote:Microsoft Print to PDF use is limited.

Only Windows 10.
How to silent mode ?
How to configure ?
How to assignt pdf full file path name ?

Limited, I think.

Regards.


Yes Correct. :-)
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Rpreview issues - PDF

Postby mastintin » Sat May 11, 2019 9:03 am

AntoninoP , more code for TPrinter2PDF. RoundRect support :-)

It would be necessary to clean the code and do more intensive tests.
:-)

Code: Select all  Expand view


void Emf2Pdf::ParseFile()
{
....
  case EMR_ROUNDRECT:          nRead += RoundRectangle(); break;
.....
}

//-------------------------------

#include <math.h>

#ifndef min
   #define min(a,b) ((a)<(b)?(a):(b))
#endif

size_t Emf2Pdf::RoundRectangle()
{
   size_t ret = 0;
   RECTL bound;
   fread(&bound, 4, 4, f);  ret += 16;

   PRINT_DBG("  (%ix%i)-(%ix%i) \r\n", bound.right, bound.bottom, bound.left, bound.top);

   float x = bound.left * xScale;
   float r = bound.right * xScale;
   float b = currHeight - bound.bottom * yScale;
   float t = currHeight - bound.top * yScale;

   float w = (bound.right - bound.left) * xScale;
   float h = (bound.bottom - bound.top) * yScale;

   unsigned long cx;
   unsigned long cy;

   fread(&cx, 4, 1, f); ret += 4;
   fread(&cy, 4, 1, f); ret += 4;

   PRINT_DBG("  %i points\r\n", cx);
   PRINT_DBG("  %i points\r\n", cy);


   float fcx = cx *xScale;
   float fcy = cy *yScale;

    float nRound =  min( fcx, fcy ) ;

    double  nRay  ;

    float  currWidth = HPDF_Page_GetWidth( page ) ;

    if ( currWidth  > currHeight ) {
       nRay = round(min( nRound, int(h)/2 )) ;
     }
   else
      {
      nRay =  round(min( nRound, int(w)/2) ) ;
       }


      HPDF_Page_MoveTo ( page, x + nRay,  t )  ;
      HPDF_Page_LineTo ( page, r - nRay, t )  ;

      HPDF_Page_CurveTo( page, r, t, r,  t, r,  t - nRay )  ;

      HPDF_Page_LineTo ( page, r, b + nRay );

      HPDF_Page_CurveTo( page, r, b, r, b, r - nRay,  b  )  ;
      HPDF_Page_LineTo ( page, x + nRay, b )       ;
      HPDF_Page_CurveTo( page, x, b,  x, b, x, b + nRay )   ;

      HPDF_Page_LineTo ( page, x, t - nRay )    ;
      HPDF_Page_CurveTo( page, x, t,  x, t, x + nRay, t ) ;


   //  HPDF_Page_GSave(page) ;

   if (currentPen.width > 0 && currentBrush.solid)
   {
      HPDF_Page_FillStroke(page);
   }
   else if (currentPen.width > 0)
   {
      HPDF_Page_Stroke(page);
   }
   else if (currentBrush.solid)
   {
      HPDF_Page_Fill(page);
   }

   return ret;
}

 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 61 guests