.pdf to .tif?

.pdf to .tif?

Postby reinaldocrespo » Sun Mar 13, 2016 6:41 pm

Hello everyone.

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

Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: .pdf to .tif?

Postby mastintin » 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: Select all  Expand view


#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  Expand view



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
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: .pdf to .tif?

Postby reinaldocrespo » Mon Mar 14, 2016 1:42 pm

Mastintín; Muchas gracias por esta respuesta.

Saludos.


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: .pdf to .tif?

Postby renep » Mon Mar 14, 2016 3: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.
renep
 
Posts: 2
Joined: Mon Mar 14, 2016 12:49 pm

Re: .pdf to .tif?

Postby reinaldocrespo » Mon Mar 14, 2016 3:53 pm

Rene;

That's exactly what I was looking for.

Thank you very much for sharing this solution.


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: .pdf to .tif?

Postby renep » Mon Mar 14, 2016 5:09 pm

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

http://drakedwornik.com/2013/03/06/batc ... n-windows/
renep
 
Posts: 2
Joined: Mon Mar 14, 2016 12:49 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 63 guests