C # Guide PDF learning

Source: Internet
Author: User

The main use is the Itextsharp method,

Reference Documentation:

(1) http://www.docin.com/p-23672859.html

(2) http://www.cnblogs.com/islands/archive/2008/06/27/1231288.html

(3) http://www.cnblogs.com/julyluo/p/3839788.html

1,itextsharp
2,service Stack
3,testdriven
4,fastreport

Itextsharp Development Steps

The meaning that class represents
Paragraph text in a report
Picture in Image Report
Pdfptable form
Pdfpcell cell
Knowing these 4 classes is the next step in development:

1. Add content to the cell Pdfpcell class.

2. Add cell Pdfpcell to pdfptable.

3. Add the table Pdfptable to document.
In the above steps the most important is the first step is to add content to Pdfpcell, and the content in Pdfpcell can be divided into the following three situations:
Text paragraph
Picture image
Form Pdfptable

First, the text is expressed by paragraph, before adding to note the font problem, because we use a Chinese font, if the default English font rendering will be garbled,
So we have to define the Chinese font first:
Basefont bf_light = Basefont.createfont (@ "c:\windows\fonts\simsun.ttc,0", Basefont.identity_h, BaseFont.EMBEDDED);


Second, the drawing uses is the Pdfcontentbyte class
Draw Line
Canvas. SaveState ();
Canvas. Setlinewidth (2f);
Canvas. MoveTo (100, 100);
Canvas. LineTo (200, 200);
Canvas. Stroke ();
Canvas. Restorestate ();

Text
columntext.showtextaligned (Canvas, Element.align_right, New Phrase ("Julyluo test", New Font (Bf_light, 10)), 100, 20, 0);


public void Celllayout (Pdfpcell cell, Rectangle position, pdfcontentbyte[] canvases)
The Ipdfpcellevent interface means the method that is exposed after the cell is added to the document. Obviously, with the postion parameter we can get the coordinates, the canvases parameter can get the artboard.
So to paint, create a class that implements the interface ipdfpcellevent, and then draw lines and text in the Celllayout method:

Paint classes, and cell associations
Resolutionchart chart = new Resolutionchart (FileName, YMax, Yscale);
Cell. Cellevent = chart;

With Itextsharp development, if the report only text, the picture is Pdfpcell a class can be done. But if you want to draw some bar Chart,bar chart, these diagrams are needed
Coordinates, we can get the coordinates through the Ipdfpcellevent interface and draw the corresponding graph

Third, pdfptable

Pdfptable table
Table. widthpercentage=100;
Table. HorizontalAlignment = Element.align_right;
Table. Spacingbefore = 100f;
Table. Spacingafter = 100f;
Table. TotalWidth = 100;
Table. Lockedwidth = true;

Table. Defaultcell.bordercolor = new Basecolor (255,0,0);//change default column style
Pdfptable does not provide the ability to merge columns, the Addcell (pdfptable table) must be implemented in the form of a nested table

Iv. Pdfpcell

Pdfpcell through CELL1. Colspan = 2; setting cross-columns
Height of Cell:
Cell1. NoWrap = true;//prohibits text wrapping, which is wrapped by default
Cell1. Fixedheight = 100;//Sets the height of the row to a fixed value (more than the content part is missing)
Cell1. minimumheight= 100;//min. height
The alignment of the cell:
HorizontalAlignment horizontal alignment, VerticalAlignment vertical alignment
padding, line spacing of cells
Filler: padding,paddingbottom,paddingleft,paddingright,paddingtop
Line spacing: setleading (float fixedleading, float multipliedleading)
Fixedleading represents the value of the line spacing,
Multipliedleading represents a multiple of the font size
Useborderpadding: Force the width of the border to be counted
Useascender: Increment
Usedescender: Degradation

Cross-page table splitting
Headerrows, number of rows in the header row
Splitrows, whether to split the branch, (default is the line priority, only when a whole page can not display a row, will be split branch)
Page First: Splitlate=false

Add table in absolute position
public float writeselectedrows (int rowstart, int rowend, float xPos,
float YPos, pdfcontentbyte canvas);

Memory Management for large tables
The solution is to break up the big table into tables, connect the tables to the end, and the output will be no different than a single table.

C # Guide PDF learning

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.