It is my Computer Notes. Using Guide : object-key or object-key-key e.g. Step 1 Blog Search : [mysql-run] and then Step 2 ctrl+F [mysql-run] {bookMark me : Ctrl+D}
2013年10月30日 星期三
itext-function-control java-pdf java-print
import com.itextpdf.text.Anchor;
import com.itextpdf.text.BadElementException;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chapter;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.List;
import com.itextpdf.text.ListItem;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Section;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.PageSize;
public class MainClass {
public static void main(String[] args) throws Exception {
Document document = new Document();
Document document = new Document( PageSize.A4, 20, 20, 20, 20 );
PdfWriter.getInstance( document, new FileOutputStream( "HelloWorld.pdf" ) );
PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
document.open();
Chunk c = new Chunk("this is a test");
float w = c.getWidthPoint();
Paragraph p = new Paragraph("The width of the chunk: '");
p.add(c);
p.add("' is ");
p.add(String.valueOf(w));
p.add(" points or ");
p.add(String.valueOf(w / 72f));
p.add(" inches or ");
p.add(String.valueOf(w / 72f * 2.54f));
p.add(" cm.");
document.add(p);
document.add(Chunk.NEWLINE); // New Line new space line
document.add(c);
document.add(table);
table = new PdfPTable(3); ////////////////////////////// columns of Report
table.setWidths(new int[]{30,850,260}); ////////////////////// column widths
table.setWidthPercentage(100); //////////////////////////////////// tables width 100%
table.getDefaultCell().setBorder(0); ////////////////////////////// border-width to 0
c1 = new PdfPCell(new Phrase("3", font8));
c1.setBorder(0);
c1.setHorizontalAlignment(Element.ALIGN_LEFT);
table.addCell(c1); //1
c1 = new PdfPCell(new Phrase("(a) H.K.Identity Card Number : ", font8));
c1.setBorder(0);
c1.setHorizontalAlignment(Element.ALIGN_LEFT);
table.addCell(c1); //2
c1 = new PdfPCell(new Phrase(dRaws[i][1], font8));
c1.setBorder(0);
c1.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.addCell(c1);
document.close();
}
}
xxxxxxxxxxxxxxx
public static void main(String args[]) {
try {
// create a new document
Document document = new Document( PageSize.A4, 20, 20, 20, 20 );
PdfWriter.getInstance( document, new FileOutputStream( "HelloWorld.pdf" ) );
document.open();
document.add( new Paragraph( "Hello, World!" ) );
document.add( new Paragraph( "Hello, World!" ) );
// add a couple of blank lines
document.add( Chunk.NEWLINE );
document.add( Chunk.NEWLINE );
// add one more line with text
document.add( new Paragraph( "Hello, World!" ) );
document.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言