Use ASP. NET (C #) to generate PDF files-iTextSharp library (on)

Source: Internet
Author: User
Tags visual studio 2010

ASP is required for work content. net c # generate a PDF file, but. NET framework does not have the built-in PDF function, so you can only find the function provided by Third-Party online. Please help me. The search results have been shown in the upper-right corner. In the search results, there are a lot of PDF functions to be paid, so we will exclude them first, and we will search for them as small as free and support Chinese, finally, let me find a very practical and easy-to-use library-iTextSharp.

This function is originally called iText and mainly supports Java program statement. Later, we made a version for Microsoft. net c Sharp, which is the iTextSharp we want to introduce today. The following functions are supported:

1. Create: Automate, Convert, Sign, Encrypt.
2. Read: Extract.
3. Update: Stamp, Fill out, Split/Merge, Convert, Sign, and Encrypt.
Next, let me show you how to use a program to generate a PDF file.

Development Environment
1. My ASP. NET development environment is Microsoft Visual Studio 2010, and the program statement used is C #.
2. The current iTextSharp version is 5.0.4, the lower limit location: http://sourceforge.net/projects/itextsharp. Please download the zip file first, and there is only one dll after resolving the issue. Use the Add Reference method to change itextsharp. dll is added to the Bin object of your micro-segmentation case. This is so simple and coding can be started.

Part 1: first create a Web Application

 

In this example, after using the web application to generate a pdf file in the Server Memory product, the user can manually download the file or store the file. The usage of the example writer is different:


To generate a pdf file in the Server FileSystem, you can use the following program:


To display Chinese characters in the PDF file content, the most important thing is the font setting. If there is no correct setting of the Chinese character type, it will cause the problem that Chinese characters cannot be displayed. First, set the basic font: kaiu. ttf is The title Font provided by The operating system. IDENTITY_H refers to encoding (The Unicode encoding with horizontal writing) and whether to embed The font into The PDF. Then, the basic fonts will be changed, such as Font Size, coarse body oblique, and hidden colors. You can also use other Chinese fonts.

 

After opening the case, the case will be closed.

 

In this example, you have already created an example (please refer to example.pdf ). The following figure shows the itinerary result:

 

Select to open the primary keys, which are shown as follows:

 

Part 2: Use chunk, phrase, and paragraph to create a text section content

Paragraph is a Paragraph in an article. It can be composed of phrases (sentences), and phrase can be further formed by chunks (Text fragments. In this way, you can easily insert different types of fonts into text paragraphs. Note that the chunk does not automatically upload rows. You must insert the line character "\ n" or Environment. NewLine. As for Paragraph, there are many types of settings, such as Alignment, indentation, leading, and spacing.


 


 

The results are as follows:

 

 

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.