Page 1 of 2

FWSavePreviewToPDF 32-bit vs. 64-bit

PostPosted: Thu Feb 02, 2017 2:05 am
by don lowenstein
I use FWSavePreviewToPDF to create .PDF files

using FWH 32-bit version I can copy/paste text from the output.

using FWH 64-bit version COMPILING SAME EXACT CODE, I can not copy/paste text from the output. I can only copy an image section of the .PDF.

what can I do so that the 64-bit FWH allows me to copy / paste the pdf information as text?

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

PostPosted: Thu Feb 02, 2017 2:08 am
by don lowenstein
Correction - I use a different library for 32-bit PDF files.

therefore, my question is, how can I create FWH pdf file that allows the text to be copy/paste as text and not an image?

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

PostPosted: Thu Feb 02, 2017 2:35 am
by nageswaragunupudi
don lowenstein wrote:Correction - I use a different library for 32-bit PDF files.

therefore, my question is, how can I create FWH pdf file that allows the text to be copy/paste as text and not an image?


Not possible with FWSavePreviewToPDF .

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

PostPosted: Thu Feb 02, 2017 2:44 am
by don lowenstein
If I choose to preview the file first using the FWH preview, then click the "Save to PDF" button, I can indeed copy / paste text.

I don't see why the button on the report-preview screen from FWH will allow the copy / paste of text.

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

PostPosted: Thu Feb 02, 2017 10:45 am
by Antonio Linares
Don,

> Correction - I use a different library for 32-bit PDF files

Can't you get a 64 bits version of such library ?

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

PostPosted: Thu Feb 02, 2017 12:01 pm
by Carlos Mora
Hi Don

don lowenstein wrote:Correction - I use a different library for 32-bit PDF files.
therefore, my question is, how can I create FWH pdf file that allows the text to be copy/paste as text and not an image?

What are you iusing in 32 bits to generate regular (no images) pdfs?
The only one i know is PdfToImage.dll, but it has several issues related to fonts handling, and in some cases the conversion was far from accurate.


Carlos

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

PostPosted: Thu Feb 02, 2017 3:28 pm
by don lowenstein
clicking on the Export to PDF from the FiveWin previewer produces on that can be copy/pasted as text.

how does that happen?

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

PostPosted: Thu Feb 02, 2017 4:35 pm
by don lowenstein
I used Image2pdf.dll from utility warrior.

it is a 32-bit library and I can't seem to find this vendor anymore.

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

PostPosted: Fri Feb 03, 2017 10:21 am
by Antonio Linares
Don,

> clicking on the Export to PDF from the FiveWin previewer produces on that can be copy/pasted as text

Not sure if we can call the button function directly

We are checking it

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

PostPosted: Fri Feb 03, 2017 5:02 pm
by don lowenstein
FWSavePreviewToPDF is called by that button using a TPreview object I believe.

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

PostPosted: Fri Feb 03, 2017 5:57 pm
by don lowenstein
HB_FUNC( GDIPLUSEMFTOJPG )

this function is used by FWSavePreviewToPDF to create a jpeg file.

for some reason the file created by DDIPLUSEMFTOJPG contains a file extension of JPEG followed by Chinese-looking characters.

LPWSTR filefin = ( LPWSTR ) hb_parc( 3 );
CLSID cClsid ;

CLSIDFromString( L"{557CF401-1A04-11D3-9A73-0000F81EF32E}" , &cClsid ) ;
newImage->Save( filefin , &cClsid, &encoderParameters );


the FErase commmand does not work on these files with the "unusual" extension.

where does the unusual extension come from?

these odd files accumulate and don't get deleted by FErase.

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

PostPosted: Fri Feb 03, 2017 6:49 pm
by nageswaragunupudi
don lowenstein wrote:HB_FUNC( GDIPLUSEMFTOJPG )

this function is used by FWSavePreviewToPDF to create a jpeg file.

for some reason the file created by DDIPLUSEMFTOJPG contains a file extension of JPEG followed by Chinese-looking characters.

LPWSTR filefin = ( LPWSTR ) hb_parc( 3 );
CLSID cClsid ;

CLSIDFromString( L"{557CF401-1A04-11D3-9A73-0000F81EF32E}" , &cClsid ) ;
newImage->Save( filefin , &cClsid, &encoderParameters );


the FErase commmand does not work on these files with the "unusual" extension.

where does the unusual extension come from?

these odd files accumulate and don't get deleted by FErase.

