FWSavePreviewToPDF 32-bit vs. 64-bit

User avatar
don lowenstein
Posts: 196
Joined: Mon Oct 17, 2005 9:09 pm
Contact:

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

Post by don lowenstein »

After I added your code changes, I received many compiler errors for MS Visual Studio compiler
do your updated functions compile cleanly?

Code: Select all


Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24213.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

TDPrev2PDF.c


HB_FUNC_STATIC( PDFBEGIN ) // ( cPDF )

m:\bisys\allprg\TDPrev2PDF.prg(469): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\ucrt\stdio.h(207): note: see declaration of 'fopen'

HB_FUNC_STATIC( PGJPEG1 ) // ( nImageAt, nPage, nJpegWidth, nJpegHeight, cJpegBuf )

m:\bisys\allprg\TDPrev2PDF.prg(532): warning C4267: '+=': conversion from 'size_t' to 'LONG', possible loss of data
m:\bisys\allprg\TDPrev2PDF.prg(526): warning C4244: 'initializing': conversion from 'HB_SIZE' to 'LONG', possible loss of data
m:\bisys\allprg\TDPrev2PDF.prg(573): warning C4244: '=': conversion from 'HB_SIZE' to 'long', possible loss of data

HB_FUNC( GDIP_EMFTOJPG )

m:\bisys\allprg\TDPrev2PDF.prg(619): error C2065: 'Metafile': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(619): error C2065: 'original': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(619): error C2065: 'new': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(619): error C2106: '=': left operand must be l-value
m:\bisys\allprg\TDPrev2PDF.prg(619): error C2146: syntax error: missing ';' before identifier 'Metafile'
m:\bisys\allprg\TDPrev2PDF.prg(619): warning C4013: 'Metafile' undefined; assuming extern returning int
m:\bisys\allprg\TDPrev2PDF.prg(621): warning C4013: 'AnsiToWide' undefined; assuming extern returning int
m:\bisys\allprg\TDPrev2PDF.prg(626): error C2065: 'original': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(626): error C2223: left of '->GetWidth' must point to struct/union
m:\bisys\allprg\TDPrev2PDF.prg(627): error C2065: 'original': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(627): error C2223: left of '->GetHeight' must point to struct/union
m:\bisys\allprg\TDPrev2PDF.prg(649): error C2065: 'Bitmap': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(649): error C2065: 'newImage': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(649): error C2065: 'new': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(649): error C2106: '=': left operand must be l-value
m:\bisys\allprg\TDPrev2PDF.prg(649): error C2146: syntax error: missing ';' before identifier 'Bitmap'
m:\bisys\allprg\TDPrev2PDF.prg(649): warning C4013: 'Bitmap' undefined; assuming extern returning int
m:\bisys\allprg\TDPrev2PDF.prg(650): error C2065: 'newImage': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(650): error C2223: left of '->SetResolution' must point to struct/union
m:\bisys\allprg\TDPrev2PDF.prg(652): error C2065: 'Graphics': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(652): error C2065: 'g': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(652): error C2065: 'new': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(652): error C2106: '=': left operand must be l-value
m:\bisys\allprg\TDPrev2PDF.prg(652): error C2146: syntax error: missing ';' before identifier 'Graphics'
m:\bisys\allprg\TDPrev2PDF.prg(652): warning C4013: 'Graphics' undefined; assuming extern returning int
m:\bisys\allprg\TDPrev2PDF.prg(652): error C2065: 'newImage': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(653): error C2065: 'g': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(653): error C2223: left of '->Clear' must point to struct/union
m:\bisys\allprg\TDPrev2PDF.prg(653): error C2065: 'Color': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(653): error C2143: syntax error: missing ')' before ':'
m:\bisys\allprg\TDPrev2PDF.prg(653): error C2059: syntax error: ')'
m:\bisys\allprg\TDPrev2PDF.prg(654): error C2065: 'g': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(654): error C2223: left of '->SetSmoothingMode' must point to struct/union
m:\bisys\allprg\TDPrev2PDF.prg(654): error C2065: 'SmoothingModeAntiAlias': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(656): error C2065: 'g': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(656): error C2223: left of '->DrawImage' must point to struct/union
m:\bisys\allprg\TDPrev2PDF.prg(656): error C2065: 'original': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(659): error C2065: 'EncoderParameters': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(659): error C2146: syntax error: missing ';' before identifier 'encoderParameters'
m:\bisys\allprg\TDPrev2PDF.prg(659): error C2065: 'encoderParameters': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(661): error C2065: 'encoderParameters': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(661): error C2224: left of '.Count' must have struct/union type
m:\bisys\allprg\TDPrev2PDF.prg(662): error C2065: 'encoderParameters': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(662): error C2224: left of '.Parameter' must have struct/union type
m:\bisys\allprg\TDPrev2PDF.prg(663): error C2065: 'encoderParameters': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(663): error C2224: left of '.Parameter' must have struct/union type
m:\bisys\allprg\TDPrev2PDF.prg(663): error C2065: 'EncoderParameterValueTypeLong': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(664): error C2065: 'encoderParameters': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(664): error C2224: left of '.Parameter' must have struct/union type
m:\bisys\allprg\TDPrev2PDF.prg(666): error C2065: 'encoderParameters': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(666): error C2224: left of '.Parameter' must have struct/union type
m:\bisys\allprg\TDPrev2PDF.prg(672): error C2065: 'newImage': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(672): error C2223: left of '->Save' must point to struct/union
m:\bisys\allprg\TDPrev2PDF.prg(672): error C2065: 'encoderParameters': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(674): error C2065: 'delete': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(674): error C2146: syntax error: missing ';' before identifier 'newImage'
m:\bisys\allprg\TDPrev2PDF.prg(674): error C2065: 'newImage': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(675): error C2065: 'delete': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(675): error C2146: syntax error: missing ';' before identifier 'g'
m:\bisys\allprg\TDPrev2PDF.prg(675): error C2065: 'g': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(676): error C2065: 'delete': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(676): error C2146: syntax error: missing ';' before identifier 'original'
m:\bisys\allprg\TDPrev2PDF.prg(676): error C2065: 'original': undeclared identifier
m:\bisys\allprg\TDPrev2PDF.prg(677): error C2039: 'Release': is not a member of 'IStream'
C:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\um\objidlbase.h(2394): note: see declaration of 'IStream'
m:\bisys\allprg\TDPrev2PDF.prg(598): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
C:\Program Files (x86)\Windows Kits\10\include\10.0.14393.0\ucrt\stdio.h(207): note: see declaration of 'fopen'
m:\bisys\allprg\TDPrev2PDF.prg(606): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
m:\bisys\allprg\TDPrev2PDF.prg(621): warning C4047: 'initializing': 'LPWSTR' differs in levels of indirection from 'int'


 
Don Lowenstein
www.laapc.com
User avatar
mastintin
Posts: 1502
Joined: Thu May 27, 2010 2:06 pm

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

