Treat my content as plain text, not as HTML. They have been very helpful even in customizing their thumbnil for a particular need of mine. Post as a guest Name. Applying page numbers in itextsharp pdf. This works ok but the images do appear a bit pixelated from being shrunk.
|Published (Last):||14 December 2014|
|PDF File Size:||14.80 Mb|
|ePub File Size:||14.7 Mb|
|Price:||Free* [*Free Regsitration Required]|
Introduction This article presents VB. Often when looking for documents it is much easier to find what you want visually, for example seeing the cover of a document. The application was written for a website that I was developing that needed to display links to PDF documents. Instead of just showing a little PDF icon next to each document we wanted to display the front page of the actual document.
As shown below, this gives the listings better aesthetics and also enables the users to find documents quicker if they recognise it. We then had this application scheduled as a batch service to run every 5 minutes and check for new files. In the backend system the documents have metadata stored in a SQL Server database. Using the Acrobat SDK also meant we could programmically read the PDF metadata and retrieve the number of pages in the document, which could then be displayed as well.
Although the end users could have entered that information it meant less work for them and a better overall impression of the web site. Approach To generate the thumbnail image for each document I used the Adobe Acrobat 5. NET 1. Note: do not confuse the thumbnails that are part of a PDF document with the. Then using the. NET Framework we can copy this to a bitmap, scale and combine that image and then save the result as a. To achieve this effect I created a transparent. By making the bottom-left pixel transparent too we can easily set the transparent colour for a bitmap in.
I keep the top-right of the image white where the corner folds over, that means I can just combine the images by drawing the transparent template directly over the PDF image to achieve the final look.
The Adobe Acrobat 5. The latest SDK for Acrobat 6. To quickly see if you have the full version of Adobe Acrobat installed, use regedit. The code was written in VB. NET using the. Initially we create an instance of AcroExch. PDDoc using late-binding. The referenced Adobe Acrobat 5. By referencing the type library we can get the Intellisense and strong-typing of the other Acrobat objects.
From this we can get a rectangle object of the actual page dimensions. Finally we render the PDF page to the clipboard at full size. We could have Acrobat scale the image down for us by a percentage, but we can get better visual results using the. NET scaling algorithms of the Bitmap class. It would have been more efficient to render directly to an off-screen bitmap, and also not have overwritten what ever was previously on the clipboard, but I found the clipboard method the most stable way to get a rendered bitmap of the page using Acrobat.
Note: the Draw method is deprecated, as it only works on Win16 systems where hWnd was unique to Windows and not to each process as on NT. Rect" pdfRect. Set the correct file to load as the template, and if it is landscape, switch the width and height. GetData DataFormats. We use both because the Bitmap class supports MakeTransparent and the image can easily be passed to the Graphics. DrawImage method. Render the pdfImage using the GetThumbnailImage method of the.
NET Framework Bitmap class, this provides a very smooth scaled version of the image. Next create a blank bitmap with room for the template border. Set the templateBitmap to use the bottom-left pixel of the image as the transparency colour using calling MakeTransparent. See an article on Chris Sells website for more on transparencies in. Using the new blank bitmap, draw the rendered pdf page image to it and then the template with transparency directly over the top.
Because it is transparent the main area of the page template will still appear through. Finally, save the composited image back as a. Save outputFile, Imaging. Png Write some feedback to the console as we work through each of the files. WriteLine "Generated thumbnail Dispose pdfDoc. Close Marshal. ReleaseComObject pdfPage Marshal. ReleaseComObject pdfRect Marshal. Even though the application is actually a console application we still need System.
Form as the clipboard dataformats are from there. Use the app. Which we can see in the screenshot below. Further Enhancements Further improvements might be to: Render directly to an off-screen bitmap rather than to the clipboard. Remove the reliance on having a full version of Adobe Acrobat by using Ghostscript libraries instead. One case we had was documents that could be viewed internally but were blocked due to compliance issues for external users, by designing different templates and rendering them with the page it was obviously the document was private further enhancing usuability, eg.
Points of Interest The Adobe Acrobat 5. If running under an NT service account the screen resolution and depth make a difference; for example if your server is only set for colours in x , and if the console application is run via the service it will not be able to render bit colour thumbnails. Also, if running in a batch on a server you should check the terms of the Acrobat license agreement to whether you are allowed to run the Adobe Acrobat application in a server-type process.
The images are about Kb in size and for about 3Gb of documents the thumbnails would take an additional 60MB - so storage requirements are not excessive. The actual time to generate thumbnails for thousands of documents would be a few hours, as Acrobat needs to load each document as well as the rendering to the clipboard, and the.
NET bitmap scaling, etc. NET framework. At first it can be quite daunting trying to find good information on working with PDF documents programmatically, although there are now a number of good commercial components which hide a lot of the underlying postscript complexities. I originally wrote this utility in Visual Basic 6 using a third-party imaging components, but now it is easier to share the code using the. Especially as the complex imaging and manipulation can now be done with a few simple statements.
Geting Image from first page of pdf for showing thumbnail nail with itextsharp
Subscribe to RSS
Generate Thumbnail Images from PDF Documents