Developer Guide
Developer Guide
Introduction
PDFThumbnail.NET is an ASP.NET control for server-side generation of PDF thumbnails that can be viewed on the client as images. PDFThumbnail.NET has no external dependencies. It requires ASP.NET 1.1 or higher. For a live demo, visit: http://www.tallcomponents.com/default.aspx?redir=livedemos-pdfthumbnail. PDFThumbnail.NET is build on the .NET PDF rasterization technology from TallComponents BV. If you need full PDF rasterization capabilities including rasterizing directly to System.Drawing.Graphics, contact us at [email protected] for sales questions and at [email protected] for technical questions.
FAQ
Q A
Is it possible to save generated images for later use? No. PDFRasterizer.NET (not free) does allow you to do this. Note that this is a deliberate restriction. If you need to overcome this, then please take a look at our commercial product PDFRasterizer.NET. The PDFThumbnail.NET control is included as a code sample of PDFRasterizer.NET. Is it possible to control the size of the thumbnails by setting the width and height? No you cannot. But you can control the size by setting the DPI property. The maximum value is 18 DPI. Note that this is a deliberate restriction. If you need to overcome this, then please take a look at our commercial product PDFRasterizer.NET. The PDFThumbnail.NET control is included as a code sample of PDFRasterizer.NET. Is it possible to render PDF documents that are outside the virtual folder? No, you can only render PDF documents that are inside the virtual folder. In other words, you can only render PDF documents that are accessible through Server.MapPath. Note that this is a deliberate restriction. If you need to overcome this, then please take a look at our commercial product PDFRasterizer.NET. The PDFThumbnail.NET control is included as a code sample of PDFRasterizer.NET.
Q A
Q A
Page 1 of 8
Company
TallComponents BV Beekstraat 18a 5931 ES Tegelen The Netherlands (timezone GMT +1) P +31 (0)77 47 48 677 F +31 (0)77 46 29 181 Support: [email protected] Sales: [email protected]
Page 2 of 8
Control reference
PDFThumbnail.NET is deployed as 2 files:TallComponents.PdfThumbnail.dll and pdfthumbnail.aspx. It also includes a folder (CMaps) with character maps used for correct text representation. pdfthumbnail.aspx is included in the PDFThumbnail.NET distribution and is a simple ASP.NET file which you should leave unchanged. pdfthumbnail.aspx should be copied to [virtual root] \ pdfthumbnail.aspx by default. The name and the location of this file can be changed using ThumbnailPage attribute or property (see also below). If for some reason you do not have this file, you can easily reconstruct it as it consists of the following single line: pdfthumbnail.aspx
<%@ Page language="c#" Inherits="TallComponents.Web.PDF.ThumbnailPage" %>
Listing 1 Standard content of pdfthumbnail.aspx. TallComponents.PdfThumbnail.dll implements the ASP.NET control and must be copied to the bin folder of the web application (recommended) or installed in the machine wide GAC. CMaps must be copied to the [virtual root]\ folder. Attributes The ASP.NET control can be included in an aspx page as demonstrated in Listing 2. The attributes correspond to the public properties as listed in the next section. The following attributes are supported: Attributes Runat Path Should always be server. Virtual path to the PDF document. No default. Note that you can only render PDF documents that are inside the virtual folder. In other words, you can only render PDF documents that are accessible through Server.MapPath. This is a deliberate restriction. If you need to overcome this, then please take a look at our commercial product PDFRasterizer.NET. The PDFThumbnail.NET control is included as a code sample of PDFRasterizer.NET 1-based index of the page to display. Default: 1 The resolution of the thumbnail in dots per inch. Default and maximum: 18
Index DPI
BorderWidth Width of the border in pixels. Specify zero for no border. Default: 1 BorderColor Border color. Default: System.Drawing.Color.Gray URL HighQuality DefaultFont If set, the thumbnail behaves as a hyperlink to the specified URL. Default: null If true, the result uses better (but somewhat slower) color conversion. Name of the font file (for example arial.ttf) for non-embedded fonts.
Page 3 of 8
Programmatic API In addition to embedding the control in an ASPX page, you can access the control programmatically. The PDFThumbnail.NET control is a .NET class of type TallComponents.Web.PDF.Thumbnail and inherits from System.Web.UI.Control. TallComponents.Web.PDF.Thumbnail supports the following members: Properties
System.Drawing.Color BorderColor int BorderWidth string DefaultFont int DPI bool HighQuality int Index string Path
Border color. Default: System.Drawing.Color.Gray Width of the border in pixels. Specify zero for no border. Default: 1 Name of the font file (for example arial.ttf) for non-embedded fonts. The resolution of the thumbnail in dots per inch. Default and maximum: 18 If true, the result uses better (but somewhat slower) color conversion. 1-based index of the page to display. Default: 1 Virtual path to the PDF document. No default. Note that you can only render PDF documents that are inside the virtual folder. In other words, you can only render PDF documents that are accessible through Server.MapPath. This is a deliberate restriction. If you need to overcome this, then please take a look at our commercial product PDFRasterizer.NET. The PDFThumbnail.NET control is included as a code sample of PDFRasterizer.NET The key into the Session hashtable that returns the PDF document as a byte[] object. See Sample: Display uploaded PDF document for usage. If set, the thumbnail behaves as a hyperlink to the specified URL. Default: null The URL where the component generating the thumbnails is to be found. Default value is pdfthumbnail.aspx, Methods
string SessionKey
Returns the number of pages inside the PDF document. See Sample: Display uploaded PDF document for usage.
Page 4 of 8
Listing 2 default.aspx: Sample ASPX page that uses the PDFThumbnail.NET control.
Page 5 of 8
Listing 3 default.aspx: Sample ASPX page showing thumbnails of an uploaded PDF document. Line 32: Holds the upload control. The name is set to pdf so the posted file will be available in Request.Files["pdf"]. Line 35: Connects handler that starts on line 05 to the Click event of the Display thumbs button. Line 05: The click handler is declared. Line 09: The posted file is retrieved from session state. Line 15: The posted file is stored in session state as a byte array using a GUID as the key.
Page 6 of 8
Line 17: The static method GetPageCount is used to retrieve the number of pages in the uploaded document. Line 19: A loop starts that adds a thumbnail control to panel thumbnails (declared on line 36) for each page. Line 22: The key that is used to store the document as a byte array is passed to the control using its property SessionKey. Line 23: The page to display is selected (1-based index).
Page 7 of 8
Legal
Information in this document, including URL and other Internet Web site references, is subject to change without notice. Unless otherwise noted, the example companies, organizations, products, domain names, email addresses, logos, people, places and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address, logo, person, place or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of TallComponents BV. TallComponents BV may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from TallComponents BV, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property. Acrobat and PDF are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries. All other trademarks are the property of their respective owners. 2001-2009 TallComponents BV. All rights reserved. PDFThumbnail.NET is a trademark of TallComponents BV.
Page 8 of 8