We will look into this issue.

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

PostPosted: Sat Feb 04, 2017 10:14 am
by mastintin
don lowenstein wrote:HB_FUNC( GDIPLUSEMFTOJPG )

this function is used by FWSavePreviewToPDF to create a jpeg file.

for some reason the file created by DDIPLUSEMFTOJPG contains a file extension of JPEG followed by Chinese-looking characters.

LPWSTR filefin = ( LPWSTR ) hb_parc( 3 );
CLSID cClsid ;

CLSIDFromString( L"{557CF401-1A04-11D3-9A73-0000F81EF32E}" , &cClsid ) ;
newImage->Save( filefin , &cClsid, &encoderParameters );


the FErase commmand does not work on these files with the "unusual" extension.

where does the unusual extension come from?

these odd files accumulate and don't get deleted by FErase.


Change
LPWSTR filefin = ( LPWSTR ) hb_parc( 3 );

to this :

LPWSTR filefin = AnsiToWide( ( char * ) hb_parc( 3 ) );

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

PostPosted: Sat Feb 04, 2017 11:43 am
by Carlos Mora
don lowenstein wrote:I used Image2pdf.dll from utility warrior.

it is a 32-bit library and I can't seem to find this vendor anymore.


I was working for a couple of weeks with the owner of the library to fix several problems related to font identification in EMF records, but with no luck. Several month later the author emailed me an offer to buy the source code, becouse he was closing his software business. That was the last contact I had. Anyway, I wasn't happy with the library results and quit from using it since then.

In the first message you wrote that you were interested in copying text from prds. AFAIK, that cannot be done if the pdf is made of JPGs, unless you use some kind of OCR or so to do the conversion. Am I wrong?

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

PostPosted: Sat Feb 04, 2017 12:44 pm
by mastintin
My GdiplusEMFtojpg function is something other than fwh has. Also some changes would have some functions like Emm2Jpeg ,etc .
In my function besides regulating the quality of the image you can regulate the density (important in an impression)
I Put the modified function here (with another name not to mess with us) .
Code: Select all  Expand view


HB_FUNC( GDIP_EMFTOJPG )
{

  FILE * fil = fopen (  hb_parc(1) , "rb" ) ;
  fseek ( fil , 0 , SEEK_END ) ;
  int filesize = ftell ( fil ) ;

  fseek ( fil , 0 , SEEK_SET ) ;
  HGLOBAL hglobal = GlobalAlloc ( GMEM_MOVEABLE , filesize ) ;

  char * adr = (char *)GlobalLock ( hglobal ) ;
  int nbytes = fread ( adr , 1 , filesize , fil ) ;
  fclose ( fil ) ;

  if ( nbytes != filesize )
      {
       MessageBox( GetActiveWindow(), "fallo", "No carga la imagen", 0x30 );
      } ;

  LPSTREAM pstm = NULL ;
  GlobalUnlock ( hglobal ) ;

 CreateStreamOnHGlobal ( hglobal, TRUE, &pstm ) ;

 Metafile * original  = new Metafile( pstm ) ;

 LPWSTR filefin =   AnsiToWide( ( char * ) hb_parc( 2 ) );

 long quality  =  hb_parnl(3) ;
 double nDensity =  hb_parnl(4) ;

 int nWidth  =  original->GetWidth()  ;
 int nHeight =  original->GetHeight() ;

 CLSID  EncoderQuality ;

  double nAlto ;
  double nAncho ;

  if ( nWidth > nHeight )
     {
       nAlto  = ( 210 * nDensity ) / 25.4  ;
       nAncho = ( 297 * nDensity ) / 25.4  ;
     }
  else
     {
       nAncho =  ( 210 * nDensity) / 25.4  ;
       nAlto  =  ( 297 * nDensity ) / 25.4  ;
     }

  nHeight  = (int) nAlto ;
  nWidth   = (int) nAncho ;


  Bitmap * newImage = new Bitmap(nWidth, nHeight );
           newImage->SetResolution( nDensity, nDensity );

  Graphics * g =  new Graphics( newImage );
  g->Clear( Color::White ) ;
  g->SetSmoothingMode( SmoothingModeAntiAlias );

  g->DrawImage( original,0, 0, nWidth, nHeight);

  CLSIDFromString( L"{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}", &EncoderQuality ) ;
  EncoderParameters encoderParameters;

   encoderParameters.Count = 1;
   encoderParameters.Parameter[0].Guid = EncoderQuality ;
   encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
   encoderParameters.Parameter[0].NumberOfValues = 1;

  encoderParameters.Parameter[0].Value = &quality ;

  CLSID cClsid ;

  CLSIDFromString( L"{557CF401-1A04-11D3-9A73-0000F81EF32E}" , &cClsid ) ;

   newImage->Save( filefin , &cClsid, &encoderParameters );

  delete newImage ;
  delete g ;
  delete original ;
  pstm->Release();

}

 