Post by mastintin »

Sorry for the delay .
My code compile for harbour bcc7 32bits. I could not tell you the corrections to make but I see that it includes GDIP_EMFTOJPG in TDPrev2PDF.prg.
This is not correct GDIP_EMFTOJPG is c++ code and has to be included in gdiplus.cpp or place it in a new cpp file including the includes and headers that are in gdiplus.cpp

I have a much simpler code in case it works for you.
Only 2 functions .

in gdiplus.cpp add :

Code: Select all


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();

}

 
add this function in rpreview ( for example )

Code: Select all



FUNCTION FwPrvTopdf( oPreview, cPdf, nQuality, nDensity )

   local i
   LOCAL cMsg, cExt
   local oPdf
   local aFilesDelete:= {}
   local cJpg
   LOCAL aJpg := oPreview:oDevice:aMeta
//   LOCAL Time:= Seconds()

   DEFAULT  nQuality := 50
   DEFAULT  nDensity := 300

   cExt  := "*.pdf"
   cMsg    = "PDF" + " " + FWString( "File to Save" ) + "( " + cExt + ") |" + cExt + "|"

  if Empty( cPdf ) .and. Empty( cPdf := cGetFile( cMsg, FWString( "File to Save" ), 1, CurDir(), , .t. ) )
      return nil
   endif

    oPdf  := FWPdf():New( cPDF )

   if ValType( aJpg ) != 'A'
      aJpg     := { aJpg }
   endif

   for i = 1 to len( aJpg )
      cJpg := aJpg[i]

      if Upper( cFileExt( cJpg ) ) != "JPG"
         cJpg:= cFileSetExt( cJpg, "jpg" )
         aadd( aFilesDelete, cJpg )
         GDIP_EMFTOJPG( aJpg[i], cJpg, nQuality,  nDensity  )
      endif

      oPdf:nPage++
      oPdf:WritePage( MemoRead( cJpg ) )
      sysrefresh()
   next

   oPdf:Close()
   if len(aFilesDelete) > 0
      AEval( aFilesDelete, { |cFile| FErase( cFile )  } )
   endif
//   msginfo( Seconds()-Time )

RETURN nil
 
and in rpreview add button for impresion pdf ( i use for test the zoom buttom :-) )

