{oapdf_gg}
Office software is closely linked to the PDF,the PDF is also must have to control!      Set home Page  Add to Favorites  
You are here:Home > PDF Application > PDF Development
PDF Development
Using C# language the whole PDF document Strategy Guide Graphic
Finishing by: Date:2009-04-17 20:59:48 Popularity: Tags:

template (Form xObjects )

when we discussed in Chapter IV headers and footers, we add the definition of a small piece of information to each page, in fact, the small pieces of information each wrote a paper on a new page. This is not the most economical solution, the better approach is to information as a Form Xobject added in the document only once, can be seen in its repeated position. I reached the end, we will use the template.

u create a PdfTemplate

u the best way to create PdfTemplate is PdfContentByte call createTemplate method object:

PdfContentByte-object:

PdfTemplate template = cb.createTemplate (500, 200);

In this way, the template with a width of 500 and a high of 200.

through the template PdfContentByte we can do the same thing as

template.moveTo (0, 200);

template.lineTo (500, 0);

template.stroke ();

template.beginText ();

BaseFont bf = BaseFont.createFont (BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

template.setFontAndSize (bf, 12);

template.setTextMatrix (100, 100);

template.showText ( "Text at the position 100100 (relative to the template !)");

template.endText ();

u add a template to a document

through like the following to add the same absolute position in a template:

cb.addTemplate (template, 0, 400);

you can do some interesting things, such as scaling or rotating them:

//rotate 90 degrees to the template

cb.addTemplate (template, 0, 1, -1, 0, 500, 200);

//zoom template for 50%

cb.addTemplate (template, .5 f, 0, 0, .5 f, 100, 400);

//zoom templates for 200%

cb.addTemplate (template, 2, 0, 0, 2, -200, 400);

specific demonstration

see sample code 1003.

u the first few pages of a total of a few pages

In some cases, you want to insert a number when you write shell on this page do not know the information to the text, such as:in the first page of a document, you do not know that there are a few pages of the document. Can only be completed when the entire document to know the total number of pages. When using a template, the problem would not exist. Sample code in 0103, we add a template to add ContentByte some information to the template, this is not necessary. We may at any time add information to the template, because iText Add Form Xobject the end of the PDF of the local (through the close method when the document to close the call). 1004 sample code shows the creation of the first four and then add the total to the number of pages, which were very simple and useful.

column

in this chapter, you have mastered how to text on an absolute position, in which case, we have to determine the coordinates of the beginning of the text. If we want to know the location of the end of the text, we have to do some calculation.

now we have to add some text to a rectangular box inside, hoping to reach the right sector, the text automatically wrap. Will not exceed the rectangular part, it can be adopted to achieve ColumnText category.

For example:

to show a specified phrase in the coordinates (100, 300) and (200, 500) in the middle between the rectangle, we use the following code:

PdfContentByte cb = writer.DirectContent;

ColumnText ct = new ColumnText (cb);

ct.setSimpleColumn (phrase, 60, 300, 100, 500, 15, Element.ALIGN_CENTER);

ct.go ();

by looking at sample code 1005, you will immediately find ways to be through the paintings form a number of complex objects without having to Table.

Another example:

there is no need to add a one-time text all into, you can define a rectangle, and then add some text, and finally go method with column display.

PdfContentByte cb = writer.DirectContent;

ColumnText ct = new ColumnText (cb);

ct.setSim7pleColumn (60, 300, 100, 500, 15, Element.ALIGN_CENTER);

ct.addText (phrase1);

ct.addText (phrase2);

ct.addText (phrase3);

ct.go ();

see sample code 1006.

multi-column

Of course, if the scope of the text beyond the rectangle, we do not want to lose more than the text, perhaps we would like to show to the other column of text. That is why we go to see the reasons for method return values. If the logo for the return of "NO_MORE_COLUMN", said the column did not have enough space for storage of the text, if all of the text are displayed, logo will be "NO_MORE_TEXT".

please see the sample code 1007.

irregular column

the definition of a non-rectangular area to display the column is also possible, through the use of setColumns method, we have a text about the definition of the border.

float [] left = (70,790, 70,60);

float [] right = (300790, 300700, 240700, 240590, 300590, 300106, 270,60);

ct.setColumns (left, right);

left border is a straight line, while the right side of the border is irregular. The results of this function can lead to some very interesting layout, sample code, see 1008, in this case you will need a caesar_coin.jpg of the picture:

 

PdfTable

in Chapter 5, we briefly described the object PdfPTable, and now we will be more discussion of the characteristics of the object.

You can use three kinds of different ways to create PdfTable:

PdfPTable (float [] relativeWidths);

PdfPTable (int numColumns);

PdfPTable (PdfPTable table);

to the table you can set more parameters, such as table width, column width, such as the level of alignment, you can add the following cell approach:

public void addCell (PdfPCell cell);

public void addCell (PdfPTable table);

public void addCell (Phrase phrase);

public void addCell (String text);

In addition to filling the cell and the distance and spacing, these methods are very similar with the Table object. These parameters for each individual cell have been set up, of course, you can set the default value of the cell, the cell to change the default value, use getDefaultCell () and call one or more categories PdfPCell method (you can set up alignment, spacing, borders, colors, and even the minimum height).

Note:PdfPTable, you can change out a span of cells, but can not change the line-span! In some PdfPTable independent internal lines, it is necessary to allow it to support the changes needed to span objects PdfPTable a lot of adjustments, do not expect to achieve in the near future, you can use nested tables to solve these problems.

as you can, as Chapter 5 will be added to a PdfPTable current document, but you can also add a table in the current absolute position page:

public float writeSelectedRows (int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte canvas);

parameters rowStart is the beginning of the line you want the number of parameters is rowEnd you want to show the last line (if you want to show all the lines, and -1), xPos and yPos is the coordinates of the form, canvas is a PdfContentByte object. Sample code in 1009, we added a table in the (100600) Department:

table.writeSelectedRows (0, -1, 100, 600, writer.DirectContent);

use PdfPTable, you can not set the line span and (or) to span (and how the above a bit contradictory?) you can use to solve the nested table, see sample code 1010.

Finally, sample code, sample code 1011 and 1012 demonstrated the templates and PdfTable and columns can be used together in the sample code will be used for 1012 are as follows cover.png picture:

 

color (SpotColors ) and patterns (Patterns)

color (spotcolors) the use of 1013, see sample code, sample code, sample code 1014 and 1015 demonstrated a pattern (patterns) to use.

there isArticle InformationsComment Information
Category column

Site Help | Site Map | Feedback |
OAPDF.COM Copyright 2009 V1.1