Create and manipulate PDF documents - 100% .NET
来源:互联网 发布:音乐广告制作软件 编辑:程序博客网 时间:2024/05/20 05:06
This is a showcase review for our sponsors at CodeProject. These reviews are intended to provide you with information on products and services that we consider useful and of value to developers.
Introduction
TallPDF.NET and PDFKit.NET are 100% .NET components written entirely in C# for creating, manipulating and reading PDF documents and PDF forms.The focus is to ease the task of integrating our component in a larger application. Th is is done by providing a highly intuitive object model and supporting main stream technologies such XML/XSL and ADO.NET.
Download evaluations: TallPDF.NET 2.0; PDFKit.NET 1.0 (fully functional, does not expire)
View demos online: Create invoice on the fly; Create business card on the fly
TallPDF.NET 2.0
TallPDF.NET is a 100% managed .NET component for dynamically creating documents from scratch. This component is typically deployed as part of an ASP.NET application that generates dynamic PDF from a data source or user input. However, it is just as well possible to integrate TallPDF.NET in a desktop application. Central to TallPDF.NET is a highly intuitive object model consisting of classes like Document, Section, Paragraph, Table, Footer, etc.
You can create documents either programmatically or from XML. When generating PDF from XML, classes are represented by elements and properties by attributes or child elements. You typically write an XSL file to transate your own specific XML documents to the TallPDF.NET XML format. Using the non-cached forward-only characteristics of the XmlReader class, you can pipeline these steps and achieve extremely low memory consumption, completely independent of document size. This makes TallPDF.NET an excellent solution for generating both small and very large documents.
Features
PDF Features | bookmarks; document properties; internal cross-references; external cross-references |
Text Formatting | text color; single and double strike-through; single and double underline; sub- and superscript; left, right and center alignment; justification; hyperlinking |
Page Layout | vertical alignment; relative positioning (flow layout); absolute positioning (grid layout); mix grid and flow layout; keep-with-next constraints; do-not-break constraints |
Tables | colspan; vertical and horizontal cell alignment; nest tables; fit-to-content; borders; backgrounds; repeat one or more header rows |
Generation | declarative or event-driven; flash-out pages while generating; from XML using the forward-only XmlReader class; from ADO.NET using a forward-only database cursor |
Images | BMP, GIF, JPEG, TIFF, PNG, DCT (JPG) and Flate compressiom; multipage TIFF; from file, memory or System.Drawing.Bitmap |
Document Layout | divide a document into sections; assign headers and footer to each section; standard page size; distinguish between first, middle, last, odd and even headers/footers |
Fonts | 14 standard PDF fonts; TrueType subset embedding; Unicode; support for Japanese, Cyrillic, Hebrew, Arabic, etc. |
Encryption | weak and strong passwords; restrict privileges such as allow print/copy |
Drawing | lines, rectangles, ellipses, pies, arcs, images, text, brushes and pens,draw inside relatively positioned boxes,draw on entire page as a canvas |
Generate PDF programmatically
The following code sample shows the basics of generating PDF programmatically from an ASP.NET page.
<%@Page Language="C#"%><%@Import Namespace="TallComponents.PDF.Layout"%><%// create a new instance of the TallPDF.NET documentDocument doc = new Document();// add a section to the documentSection section = new Section();doc.Sections.Add( section );// add a text paragraph to the sectionTextParagraph textParagraph = new TextParagraph();section.Paragraphs.Add( textParagraph );// add a piece of text to the text paragraphFragment fragment = new Fragment();textParagraph.Fragments.Add( fragment );fragment.Text = "Hello world!";// stream out the PDF directly to the browserdoc.Write( Response );%>
Generate PDF from XML
The central idea of TallPDF.NET is that you can build an instance of the TallPDF DOM and that you can save that instance to PDF. Instead of building a DOM instance programmatically, you can also load it from XML. There is no difference between a DOM instance loaded from XML and one that has been constructed programmatically.
The following code sample show a typical XML file and how it is converted to PDF.
<document author="Jim"> <section pagesize="Letter"> <!-- content goes here... --> </section></document>
// create an XmlDocument and load itXmlDocument xml = new XmlDocument();xml.Load( "topdf.xml" );// create a PDF document and initialize it from XMLDocument document = new Document(); document.Read( xml.DocumentElement );// stream out the PDF to fileFileStream file = new FileStream( "out.pdf", FileMode.Create );document.Write( file );
Use XSL to transform any XML document to PDF
The following code sample shows how the use an XSL to transform an existing XML to PDF:
// load the XMLXmlDocument xml = new XmlDocument();xml.Load( "data.xml" );// load the XSLXslTransform xsl = new XslTransform();xsl.Load( "transform.xsl" );// transform the XML using the XSLXmlReader reader = xsl.Transform( xml, null );// create a new PDF document and initialize if from the transformed XMLDocument document = new Document();document.Read( reader );// stream out the PDF to fileFileStream file = new FileStream( "out.pdf", FileMode.Create );document.Write( file );
PDFKit.NET 1.0
PDFKit.NET allows you to split, append, stamp, encrypt PDF documents and fill PDF forms. PDFKit.NET is a 100% managed .NET component for manipulating PDF documents and forms on the fly. This component is typically deployed as part of an ASP.NET application, however, it is just as well possible to integrate PDFKit.NET in a desktop application. Central to PDF.NET is a highly intuitive object model consisting of classes like Pages, Page, Overlay, Underlay, Shapes and Fields.
Features
Split and Append | create a new document; get single or multiple pages from an existing PDF document; combine existing and new page to cretae a new document |
Form filling | (multiline) text fields, check boxes, radio button, list boxes and combo boxes, read position and size of fields, flatten, remove or preserve fields |
Security / Encryption | 40 and 128 bit encryption; consume encrypted documents; set user and owner password; set user privileges such as allow print/copy |
Stamping | multiline text (alignment, justification, multiple fonts, etc); hyperlinks; primitive shapes such as Line, Pie, Rectangle, Image; position, rotate and scale shapes |
General | write to disk, memory or directly to an HTTP response; read from disk or memory;constant, low memory consumption, independent of document size |
Filling PDF forms
All form fields of a PDF form can be accessed through the object model of PDFKit.NET. You can enumerate the fields either at document or at page level. You can also index fields either by position or by name.
A field is represented by the Field class. You can query the field for its type (text box, radio button, etc), its position and size and various attributes such as 'multiline' and 'read-only'. If a field represents a selection control such as a combo box or radio button group, you can also enumerate the options. Finally you can fill a form field by setting its Value property and flatten it by setting the Flatten property.
// open an existing PDF formFileStream file = new FileStream( "form.pdf", FileMode.Open, FileAccess.Read );Document document = new Document( new BinaryReader( file ) );// retrieve fieldPage page = document.Pages[0];Field field = page.Fields["LastName"]; /// fill out field and flatten itfield.Value = "John Smith";field.Flatten = true;// stream the filled PDF form directly to the browserResponse.ContentType = "application/pdf";document.Write( new BinaryWriter( Response.OutputStream ) );
Stamping PDF documents
PDFKit.NET allows you to open an existing PDF document and retrieve each page by index. A page is represented by a Page class. This class exposes 2 layers: an overlay and an underlay. You can draw on each of these layers by adding shapes to it. PDFKit.NET provides a large set of primitive shapes such as Line, Pie, Rectangle, Text, Image (BMP, JPEG, etc.). Each shape can be located anywhere on the page, rotated by any angle and scaled.
// open an existing PDF documentFileStream file = new FileStream( "in.pdf", FileMode.Open, FileAccess.Read );Document document = new Document( new BinaryReader( file ) );// stamp blue verdana text over existing contentTextShape text = new TextShape( 10, 300, "John Smith", Font.TrueType( "verdana.ttf" ), 10, Color.Blue ); page.Overlay.Add( text );// stream the filled PDF form directly to the browserResponse.ContentType = "application/pdf";document.Write( new BinaryWriter( Response.OutputStream ) );
Splitting and combining PDF documents/pages
After you have opened a PDF document you can select pages from it and use them to build a new document. You can append pages that originate from different documents.
// open existing documentsFileStream file1 = new FileStream( "x.pdf", FileMode.Open, FileAccess.Read );Document source1 = new Document( new BinaryReader( file1 ) );FileStream file2 = new FileStream( "y.pdf", FileMode.Open, FileAccess.Read );Document source2 = new Document( new BinaryReader( file2 ) );// create a new, empty documentDocument target = new Document();// append pages from the existing documentstarget.Pages.Append( source1.Pages[4] );target.Pages.Append( source2.Pages[30] );target.Pages.Append( source1.Pages[45] );target.Pages.Append( source2.Pages[230] );// stream the new PDF document directly to the browserResponse.ContentType = "application/pdf";target.Write( new BinaryWriter( Response.OutputStream ) );
About Frank Rem
Graduated in 1997. Worked for some years as a software engineer, architect and project leader for different software companies. Founded TallComponents in 2001. Click here to view Frank Rem's online profile. |
- Create and manipulate PDF documents - 100% .NET
- PDFSharp-a .NET library for creating and modifying Adobe PDF documents
- iOS create PDF and show PDF
- Saving Word 2007 Documents to PDF and XPS Formats
- Generate PDF documents from a HTML page using ASP.NET
- VizualPV3D (VizualPV3D is a Flash Visualization Application that provides a GUI interface to create and manipulate objects in 3
- Create and format Word documents using R software and Reporters package
- Reading & Displaying PDF Documents
- 《css and documents》读书笔记;
- Classifying Texts and Documents
- Documents and manuals
- Linux PDF editor for manipulating PDF documents
- Automating the Creation of Data-Rich Business Documents with Word 2007 and ASP.NET
- Take (and Manipulate!) a Photo with a Web Page
- Printing with Documents and Views
- 转移Documents and Settings妙法
- Documents and Settings拒绝访问
- Accept documents and offer public documents in ODF
- 出差在外地
- Micromedia 发布DevNet最终资源开发包
- Today I begin new life
- 在blog中显示天气预报、日历、时钟、MSN、QQ在线状态
- 简单邮件传输协议(SMTP)--网络大典
- Create and manipulate PDF documents - 100% .NET
- 基于CSD的WAP组网方案
- 上海11月招聘会排期
- Today I will pluck grapes of wisdom from ..........
- 局域网内传文件或文件内容
- 剩下来的两个月的时间就弄DirectX吧!
- IOC模式简介
- 利用CDialogBar来实现类似工具栏的浮动条
- Cookies,SSL,httpclient的多线程处理,HTTP方法