DEFINE BUTTON ::oZoom OF oBar GROUP ;
MESSAGE FWString( "Page zoom" ) ;
ACTION FwPrvTopdf( Self,, 50, 200 ) ; //::Zoom() ;
TOOLTIP FWString( "Zoom" )
User avatar
don lowenstein
Posts: 196
Joined: Mon Oct 17, 2005 9:09 pm
Contact:

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

Post by don lowenstein »

Do these coding changes include writing to a PDF that allows copy / paste like the Export to PDF Button on the FW Previewer?
Don Lowenstein
www.laapc.com
User avatar
mastintin
Posts: 1502
Joined: Thu May 27, 2010 2:06 pm

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

Post by mastintin »

No .This code render the emf files in jpg files and thats is embedded in the pdf.
Being an image and not a text I do not think it can be copied and pasted.
For this the solution for what you intend is to use the Harbour Harupdf contribution.
see this: http://forums.fivetechsupport.com/viewt ... =6&t=33439
User avatar
don lowenstein
Posts: 196
Joined: Mon Oct 17, 2005 9:09 pm
Contact:

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

Post by don lowenstein »

what code does the Previewer button execute?
Don Lowenstein
www.laapc.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

Post by Antonio Linares »

what button of the previewer do you mean ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
don lowenstein
Posts: 196
Joined: Mon Oct 17, 2005 9:09 pm
Contact:

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

Post by don lowenstein »

i will send an email to you with a picture of the button.

the tooltip says "Export to PDF"
Don Lowenstein
www.laapc.com
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

Post by nageswaragunupudi »

don lowenstein wrote:i will send an email to you with a picture of the button.

the tooltip says "Export to PDF"
We understand. It is not necessary to send picture.

When we print for preview, the printer class writes the output to emf files. The emf files contain vector images of the output to be printed. One emf file per page.

Preview class just displays the images contained in the emf files and prints them on printer when required. Obviously, the preview class deals with images only and does not know anything about the text or graphics contained there in.

Exporting or Saving as Word Document:

It is possible to export the emf files to MSWord if MSOffic is installed, by clicking on "Export to Word" button or "SaveAs Word Document" button. For this purpose, the preview class embeds emf images into MSWord document, one image per page. Obviously the Word document created this way contains images only but not any text. In case MS Word is not installed but OpenOffice is installed, then OpenOffice API is used to save as word document.

If the programmer has a better way of exporting/saving as Word Document, then he can override this default behavior by assigning his own function to DATA bSaveAsWord clodeblock.

Exporting to PDF:

If the programmer has a preferred way of exporting to PDF, he may specify his function in the DATA bSaveAsPDF codeblock. For example, when he prefers to use a 3rd party library or writes his own PDF generation logic.

Otherwise, preview class takes the following default actions:

1) If MSWord is installed, first exports the vector images contained in the emf files to MSWord document (same way as above) and uses MSWords' capabilities to save the document as PDF.

In this case the quality of output is good and the file sizes are small enough.

2) Otherwise, FWH provides the last fallback option. FWH itself converts the vector images as jpeg images and embeds into PDF files one image per page and saves the document, using its own function FWSavePreviewToPDF(). This function behaves the same way with all compilers 32/64 bit.

This is the last option when better options are not available. Output file sizes are large and quality is slightly less. For obvious reasons, we can not compare the quality with dedicated software which exist solely for generating PDFs.

Even using Print to PDF kind of drivers generate better output.

For occasional use, FWSavePreviewToPDF() does the job. But for bulk jobs, it is desirable to use external libraries or drivers, dedicated for this purpose, paid or free.
Regards

G. N. Rao.
Hyderabad, India
User avatar
don lowenstein
Posts: 196
Joined: Mon Oct 17, 2005 9:09 pm
Contact:

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

Post by don lowenstein »

i still have a question "How does FWH Previewer Export to PDF option create output with copy/paste capabilities?"
Don Lowenstein
www.laapc.com
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: FWSavePreviewToPDF 32-bit vs. 64-bit

Post by nageswaragunupudi »

don lowenstein wrote:i still have a question "How does FWH Previewer Export to PDF option create output with copy/paste capabilities?"
I am not sure if I understand what exactly do you have in mind.

Previewer's Export to PDF option does not allow Paste of any text or any clipboard content to the contents (vector images) of the emf files.

What FWSavePreviewToPDF() function does is :
step1: convert vector images contained in emf files as raster image in jpeg format
step2: create blank pdf page and embed the jpeg image into the pdf page
step3: save the pdf file
Regards

G. N. Rao.
Hyderabad, India
Post Reply