FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour .pdf to .tif?
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
.pdf to .tif?
Posted: Sun Mar 13, 2016 06:41 PM

Hello everyone.

I need to convert some .pdfs into .tifs. Can we do this using fwh?

Reinaldo.

Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: .pdf to .tif?
Posted: Mon Mar 14, 2016 10:55 AM
Que yo sepa no se puede directamente , un truco puede ser mostrarlo en pantalla y capturarlo ...
pongo aquí un código que me funciona aunque la calidad del tif resultante no es muy buena ya que depende de cada resolución y tamaño de pantalla .

el asunto este en :
function captureWnd( oWnd, cFile, ntop,nleft,nWidht, nHeight )

parametros :

1.- ownd
2.- el nombre de archivo a grabar , puede ser tif,jpg,bmp,png
los siguientes parametros son el recorte a realizar en lo capturado ( la ventana ) , top,left,width,height

Esta basado en el sample pdf2.prg ....
Code (fw): Select all Collapse
#include "FiveWin.ch"



function Main()

   local oWnd, oBtn

   lShow := .f.

   DEFINE WINDOW oWnd TITLE "FiveWin ActiveX Support" ;
   FROM 5,5 TO 800, 550 PIXEL
   
   @ 2, 2 BUTTON oBtn PROMPT "Show PDF" SIZE 80, 20 ACTION ShowPDF( oWnd, oBtn )

   ACTIVATE WINDOW oWnd 


return nil

function ShowPDF( oWnd, oBtn )

   local oActiveX
   
  
      
   oActiveX = TActiveX():New( oWnd, "AcroPDF.PDF.1" ) // Use "AcroPDF.PDF.1" for Acrobat Reader 7 

   oWnd:oClient = oActiveX // To fill the entire window surface

   oActiveX:Do( "LoadFile", "normal.pdf" )
   oActiveX:Do( "SetCurrentPage", 1 )
   oActiveX:Do( "setShowToolbar", 0  )
   oBtn:Hide()
   oWnd:ReSize()
   
   if msgYesNo( "capturar?")
      captureWnd( oWnd, "yo.tif", 45,90, oWnd:nWidth-82, ownd:nHeight-142 )   
   endif
 

return nil   

function captureWnd( oWnd, cFile, ntop,nleft,nWidth, nHeight )
local oImage:= GDIBmp():new()  
     oImage:hbmp:=GDIPLUSCAPTURERECTWND(ownd:hWnd, nTop,nLeft,nWidth,nHeight )    
     oImage:save( cFile )
return nil


en el archivo gdiplus.cpp añadir ....

Code (fw): Select all Collapse
HB_FUNC( GDIPLUSCAPTURERECTWND )
{
  
   HWND hWnd = ( HWND ) hb_parnl( 1 )  ;
   int nTop  = hb_parni( 2 );
   int nLeft = hb_parni( 3 );
   int nWidth  = hb_parni( 4 );
   int nHeight = hb_parni( 5 );
   
   HDC hWndDC = GetDC( hWnd );
   HDC hCaptureDC = CreateCompatibleDC( hWndDC );
   RECT rcClient;
   GetClientRect(hWnd, &rcClient);
   HBITMAP hCaptureBitmap = CreateCompatibleBitmap( hWndDC, rcClient.right-rcClient.left, rcClient.bottom-rcClient.top );

   SelectObject( hCaptureDC, hCaptureBitmap );
   BitBlt( hCaptureDC, 0, 0, rcClient.right-rcClient.left, rcClient.bottom-rcClient.top,
           hWndDC,0, 0, SRCCOPY | CAPTUREBLT );

   Bitmap * original =  new Bitmap( hCaptureBitmap, NULL );

   ReleaseDC( hWnd, hWndDC );
   DeleteDC( hCaptureDC );
   DeleteObject( hCaptureBitmap );

   Bitmap* newImage  = new Bitmap( nWidth, nHeight);

   Graphics * graphics = new Graphics( newImage );
     
   Rect destino ( 0 , 0 , nWidth, nHeight );  
   graphics->DrawImage( original, destino , nTop , nLeft , nWidth, nHeight, UnitPixel );

   delete graphics ;
   delete original ;

   hb_retnl( ( HB_LONG ) newImage );     
     
}
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: .pdf to .tif?
Posted: Mon Mar 14, 2016 01:42 PM

Mastintín; Muchas gracias por esta respuesta.

Saludos.

Reinaldo.

Posts: 2
Joined: Mon Mar 14, 2016 12:49 PM
Re: .pdf to .tif?
Posted: Mon Mar 14, 2016 03:34 PM

Reinaldo,

I've used Ghostsccript to do this at a few client sites. You just have to make sure to use the EXE and not the Ghostscript source code in order not to step into the GPL licensing requirements. Using the EXE and performing a ShellExecute will give you great results.

For example:

http://drakedwornik.com/2013/02/05/simp ... f-to-tiff/

You can automate the whole process by creating a windows service that monitors PDF files as they are dropped in a folder where the service invokes Ghostscript via a batch file with the proper commands where the resulting TIFF/JPGs can then be output to another folder that you application can watch for files as they are created.

Rene.

Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: .pdf to .tif?
Posted: Mon Mar 14, 2016 03:53 PM

Rene;

That's exactly what I was looking for.

Thank you very much for sharing this solution.

Reinaldo.

Posts: 2
Joined: Mon Mar 14, 2016 12:49 PM
Re: .pdf to .tif?
Posted: Mon Mar 14, 2016 05:09 PM

No worries - here's another example - better at that:

http://drakedwornik.com/2013/03/06/batc ... n-windows/

Continue the discussion