.pdf to .tif?

Post Reply
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

.pdf to .tif?

Post by reinaldocrespo »

Hello everyone.

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

Reinaldo.
User avatar
mastintin
Posts: 1502
Joined: Thu May 27, 2010 2:06 pm

Re: .pdf to .tif?

Post by mastintin »

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: Select all


#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: Select all



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

 
Last edited by mastintin on Mon Mar 14, 2016 3:18 pm, edited 1 time in total.
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: .pdf to .tif?

Post by reinaldocrespo »

Mastintín; Muchas gracias por esta respuesta.

Saludos.


Reinaldo.
renep
Posts: 2
Joined: Mon Mar 14, 2016 12:49 pm

Re: .pdf to .tif?

Post by renep »

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.
User avatar
reinaldocrespo
Posts: 918
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: .pdf to .tif?

Post by reinaldocrespo »

Rene;

That's exactly what I was looking for.

Thank you very much for sharing this solution.


Reinaldo.
renep
Posts: 2
Joined: Mon Mar 14, 2016 12:49 pm

Re: .pdf to .tif?

Post by renep »

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

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