本文整理汇总了Java中com.lowagie.text.Paragraph类的典型用法代码示例。如果您正苦于以下问题:Java Paragraph类的具体用法?Java Paragraph怎么用?Java Paragraph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Paragraph类属于com.lowagie.text包,在下文中一共展示了Paragraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createContent
import com.lowagie.text.Paragraph; //导入依赖的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: main
import com.lowagie.text.Paragraph; //导入依赖的package包/类
/**
* Demonstrates the use of PageEvents.
*/
@Test
public void main() throws Exception {
Document document = new Document(PageSize.A4, 50, 50, 70, 70);
PdfWriter writer = PdfWriter.getInstance(document,
PdfTestBase.getOutputStream("endpage.pdf"));
writer.setPageEvent(new EndPageTest());
document.open();
String text = "Lots of text. ";
for (int k = 0; k < 10; ++k)
text += text;
document.add(new Paragraph(text));
document.close();
}
示例3: main
import com.lowagie.text.Paragraph; //导入依赖的package包/类
/**
* Creates a document with Named Actions.
*
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step 2: we create a writer that listens to the document
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("NamedActions.pdf"));
// step 3: we open the document
document.open();
// step 4: we add some content
Paragraph p = new Paragraph(new Chunk("Click to print").setAction(new PdfAction(PdfAction.PRINTDIALOG)));
PdfPTable table = new PdfPTable(4);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(new Phrase(new Chunk("First Page").setAction(new PdfAction(PdfAction.FIRSTPAGE))));
table.addCell(new Phrase(new Chunk("Prev Page").setAction(new PdfAction(PdfAction.PREVPAGE))));
table.addCell(new Phrase(new Chunk("Next Page").setAction(new PdfAction(PdfAction.NEXTPAGE))));
table.addCell(new Phrase(new Chunk("Last Page").setAction(new PdfAction(PdfAction.LASTPAGE))));
for (int k = 1; k <= 10; ++k) {
document.add(new Paragraph("This is page " + k));
document.add(Chunk.NEWLINE);
document.add(table);
document.add(p);
document.newPage();
}
// step 5: we close the document
document.close();
}
示例4: main
import com.lowagie.text.Paragraph; //导入依赖的package包/类
/**
* Creates a document with Named Actions.
*
* @param args The file to open
*/
public void main(String... args) throws Exception {
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step 2: we create a writer that listens to the document
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("OpenApplication.pdf"));
// step 3: we open the document
document.open();
// step 4: we add some content
String application = args[0];
Paragraph p = new Paragraph(new Chunk("Click to open " + application).setAction(
new PdfAction(application, null, null, null)));
document.add(p);
// step 5: we close the document
document.close();
}
示例5: main
import com.lowagie.text.Paragraph; //导入依赖的package包/类
/**
* Creates a document with some goto actions.
*
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
Document remote = new Document();
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Actions.pdf"));
PdfWriter.getInstance(remote, PdfTestBase.getOutputStream("remote.pdf"));
// step 3:
document.open();
remote.open();
// step 4: we add some content
PdfAction action = PdfAction.gotoLocalPage(2, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), writer);
writer.setOpenAction(action);
document.add(new Paragraph("Page 1"));
document.newPage();
document.add(new Paragraph("Page 2"));
document.add(new Chunk("goto page 1").setAction(PdfAction.gotoLocalPage(1, new PdfDestination(
PdfDestination.FITH, 500), writer)));
document.add(Chunk.NEWLINE);
document.add(new Chunk("goto another document").setAction(PdfAction.gotoRemotePage("remote.pdf", "test", false,
true)));
remote.add(new Paragraph("Some remote document"));
remote.newPage();
Paragraph p = new Paragraph("This paragraph contains a ");
p.add(new Chunk("local destination").setLocalDestination("test"));
remote.add(p);
// step 5: we close the document
document.close();
remote.close();
}
示例6: main
import com.lowagie.text.Paragraph; //导入依赖的package包/类
/**
* Creates a document with chained Actions.
*
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("ChainedActions.pdf"));
// step 3: we add Javascript as Metadata and we open the document
document.open();
// step 4: we add some content
PdfAction action = PdfAction.javaScript("app.alert('Welcome at my site');\r", writer);
action.next(new PdfAction("http://www.lowagie.com/iText/"));
Paragraph p = new Paragraph(new Chunk("Click to go to Bruno's site").setAction(action));
document.add(p);
// step 5: we close the document
document.close();
}
示例7: main
import com.lowagie.text.Paragraph; //导入依赖的package包/类
/**
* Extended font styles example.
*
*
*/
@Test
public void main() throws Exception {
Document document = new Document();
RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("ExtendedFontStyles.rtf"));
document.open();
// Use the RtfFont.STYLE_* instead of the Font styles.
RtfFont doubleStrikethrough = new RtfFont("Arial", RtfFont.UNDEFINED,
RtfFont.STYLE_DOUBLE_STRIKETHROUGH);
RtfFont shadow = new RtfFont("Arial", RtfFont.UNDEFINED,
RtfFont.STYLE_SHADOW);
// Or combine them with Font styles.
RtfFont engravedItalic = new RtfFont("Arial", RtfFont.UNDEFINED,
RtfFont.STYLE_ENGRAVED | Font.ITALIC);
// The hidden style is special since it hides text.
RtfFont hidden = new RtfFont("Arial", RtfFont.UNDEFINED,
RtfFont.STYLE_HIDDEN);
Paragraph paragraph = new Paragraph("This text is ", new RtfFont("Arial", 12));
// Use the RtfFonts when creating the text.
paragraph.add(new Chunk("deleted,", doubleStrikethrough));
paragraph.add(new Chunk(" shady,", shadow));
paragraph.add(new Chunk(" engraved and italic", engravedItalic));
paragraph.add(" and");
paragraph.add(new Chunk(" you won't see this", hidden));
paragraph.add(" nothing.");
document.add(paragraph);
document.close();
}
示例8: main
import com.lowagie.text.Paragraph; //导入依赖的package包/类
/**
* Creates a document with outlines.
*
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document(PageSize.A6);
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Bookmarks.pdf"));
// step 3:
writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
document.open();
// step 4: we grab the ContentByte and do some stuff with it
writer.setPageEvent(new BookmarksTest());
document.add(new Paragraph(
"GALLIA est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur. Hi omnes lingua, institutis, legibus inter se differunt. Gallos ab Aquitanis Garumna flumen, a Belgis Matrona et Sequana dividit. Horum omnium fortissimi sunt Belgae, propterea quod a cultu atque humanitate provinciae longissime absunt, minimeque ad eos mercatores saepe commeant atque ea quae ad effeminandos animos pertinent important, proximique sunt Germanis, qui trans Rhenum incolunt, quibuscum continenter bellum gerunt. Qua de causa Helvetii quoque reliquos Gallos virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, cum aut suis finibus eos prohibent aut ipsi in eorum finibus bellum gerunt.",
new Font(Font.HELVETICA, 12)));
document.add(new Paragraph(
"[Eorum una, pars, quam Gallos obtinere dictum est, initium capit a flumine Rhodano, continetur Garumna flumine, Oceano, finibus Belgarum, attingit etiam ab Sequanis et Helvetiis flumen Rhenum, vergit ad septentriones. Belgae ab extremis Galliae finibus oriuntur, pertinent ad inferiorem partem fluminis Rheni, spectant in septentrionem et orientem solem. Aquitania a Garumna flumine ad Pyrenaeos montes et eam partem Oceani quae est ad Hispaniam pertinet; spectat inter occasum solis et septentriones.]",
new Font(Font.HELVETICA, 12)));
document.add(new Paragraph(
"Apud Helvetios longe nobilissimus fuit et ditissimus Orgetorix. Is M. Messala, [et P.] M. Pisone consulibus regni cupiditate inductus coniurationem nobilitatis fecit et civitati persuasit ut de finibus suis cum omnibus copiis exirent: perfacile esse, cum virtute omnibus praestarent, totius Galliae imperio potiri. Id hoc facilius iis persuasit, quod undique loci natura Helvetii continentur: una ex parte flumine Rheno latissimo atque altissimo, qui agrum Helvetium a Germanis dividit; altera ex parte monte Iura altissimo, qui est inter Sequanos et Helvetios; tertia lacu Lemanno et flumine Rhodano, qui provinciam nostram ab Helvetiis dividit. His rebus fiebat ut et minus late vagarentur et minus facile finitimis bellum inferre possent; qua ex parte homines bellandi cupidi magno dolore adficiebantur. Pro multitudine autem hominum et pro gloria belli atque fortitudinis angustos se fines habere arbitrabantur, qui in longitudinem milia passuum CCXL, in latitudinem CLXXX patebant.",
new Font(Font.HELVETICA, 12)));
document.add(new Paragraph(
"His rebus adducti et auctoritate Orgetorigis permoti constituerunt ea quae ad proficiscendum pertinerent comparare, iumentorum et carrorum quam maximum numerum coemere, sementes quam maximas facere, ut in itinere copia frumenti suppeteret, cum proximis civitatibus pacem et amicitiam confirmare. Ad eas res conficiendas biennium sibi satis esse duxerunt; in tertium annum profectionem lege confirmant. Ad eas res conficiendas Orgetorix deligitur. Is sibi legationem ad civitates suscipit. In eo itinere persuadet Castico, Catamantaloedis filio, Sequano, cuius pater regnum in Sequanis multos annos obtinuerat et a senatu populi Romani amicus appellatus erat, ut regnum in civitate sua occuparet, quod pater ante habuerit; itemque Dumnorigi Haeduo, fratri Diviciaci, qui eo tempore principatum in civitate obtinebat ac maxime plebi acceptus erat, ut idem conaretur persuadet eique filiam suam in matrimonium dat. Perfacile factu esse illis probat conata perficere, propterea quod ipse suae civitatis imperium obtenturus esset: non esse dubium quin totius Galliae plurimum Helvetii possent; se suis copiis suoque exercitu illis regna conciliaturum confirmat. Hac oratione adducti inter se fidem et ius iurandum dant et regno occupato per tres potentissimos ac firmissimos populos totius Galliae sese potiri posse sperant.",
new Font(Font.HELVETICA, 12)));
document.add(new Paragraph(
"Ea res est Helvetiis per indicium enuntiata. Moribus suis Orgetoricem ex vinculis causam dicere coegerunt; damnatum poenam sequi oportebat, ut igni cremaretur. Die constituta causae dictionis Orgetorix ad iudicium omnem suam familiam, ad hominum milia decem, undique coegit, et omnes clientes obaeratosque suos, quorum magnum numerum habebat, eodem conduxit; per eos ne causam diceret se eripuit. Cum civitas ob eam rem incitata armis ius suum exequi conaretur multitudinemque hominum ex agris magistratus cogerent, Orgetorix mortuus est; neque abest suspicio, ut Helvetii arbitrantur, quin ipse sibi mortem consciverit.",
new Font(Font.HELVETICA, 12)));
// step 5: we close the document
document.close();
}
示例9: main
import com.lowagie.text.Paragraph; //导入依赖的package包/类
/**
* Demonstrates some PageLabel functionality.
*
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document();
// step 2:
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("PageLabels.pdf"));
// step 3:
writer.setViewerPreferences(PdfWriter.PageModeUseThumbs);
document.open();
// step 4:
// we add some content
for (int k = 1; k <= 10; ++k) {
document.add(new Paragraph(
"This document has the logical page numbers: i,ii,iii,iv,1,2,3,A-8,A-9,A-10\nReal page " + k));
document.newPage();
}
PdfPageLabels pageLabels = new PdfPageLabels();
pageLabels.addPageLabel(1, PdfPageLabels.LOWERCASE_ROMAN_NUMERALS);
pageLabels.addPageLabel(5, PdfPageLabels.DECIMAL_ARABIC_NUMERALS);
pageLabels.addPageLabel(8, PdfPageLabels.DECIMAL_ARABIC_NUMERALS, "A-", 8);
writer.setPageLabels(pageLabels);
// step 5: we close the document
document.close();
}
示例10: testUnbalancedSaveStateOnClose
import com.lowagie.text.Paragraph; //导入依赖的package包/类
@Test(expected=IllegalPdfSyntaxException.class)
public void testUnbalancedSaveStateOnClose() throws Exception {
initializeDocument();
writer.getDirectContent().saveState();
document.add(new Paragraph("Hello World"));
document.close();
}
示例11: main
import com.lowagie.text.Paragraph; //导入依赖的package包/类
/**
* Demonstrates some Paragraph functionality.
*
*/
@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("Paragraphs.pdf"));
// step 3: we open the document
document.open();
// step 4:
Paragraph p1 = new Paragraph(new Chunk("This is my first paragraph. ", FontFactory.getFont(
FontFactory.HELVETICA, 10)));
p1.add("The leading of this paragraph is calculated automagically. ");
p1.add("The default leading is 1.5 times the fontsize. ");
p1.add(new Chunk("You can add chunks "));
p1.add(new Phrase("or you can add phrases. "));
p1.add(new Phrase(
"Unless you change the leading with the method setLeading, the leading doesn't change if you add text with another leading. This can lead to some problems.",
FontFactory.getFont(FontFactory.HELVETICA, 18)));
document.add(p1);
Paragraph p2 = new Paragraph(new Phrase("This is my second paragraph. ", FontFactory.getFont(
FontFactory.HELVETICA, 12)));
p2.add("As you can see, it started on a new line.");
document.add(p2);
Paragraph p3 = new Paragraph("This is my third paragraph.", FontFactory.getFont(FontFactory.HELVETICA, 12));
document.add(p3);
// step 5: we close the document
document.close();
}
示例12: main
import com.lowagie.text.Paragraph; //导入依赖的package包/类
/**
* Using FontSelector.
*/
@Test
public void main() throws Exception {
// step 1
Document document = new Document();
// step 2
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("differentfonts.pdf"));
// step 3
document.open();
// step 4
Paragraph p = new Paragraph();
p.add(new Chunk("This text is in Times Roman. This is ZapfDingbats: ", new Font(Font.TIMES_ROMAN, 12)));
p.add(new Chunk("abcdefghijklmnopqrstuvwxyz", new Font(Font.ZAPFDINGBATS, 12)));
p.add(new Chunk(". This is font Symbol: ", new Font(Font.TIMES_ROMAN, 12)));
p.add(new Chunk("abcdefghijklmnopqrstuvwxyz", new Font(Font.SYMBOL, 12)));
document.add(new Paragraph(p));
// step 5
document.close();
}
示例13: main
import com.lowagie.text.Paragraph; //导入依赖的package包/类
/**
* Generates an HTML page with the text 'Hello World'
*
*/
@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 HTML-stream to a file
HtmlWriter.getInstance(document, PdfTestBase.getOutputStream("HelloWorld.html"));
// step 3: we open the document
document.open();
// step 4: we add a paragraph to the document
document.add(new Paragraph("Hello World"));
// step 5: we close the document
document.close();
}
示例14: main
import com.lowagie.text.Paragraph; //导入依赖的package包/类
/**
* Generates 2 documents: one that respects the order of Images added,
* another that has the default behaviour: only show the images if they fit
* on the page, if they don't fit, wait until the next page.
*/
@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("notInSequence.pdf"));
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("inSequence.pdf"));
writer.setStrictImageSequence(true);
// step 3: we open the document
document.open();
// step 4:
document.add(new Paragraph("1st image"));
Image jpg = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
document.add(jpg);
document.add(new Paragraph("2nd image"));
Image gif = Image.getInstance(PdfTestBase.RESOURCES_DIR + "getacro.gif");
document.add(gif);
document.add(new Paragraph("3rd image"));
document.add(jpg);
document.add(new Paragraph("4th image"));
document.add(gif);
document.add(new Paragraph("5th image"));
document.add(jpg);
document.add(new Paragraph("6th image"));
document.add(gif);
document.add(new Paragraph("7th image"));
document.add(jpg);
// step 5: we close the document
document.close();
}
示例15: main
import com.lowagie.text.Paragraph; //导入依赖的package包/类
/**
* Scaling an image.
*/
@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("scaling.pdf"));
// step 3: we open the document
document.open();
// step 4: we add content
Image jpg1 = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
jpg1.scaleAbsolute(160, 120);
document.add(new Paragraph("scaleAbsolute(160, 120)"));
document.add(jpg1);
Image jpg2 = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
jpg2.scalePercent(50);
document.add(new Paragraph("scalePercent(50)"));
document.add(jpg2);
Image jpg3 = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
jpg3.scaleAbsolute(320, 120);
document.add(new Paragraph("scaleAbsolute(320, 120)"));
document.add(jpg3);
Image jpg4 = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
jpg4.scalePercent(100, 50);
document.add(new Paragraph("scalePercent(100, 50)"));
document.add(jpg4);
// step 5: we close the document
document.close();
}