本文整理匯總了Java中com.lowagie.text.Document.add方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.add方法的具體用法?Java Document.add怎麽用?Java Document.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.lowagie.text.Document
的用法示例。
在下文中一共展示了Document.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createContent
import com.lowagie.text.Document; //導入方法依賴的package包/類
public void createContent(WebInput wi, DocInfo di)throws ControllerException {
Document pdfDoc = di.getPdfDocument();
try {
pdfDoc.add(new Paragraph("Hello World!"));
try {
BaseFont bf = BaseFont.createFont("STSong-Light",
"UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
Font FontChinese = new Font(bf, 12, Font.NORMAL);
String info=wi.getParameter("info");
Paragraph p0 = new Paragraph(info, FontChinese);
pdfDoc.add(p0);
Paragraph p1 = new Paragraph("Beetle Web Framework 頁麵生成PDF文件演示!", FontChinese);
pdfDoc.add(p1);
} catch (Exception ex1) {
throw new ControllerException(ex1);
}
} catch (DocumentException ex) {
throw new ControllerException(ex);
}
}
示例2: close
import com.lowagie.text.Document; //導入方法依賴的package包/類
@Override
public void close() throws IOException {
try {
float width = 0;
float[] w = new float[iMaxWidth.length - iHiddenColumns.size()]; int wi = 0;
for (int i = 0; i < iMaxWidth.length; i++)
if (!iHiddenColumns.contains(i)) { width += 15f + iMaxWidth[i]; w[wi++] = iMaxWidth[i]; }
Document document = new Document(new Rectangle(60f + width, 60f + width * 0.75f), 30f, 30f, 30f, 30f);
PdfWriter writer = PdfWriter.getInstance(document, iOutput);
writer.setPageEvent(new PdfEventHandler());
document.open();
iTable.setWidths(w);
document.add(iTable);
document.close();
} catch (DocumentException e) {
throw new IOException(e.getMessage(), e);
}
}
示例3: convertWriteToPdf
import com.lowagie.text.Document; //導入方法依賴的package包/類
public static void convertWriteToPdf(BufferedImage bufeBufferedImage, String path) {
try {
//Image img = Image.getInstance("C:\\Users\\SOFTWARE1\\Desktop\\boshtwain4JImages\\testcapture1507134499431.jpg");
Image img = Image.getInstance(bufeBufferedImage, null);
Document document = new Document(img);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(path));
//--
document.open();
img.setAbsolutePosition(0, 0);
//--
document.add(img);
//--
document.close();
} catch (DocumentException | IOException e) {
System.out.println("Intern Log : " + e.getMessage());
}
}
示例4: buildPdfDocument
import com.lowagie.text.Document; //導入方法依賴的package包/類
@Override
protected void buildPdfDocument(Map<String, Object> model, Document document, PdfWriter writer,
HttpServletRequest request, HttpServletResponse response) throws Exception {
List<Book> books = (List<Book>) model.get("book");
PdfPTable table = new PdfPTable(3);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
table.getDefaultCell().setBackgroundColor(Color.lightGray);
table.addCell("Book Name");
table.addCell("Author Name");
table.addCell("Price");
for (Book book : books) {
table.addCell(book.getBookName());
table.addCell(book.getAuthor());
table.addCell("" + book.getPrice());
}
document.add(table);
}
示例5: downloadPdfFile
import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
* Generates a PDF file with the given text
* http://itext.ugent.be/itext-in-action/
* @return A PDF file as a byte array
*/
public FileTransfer downloadPdfFile(String contents) throws Exception
{
if (contents == null || contents.length() == 0)
{
contents = "[BLANK]";
}
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
Document document = new Document();
PdfWriter.getInstance(document, buffer);
document.addCreator("DWR.war using iText");
document.open();
document.add(new Paragraph(contents));
document.close();
return new FileTransfer("example.pdf", "application/pdf", buffer.toByteArray());
}
示例6: main
import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
* Using FontSelector.
*/
@Test
public void main() throws Exception {
// step 1
Document document = new Document();
// step 2
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("fontselection.pdf"));
// step 3
document.open();
// step 4
String text = "This text is the first verse of \u275dThe Iliad\u275e. It's not polytonic as it should be "
+ "with \u2798 and \u279a entoation variants but that's all we have for now.\n\n"
+ "\u2766\u00a0\u00a0\u039c\u03b7\u03bd\u03b9\u03bd \u03b1\u03b5\u03b9\u03b4\u03b5, \u03b8\u03b5\u03b1, \u03a0\u03b7\u03bb\u03b7\u03b9\u03b1\u03b4\u03b5\u03c9 \u0391\u03c7\u03b9\u03bb\u03b7\u03bf\u03c2";
FontSelector sel = new FontSelector();
sel.addFont(new Font(Font.TIMES_ROMAN, 12));
sel.addFont(new Font(Font.ZAPFDINGBATS, 12));
sel.addFont(new Font(Font.SYMBOL, 12));
Phrase ph = sel.process(text);
document.add(new Paragraph(ph));
// step 5
document.close();
}
示例7: main
import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
* Adds an Image at an absolute position.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("absolutepositions.pdf"));
// step 3: we open the document
document.open();
// step 4: we add content
Image png = Image.getInstance(PdfTestBase.RESOURCES_DIR + "hitchcock.png");
png.setAbsolutePosition(171, 250);
document.add(png);
png.setAbsolutePosition(342, 500);
document.add(png);
// step 5: we close the document
document.close();
}
示例8: main
import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
* How to substiture special characters with Phrase.getInstance.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2:
// we create a writer that listens to the document
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("SymbolSubstitution.pdf"));
// step 3: we open the document
document.open();
// step 4:
document.add(Phrase.getInstance("What is the " + (char) 945 + "-coefficient of the " + (char) 946
+ "-factor in the " + (char) 947 + "-equation?\n"));
for (int i = 913; i < 970; i++) {
document.add(Phrase.getInstance(" " + i + ": " + (char) i));
}
// step 5: we close the document
document.close();
}
示例9: main
import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
* Generates a document with a header containing Page x of y and with a Watermark on every page.
*/
@Test
public void main() throws Exception {
// step 1: creating the document
Document doc = new Document(PageSize.A4, 50, 50, 100, 72);
// step 2: creating the writer
PdfWriter writer = PdfWriter.getInstance(doc, PdfTestBase.getOutputStream( "pageNumbersWatermark.pdf"));
// step 3: initialisations + opening the document
writer.setPageEvent(new PageNumbersWatermarkTest());
doc.open();
// step 4: adding content
String text = "some padding text ";
for (int k = 0; k < 10; ++k) {
text += text;
}
Paragraph p = new Paragraph(text);
p.setAlignment(Element.ALIGN_JUSTIFIED);
doc.add(p);
// step 5: closing the document
doc.close();
}
示例10: buildPdfDocument
import com.lowagie.text.Document; //導入方法依賴的package包/類
protected void buildPdfDocument(Map<String, Object> map, Document document,
PdfWriter pdfWriter, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
Map<String,String> userData = (Map<String,String>) map.get("userData");
Table table = new Table(2);
table.addCell("No.");
table.addCell("User Name");
for (Map.Entry<String, String> entry : userData.entrySet()) {
table.addCell(entry.getKey());
table.addCell(entry.getValue());
}
document.add(table);
}
示例11: buildPdfDocument
import com.lowagie.text.Document; //導入方法依賴的package包/類
@Override
protected void buildPdfDocument(Map<String, Object> map,
Document document,
PdfWriter pdfWriter,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
Grade grade = (Grade) map.get("grade");
String validationLink = (String) map.get("validationLink");
document.add(generateTitle());
document.add(EMPTY_LINE);
document.add(generateContent(grade));
document.add(EMPTY_LINE);
document.add(generateValidation(validationLink));
}
示例12: main
import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
* Demonstrates how to measure and scale the width of a Chunk.
*
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2:
// we create a writer that listens to the document
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Width.pdf"));
// step 3: we open the document
document.open();
// step 4:
Chunk c = new Chunk("quick brown fox jumps over the lazy dog");
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.");
document.add(p);
document.add(c);
document.add(Chunk.NEWLINE);
c.setHorizontalScaling(0.5f);
document.add(c);
document.add(c);
// step 5: we close the document
document.close();
}
示例13: main
import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
* Uses a java.awt.Image object to construct a com.lowagie.text.Image
* object.
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("awt_image.pdf"));
// step 3: we open the document
document.open();
// step 4: we add content to the document
for (int i = 0; i < 300; i++) {
document.add(new Phrase("Who is this? "));
}
PdfContentByte cb = writer.getDirectContent();
java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage(PdfTestBase.RESOURCES_DIR + "H.gif");
Image image = Image.getInstance(awtImage, null);
image.setAbsolutePosition(100, 500);
cb.addImage(image);
Image gif = Image.getInstance(awtImage, new Color(0x00, 0xFF, 0xFF), true);
gif.setAbsolutePosition(300, 500);
cb.addImage(gif);
Image img1 = Image.getInstance(awtImage, null, true);
img1.setAbsolutePosition(100, 200);
cb.addImage(img1);
Image img2 = Image.getInstance(awtImage, new Color(0xFF, 0xFF, 0x00), false);
img2.setAbsolutePosition(300, 200);
cb.addImage(img2);
// step 5: we close the document
document.close();
}
示例14: main
import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
* Example originally written by Wendy Smoak to generate a Table with
* 'floating boxes'. Adapted by Bruno Lowagie.
*
*/
@Test
public void main() throws Exception {
FloatingBoxesTest floatingBoxes = new FloatingBoxesTest();
// step 1
Document document = new Document();
// step 2
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("FloatingBoxes.pdf"));
// step 3
document.open();
// step 4
PdfPTable table = new PdfPTable(2);
table.setTableEvent(floatingBoxes);
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
table.getDefaultCell().setCellEvent(floatingBoxes);
table.getDefaultCell().setPadding(5f);
table.addCell("value");
table.addCell("name");
table.addCell(new Paragraph("dog"));
table.addCell(new Paragraph("cat"));
table.addCell(new Paragraph("bird"));
table.addCell(new Paragraph("horse"));
document.add(table);
// step 5
document.close();
}
示例15: main
import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
* An example using MultiColumnText with irregular columns.
*/
@Test
public void main() throws Exception {
Document document = new Document();
OutputStream out = PdfTestBase.getOutputStream("multicolumnsimple.pdf");
PdfWriter.getInstance(document, out);
document.open();
MultiColumnText mct = new MultiColumnText();
// set up 3 even columns with 10pt space between
mct.addRegularColumns(document.left(), document.right(), 10f, 3);
// Write some iText poems
for (int i = 0; i < 30; i++) {
mct.addElement(new Paragraph(String.valueOf(i + 1)));
mct.addElement(newPara(randomWord(noun), Element.ALIGN_CENTER, Font.BOLDITALIC));
for (int j = 0; j < 4; j++) {
mct.addElement(newPara(poemLine(), Element.ALIGN_LEFT, Font.NORMAL));
}
mct.addElement(newPara(randomWord(adverb), Element.ALIGN_LEFT, Font.NORMAL));
mct.addElement(newPara("\n\n", Element.ALIGN_LEFT, Font.NORMAL));
}
document.add(mct);
document.close();
}