本文整理匯總了Java中rst.pdfbox.layout.elements.Document.save方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.save方法的具體用法?Java Document.save怎麽用?Java Document.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rst.pdfbox.layout.elements.Document
的用法示例。
在下文中一共展示了Document.save方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: save
import rst.pdfbox.layout.elements.Document; //導入方法依賴的package包/類
/**
* Renders the document into the given output stream
*
* @param stream
* @throws IOException
*/
public void save(OutputStream stream) throws IOException {
// Render
Document document = new Document(style.gethMargin(), style.gethMargin(), style.getvMargin(), style.getvMargin());
for (Element element : this.elements) {
element.render(document, 0, this.style);
}
// Save to temp file
File tmp = File.createTempFile("arx", "certificate");
document.save(tmp);
// Load and watermark
PDDocument pdDocument = PDDocument.load(tmp);
Watermark watermark = new Watermark(pdDocument);
watermark.mark(pdDocument);
// Save
pdDocument.save(stream);
pdDocument.close();
tmp.delete();
}
示例2: main
import rst.pdfbox.layout.elements.Document; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
Document document = new Document(40, 60, 40, 60);
Paragraph paragraph = new Paragraph();
paragraph.addText("Hello Document", 20,
PDType1Font.HELVETICA);
document.add(paragraph);
final OutputStream outputStream = new FileOutputStream("hellodoc.pdf");
document.save(outputStream);
}
示例3: documentToByteArray
import rst.pdfbox.layout.elements.Document; //導入方法依賴的package包/類
private byte[] documentToByteArray(Document document) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
document.save(out);
return out.toByteArray();
}
示例4: main
import rst.pdfbox.layout.elements.Document; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String text1 = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, "
+ "sed diam nonumy eirmod tempor invidunt ut labore et dolore magna "
+ "aliquyam erat, _sed diam_ voluptua. At vero eos et *accusam et justo* "
+ "duo dolores et ea rebum.\n\nStet clita kasd gubergren, no sea takimata "
+ "sanctus est *Lorem ipsum _dolor* sit_ amet. Lorem ipsum dolor sit amet, "
+ "consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt "
+ "ut labore et dolore magna aliquyam erat, *sed diam voluptua.\n\n"
+ "At vero eos et accusam* et justo duo dolores et ea rebum. Stet clita kasd "
+ "gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n\n";
String text2 = "At *vero eos et accusam* et justo duo dolores et ea rebum."
+ "Stet clita kasd gubergren, no sea takimata\n\n"
+ "sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, "
+ "_consetetur sadipscing elitr_, sed diam nonumy eirmod tempor invidunt "
+ "ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero "
+ "eos et _accusam et *justo* duo dolores_ et ea rebum. Stet clita kasd "
+ "gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n";
Document document = new Document(40, 60, 40, 60);
Paragraph paragraph1 = new Paragraph();
paragraph1.addMarkup(text1, 11, BaseFont.Times);
document.add(paragraph1);
Paragraph paragraph2 = new Paragraph();
paragraph2.addMarkup(text2, 12, BaseFont.Helvetica);
document.add(paragraph2);
Paragraph paragraph3 = new Paragraph();
paragraph3.addMarkup(text1, 8, BaseFont.Courier);
document.add(paragraph3);
document.add(paragraph1);
document.add(paragraph3);
document.add(paragraph1);
document.add(paragraph2);
document.add(paragraph1);
document.add(paragraph3);
document.add(paragraph2);
document.add(paragraph1);
document.add(paragraph1);
document.add(paragraph3);
document.add(paragraph2);
document.add(paragraph2);
document.add(paragraph3);
document.add(paragraph1);
document.add(paragraph1);
document.add(paragraph2);
document.add(paragraph1);
document.add(paragraph3);
document.add(paragraph2);
document.add(paragraph3);
document.add(paragraph1);
document.add(paragraph1);
document.add(paragraph3);
document.add(paragraph2);
document.add(paragraph2);
final OutputStream outputStream = new FileOutputStream(
"multiplepages.pdf");
document.save(outputStream);
}
示例5: main
import rst.pdfbox.layout.elements.Document; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String text1 = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, "
+ "sed diam nonumy eirmod tempor invidunt ut labore et dolore magna "
+ "aliquyam erat, _sed diam_ voluptua. At vero eos et *accusam et justo* "
+ "duo dolores et ea rebum.\n\nStet clita kasd gubergren, no sea takimata "
+ "sanctus est *Lorem ipsum _dolor* sit_ amet. Lorem ipsum dolor sit amet, "
+ "consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt "
+ "ut labore et dolore magna aliquyam erat, *sed diam voluptua.\n\n"
+ "At vero eos et accusam* et justo duo dolores et ea rebum. Stet clita kasd "
+ "gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n\n";
String text2 = "At *vero eos et accusam* et justo duo dolores et ea rebum."
+ "Stet clita kasd gubergren, no sea takimata\n\n"
+ "sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, "
+ "_consetetur sadipscing elitr_, sed diam nonumy eirmod tempor invidunt "
+ "ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero "
+ "eos et _accusam et *justo* duo dolores_ et ea rebum. Stet clita kasd "
+ "gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n";
Document document = new Document(40, 60, 40, 60);
SectionRenderer sectionRenderer = new SectionRenderer();
document.addRenderer(sectionRenderer);
document.addRenderListener(sectionRenderer);
Paragraph paragraph = new Paragraph();
paragraph.addMarkup(text1, 11, BaseFont.Times);
paragraph.addMarkup(text2, 12, BaseFont.Helvetica);
paragraph.addMarkup(text1, 8, BaseFont.Courier);
document.add(new Section(1));
document.add(paragraph);
document.add(paragraph);
document.add(paragraph);
document.add(new Section(2));
document.add(paragraph);
document.add(paragraph);
document.add(paragraph);
document.add(new Section(3));
document.add(paragraph);
document.add(paragraph);
final OutputStream outputStream = new FileOutputStream("customrenderer.pdf");
document.save(outputStream);
}
示例6: main
import rst.pdfbox.layout.elements.Document; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String text1 = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, "
+ "sed diam nonumy eirmod tempor invidunt ut labore et dolore magna "
+ "aliquyam erat, _sed diam_ voluptua. At vero eos et *accusam et justo* "
+ "duo dolores et ea rebum.\n\nStet clita kasd gubergren, no sea takimata "
+ "sanctus est *Lorem ipsum _dolor* sit_ amet. Lorem ipsum dolor sit amet, "
+ "consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt "
+ "ut labore et dolore magna aliquyam erat, *sed diam voluptua.\n\n"
+ "At vero eos et accusam* et justo duo dolores et ea rebum. Stet clita kasd "
+ "gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n\n";
String text2 = "At *vero {link[#hello]}eos{link} et accusam* et justo duo dolores et ea rebum."
+ "Stet clita kasd gubergren, no sea takimata\n\n"
+ "sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, "
+ "_consetetur sadipscing elitr_, sed diam nonumy eirmod tempor invidunt "
+ "ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero "
+ "eos et _accusam et *justo* duo dolores_ et ea rebum. Stet clita kasd "
+ "gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n";
Document document = new Document(40, 60, 40, 60);
Paragraph paragraph0 = new Paragraph();
paragraph0.addMarkup("This is a link to {link[https://github.com/ralfstuckert/pdfbox-layout]}PDFBox-Layout{link}.\n\n", 11, BaseFont.Times);
paragraph0.addMarkup("Now the same link with color instead of underline {color:#ff5000}{link:none[https://github.com/ralfstuckert/pdfbox-layout]}PDFBox-Layout{link}{color:#000000}.\n\n", 11, BaseFont.Times);
paragraph0.addMarkup("And here comes a link to an internal anchor name {color:#ff5000}{link[#hello]}hello{link}{color:#000000}.\n\n", 11, BaseFont.Times);
document.add(paragraph0);
Paragraph paragraph1 = new Paragraph();
paragraph1.addMarkup(text1, 11, BaseFont.Times);
document.add(paragraph1);
Paragraph paragraph2 = new Paragraph();
paragraph2.addMarkup(text2, 12, BaseFont.Helvetica);
document.add(paragraph2);
Paragraph paragraph3 = new Paragraph();
paragraph3.addMarkup(text1, 8, BaseFont.Courier);
document.add(paragraph3);
Paragraph paragraph4 = new Paragraph();
paragraph4.addMarkup("\n\n{anchor:hello}Here{anchor} comes the internal anchor named *hello*\n\n", 15, BaseFont.Courier);
document.add(paragraph1);
document.add(paragraph3);
document.add(paragraph1);
document.add(paragraph2);
document.add(paragraph1);
document.add(paragraph3);
document.add(paragraph4);
document.add(paragraph2);
document.add(paragraph1);
document.add(paragraph1);
final OutputStream outputStream = new FileOutputStream(
"links.pdf");
document.save(outputStream);
}
示例7: main
import rst.pdfbox.layout.elements.Document; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String text = "*Lorem ipsum* dolor sit amet, consetetur sadipscing elitr, "
+ "sed diam nonumy eirmod tempor invidunt ut labore et dolore magna "
+ "aliquyam erat, _sed diam_ voluptua. At vero eos et _accusam et justo_ "
+ "duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata "
+ "sanctus est _Lorem ipsum dolor sit_ amet. Lorem ipsum dolor sit amet, "
+ "consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt "
+ "ut labore et dolore magna aliquyam erat, sed diam.";
// create document without margins
Document document = new Document();
document.add(new ColumnLayout(2, 5));
Paragraph left = new Paragraph();
// no line spacing for the first line
left.setApplyLineSpacingToFirstLine(false);
// use a bigger line spacing to visualize the effects of line spacing more drastically
left.setLineSpacing(1.5f);
left.setMaxWidth(document.getPageWidth()/2);
left.addMarkup(text, 11, BaseFont.Times);
document.add(left);
document.add(left);
document.add(left);
document.add(ColumnLayout.NEWCOLUMN);
Paragraph right = new Paragraph();
right.setLineSpacing(1.5f);
right.setMaxWidth(document.getPageWidth()/2);
right.addMarkup(text, 11, BaseFont.Times);
document.add(right);
document.add(right);
document.add(right);
final OutputStream outputStream = new FileOutputStream(
"linespacing.pdf");
document.save(outputStream);
}
示例8: main
import rst.pdfbox.layout.elements.Document; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String text1 = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, "
+ "sed diam nonumy eirmod tempor invidunt ut labore et dolore magna "
+ "aliquyam erat, _sed diam_ voluptua. At vero eos et *accusam et justo* "
+ "duo dolores et ea rebum.\n\nStet clita kasd gubergren, no sea takimata "
+ "sanctus est *Lorem ipsum _dolor* sit_ amet. Lorem ipsum dolor sit amet, "
+ "consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt "
+ "ut labore et dolore magna aliquyam erat, *sed diam voluptua.\n\n"
+ "At vero eos et accusam* et justo duo dolores et ea rebum. Stet clita kasd "
+ "gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n\n";
String text2 = "At *vero eos et accusam* et justo duo dolores et ea rebum. "
+ "Stet clita kasd gubergren, no sea takimata\n\n"
+ "sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, "
+ "_consetetur sadipscing elitr_, sed diam nonumy eirmod tempor invidunt "
+ "ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero "
+ "eos et _accusam et *justo* duo dolores_ et ea rebum. Stet clita kasd "
+ "gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n";
Document document = new Document(40, 50, 40, 60);
Paragraph title = new Paragraph();
title.addMarkup("*This Text is organized in Colums*", 20, BaseFont.Times);
document.add(title, VerticalLayoutHint.CENTER);
document.add(new VerticalSpacer(5));
// use column layout from now on
document.add(new ColumnLayout(2, 10));
Paragraph paragraph1 = new Paragraph();
paragraph1.addMarkup(text1, 11, BaseFont.Times);
document.add(paragraph1);
Paragraph paragraph2 = new Paragraph();
paragraph2.addMarkup(text2, 12, BaseFont.Helvetica);
document.add(paragraph2);
Paragraph paragraph3 = new Paragraph();
paragraph3.addMarkup(text1, 8, BaseFont.Courier);
document.add(paragraph3);
document.add(paragraph1);
document.add(paragraph3);
document.add(paragraph1);
document.add(paragraph2);
document.add(paragraph1);
document.add(paragraph3);
document.add(paragraph2);
document.add(paragraph1);
document.add(paragraph1);
document.add(paragraph3);
document.add(paragraph2);
document.add(paragraph2);
document.add(paragraph3);
document.add(paragraph1);
document.add(paragraph1);
document.add(paragraph2);
document.add(paragraph1);
document.add(paragraph3);
document.add(paragraph2);
document.add(paragraph3);
document.add(paragraph1);
document.add(paragraph1);
document.add(paragraph3);
document.add(paragraph2);
document.add(paragraph2);
final OutputStream outputStream = new FileOutputStream(
"columns.pdf");
document.save(outputStream);
}