Using ASP. NET (C #) to generate a PDF example-itextsharp Library (below)

Source: Internet
Author: User

Http://www.cc.ntu.edu.tw/chinese/epaper/0016/20110320_1610.html

Author: Tang Xiaoyun/zookeeper University Computer and Information Network Center Programming organization programming Organization

In the Computing Project of the previous issue, we introduced itextsharp, a very large and free PDF function, I believe you should be familiar with it. Next, we will introduce the dynamic functions, including direct content, header, footer, barcode, JavaScript, and other interactive functions.
 

Part 1: Direct content
Direct content refers to the insert content in the response position of the response. In the example, two classes of contentbyte and columntext are used. First, add an upper layer character to the plane, and then click "upper layer" in the picture, fill a rectangle in the Lower Layer of the picture and fill in the fill color. The main methods used are pluwriter. directcontent and pluwriter. directcontentunder:

The results are as follows:

Next, we will set the following lines for any position on the platform:

If columntext text is used to show the text content to the corresponding area, please refer to the following program:

The results are as follows:

Part 2: header and footer
If we want to add a header or footer to each partition, in addition to the direct content mentioned in Part 1, the most important thing is to handle the page event, that is, the pdfpageeventhelper interface.
You can override events as follows: onchapter, onchapterend, onclosedocument, onendpage, ongenerictag, onopendocument, onparagraph, onparagraphend, onsection, onsectionend, and onstartpage. We can meet program requirements and pick out the events we need to use to modify the program.
In our example, we hope that we can display the data at the end of the last batch and establish the case. Therefore, we should first create a page event class and change the onopendocument method. The aggregate template is used to store the total number at the end of each batch:

Then the override onendpage method is used. We will display the "ntu c & Inc" text in the header at the upper right corner of each queue; in the lower-left corner, footer displays the total number and the footer in the lower-right corner shows the date and time of file production. Use showtextaligned, showtextmatrix, showtext, and other methods to set the correct position of the text display, and retain the position of the template to display the total number:

The last override onclosedocument method, because the location of the template has been retained, you only need to fill in the content.

 

Part 3: barcode Condition
Itextsharp provides direct sensing to produce various conditions, including barcode and QR code. You can also use the page event Method of the previous example to create a file condition at the end of each batch, and use the placebarcode method. Program tracing is easy to understand. You can directly compile the program as follows:

The results are as follows:

 

Part 4: use JavaScript to interact with users

The complete program is as follows:

The javascript program is very simple:

The results are as follows:

The <print this notebook> text appears in the upper-right corner. When the mouse moves up, it indicates the cursor that can be clicked and clicked. After you press the mouse on the left side, it will pop out of the alert preview window:

Then press confirm to print the target speaker:

This function can be used to hide the menu bar and tool bar. You can directly print the animation on the plane.

Conclusion:
Before using a program to generate a PDF example, we only have a rough understanding of the PDF file. In general, it should be in a certain case format. After the answer is received, I found that the website was actually used. In particular, there were such large letter types that could be used. It was just a huge addition to programming developers. Are there other functions available yet? The answer is yes, and there are a lot more. I will try again to introduce it to you. If you have any requirements, you can start looking for them from the transcript. Maybe you will get more.
 

Additional information

  1. Main tutorial website
    Http://itextpdf.com/index.phphttp://www.mikesdotnetting.com/Article/80/Create-PDFs-in-ASP.NET-getting-started-with-iTextSharp

  2. Watermark watermark for http://footheory.com/blogs/donnfelker/archive/2008/05/11/using-itextsharp-to-watermark-write-text-to-existing-pdf-s.aspx

  3. Using bookmark
    Http://www.mazsoft.com/blog/post/2008/04/30/Code-sample-for-using-iTextSharp-PDF-library.aspx

  4. Footer notebook
    Http://stackoverflow.com/questions/1032614/itextsharp-creating-a-footer-page-of

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.