Use abcpdf in C # To process PDF, so easy

Source: Internet
Author: User
Tags classic asp
Document directory
  • Abcpdf Overview
  • Usage

In the past few days, the project needs to guide the page into PDF. At the beginning, itextsharp was used. I thought it was complicated to process pages. Later, I accidentally saw abcpdf, which is very simple to use, you can record some common operations and share them with everyone. If you don't talk nonsense, paste the Code directly.

Modification, is there a link to the official website with more code? Why ???

Abcpdf Overview

Http://www.websupergoo.com/

The demo uses the latest version abcpdf. Net 9.1x64. It supports the latest Win8, ie10 (server version), server2003, XP, Vista, win7, and Win8 versions.

Abcpdf has a 30-day trial

Reference Method, install abcpdf component, there are two DLL is useful, need to add reference to abcpdf. dll, ABCpdf9-64.dll (engine components) in the bin directory can be

It has other components, such as functions not available in itextsharp. If you can directly specify a URL, you can convert the page to PDF. This is also its strength.

When selecting a version, you must note that the 64-bit and 32-bit versions are differentiated. if the version is wrong, an error will occur. You must note that this issue may occur during IIS deployment, please refer to the official information: http://www.websupergoo.com/support.htm FAQ introduction more detailed

Usage

Let's take a look at the code below.

Add reference:

Using websupergoo. abc00009;

String url = "http://www.websupergoo.com/support.htm"; private void downloadpdf (string filename, byte [] buffer) {response. buffer = false; response. addheader ("connection", "keep-alive"); response. contenttype = "application/octet-stream"; response. addheader ("content-disposition", "attachment; filename =" + filename); response. addheader ("Content-Length", buffer. length. tostring (); response. binarywrite (Buffer);} private string getfilename () {return datetime. now. tostring ("yyyy-mm-dd-hh-mm-SS") + ". PDF ";} /// <summary> /// specify the URL to generate a PDF // </Summary> /// <Param name = "sender"> </param> // <Param name = "E"> </param> protected void button#click (Object sender, eventargs e) {string filename = getfilename (); Doc = new doc (); Doc. page = Doc. addpage (); // create a page Doc. rect. inset (10, 10); // set the rectangle margin int id = Doc. addimageurl (URL, true, 800, false); // return a page ID when adding a URL. // the following code is very important and is related to paging. If you do not write this code, you cannot paging while (true) {// This judgment should be to determine whether the ID is a page object. If not, it will jump out of the loop if (! Doc. chainable (ID) {break;} Doc. page = Doc. addpage (); Id = Doc. addimagetochain (ID); // Add the linked Object ID to the page and return an ID} Doc. flatten (); // compressed PDF Doc. save (server. mappath (filename); // Save the PDF file to the relative path. // You can also output byte [] buffer = Doc. getdata (); // get bytes [] downloadpdf (filename, buffer );} /// <summary> /// custom page /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> protected void butto N2_click (Object sender, eventargs e) {string filename = getfilename (); Doc = new doc (); Doc. page = Doc. addpage (); // create a page Doc. rect. inset (10, 10); // set the rectangle margin. Here, rect is an important object. You can also use Doc. rect. string to set the attribute Doc. fontsize = 24; // set the default font size Doc. color. string = "89,89, 254"; int id = Doc. addtext ("Hello world !!! "); // Add text Doc. framerect (); // Add the Border Operation Doc. save (server. mappath (filename); byte [] buffer = Doc. getdata (); downloadpdf (filename, buffer );} /// <summary> /// HTML elements are supported /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> protected void button3_click (Object sender, eventargs e) {string filename = getfilename (); Doc = new doc (); Doc. page = Doc. addpage (); Doc. rect. inset (10, 10); Doc. addhtml ("<H2> How to Use the abcpdf </H2>"); Doc. addhtml ("<HR>"); Doc. addhtml (@ "<p> Use abcpdf to create Adobe PDF documents on the fly. you won't believe how simple-yet how powerful it truly is. find out more... if you 've been using version 8 you'll love version 9. it uses des compute powerful new features designed to make your life easier. find out more... or check out our feature chart... abcpdf. net is. net native product encapsulated in an easy-to-deploy set of DLLs. it also offers a virtualized COM interface designed for backwards compatibility with abcpdf ASP and classic ASP/COM. abcpdf is normally priced from $329. however as a special offer we'll give you a free license key-all you have to do is link back to our web site. for full details check out our link guidelines... </P> "); // here is not amazing. html supports and is flexible. I like a doc. save (server. mappath (filename); byte [] buffer = Doc. getdata (); downloadpdf (filename, buffer );} /// <summary> /// customize the header and footer /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> protected void button4_click (Object sender, eventargs e) {string filename = getfilename (); Doc = new doc (); Doc. page = Doc. addpage (); Doc. rect. inset (20, 40); Doc. addhtml ("<H2> How to Use the abcpdf </H2>"); Doc. addhtml ("<HR>"); // customize the header Doc. rect. string = "24 750 588 778"; // remember to locate here doc. hpos = 0; // center, 0 indicates center left, 1 indicates center right doc. VPOs = 0.5; // center, 0 stands for top, and 1 stands for bottom Doc. color. string = "blue"; // blue for (INT I = 1; I <= Doc. pagecount; I ++) {Doc. pagenumber = I; Doc. addhtml ("<B> <font>" + "laozhao learn abcpdf, save time for" + datetime. now. tostring () + "</font> </B>"); Doc. addline (24,750,588,750); // draw a separator line} // footer Doc. rect. string = "24 12 588 40"; Doc. hpos = 1.0; // right doc. VPOs = 0.5; // middle Doc. color. string = "black"; for (INT I = 1; I <= Doc. pagecount; I ++) {Doc. pagenumber = I; Doc. addhtml ("<u> page: </u>" + I. tostring () + "/" + Doc. pagecount. tostring (); Doc. addline (24, 40,588, 40);} Doc. save (server. mappath (filename); byte [] buffer = Doc. getdata (); downloadpdf (filename, buffer );}

The above are some of the features I have used, and some of them are also very useful.

DOC also supports addimagehtml

Parameter description:

HTML: HTML to be added

Paged: whether to pagination; true: Enable pagination

Width: The page width (the width of the browser when the browser parses HTML)

Disablecache: whether to ignore the cache; true: Disable caching; false: enable caching

One thing to mention is the technical support. The official website is doing well. A support page covers many common problems and solutions, which is fairly detailed. I wish you a pleasant use.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.