changes in Emf2Jpeg( cEMF )
Code: Select all  Expand view


static function Emf2Jpeg( cEMF ,  nQuality,  nDensity )

   local cJpeg    := cFileSetExt( cEMF, "jpg" )
   local hDC1, hDC, hDib, hDib2, hMem, hBmp, hOldBmp, hEMF
   local cBuf, oRect, lRet := .f.
   local nFormat


DEFAULT nQuality := 100
DEFAULT nDensity := 300
 
#ifdef USEGDI
   if upper(right(cEMF,3)) == "EMF"
       GDIP_EMFTOJPG( cEMF , cJpeg  , nQuality,  nDensity )
   endif
   cBuf        := MemoRead( cJpeg )
#else

   cBuf         := MemoRead( cEMF )
   oRect        := TRect():New( 0, 0, Bin2L( SubStr( cBuf, 21, 4 ) ) / 2, ;
                                  Bin2L( SubStr( cBuf, 17, 4 ) ) / 2  )
   hEMF        := GetEnhMetaFile( cEMF )
   hDC1        := GetDC( GetDesktopWindow() )
   hDC         := CreateCompatibleDC( hDC1 )
   hBmp        := CreateCompatibleBitmap( hDC1, oRect:nWidth, oRect:nHeight )
   hOldBmp     := SelectObject( hDC, hBmp )
   FillRect( hDC, oRect:aRect, GetStockObject( 0 ) )
   PlayEMF( hDC, hEMF, oRect:cRect )

   hDib        := DibFromBitmap( hBmp )
   cBuf        := DibToStr( hDib )

   GlobalFree( hDib )
//   CloseEnhMetafile( hEMF )     // commented out 2014-02-13
   DeleteEnhMetafile( hEMF )      // inserted 2014-02-13

   SelectObject( hDC, hOldBmp )
   DeleteDC( hDC )
   DeleteDC( hDC1 )
   DeleteObject( hBmp )

   hMem        := FI_OpenMemory( cBuf, Len( cBuf ) )
   nFormat     := FI_GetFileTypeFromMemory( hMem, 0 )
   hDib        := FI_LoadFromMemory( nFormat, hMem, 0 )
   cBuf        := nil  // to release memory
   FI_CloseMemory( hMem )
   hDib2       := FICnv24( hDib )
   FIUnload( hDib )
   lRet        := FISave( 2, hDib2, cJpeg, JPEG_DEFAULT )
   FIUnload( hDib2 )
   cBuf        := If( lRet, MemoRead( cJpeg ), "" )
#endif
   FErase( cJpeg )

return cBuf

 


changes in Tpdf

Code: Select all  Expand view


 DATA nQuality, nDensity

METHOD New( cFile, cOrient ,nQuality, nDensity ) CLASS FWPDF

   DEFAULT cOrient   := "P"
   DEFAULT nQuality  := 50
   DEFAULT nDensity  := 300

   ::nQuality := nQuality
   ::nDensity := nDensity

   if cOrient == "P"
      ::nPageWidth   := a4_width
      ::nPageHeight  := a4_height
   else
      ::nPageWidth   := a4_height
      ::nPageHeight  := a4_width
   endif
   ::aRefs           := { 0, 0 }
   ::nDocLen      := PdfBegin( cFile )

return Self

METHOD AddMeta( cMeta ) CLASS FWPDF

   local nAt

   ::nPage++
   ::WritePage( Emf2Jpeg( cMeta, ::nQuality, ::nDensity  ) )

return Self

 


and changes in FWSavePreviewToPDF

Code: Select all  Expand view


function FWSavePreviewToPDF( oDevice, cPDF, lOpen, nQuality, nDensity  )   // oDevice can be oPrinter or oPreview

   local cOrient, oPDF
   local hWnd
   LOCAL aDatos:= {}
   DEFAULT nQuality :=  50
   DEFAULT nDensity := 300

  .........
   
      oPdf = fwPdf():New( cPdf, cOrient, nQuality, nDensity )
     
 .......