當前位置: 首頁>>代碼示例>>Java>>正文


Java Document.newPage方法代碼示例

本文整理匯總了Java中com.lowagie.text.Document.newPage方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.newPage方法的具體用法?Java Document.newPage怎麽用?Java Document.newPage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.lowagie.text.Document的用法示例。


在下文中一共展示了Document.newPage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
 * Break a large table up into several smaller tables for memory management
 * purposes.
 * 
 */
@Test
public void main() throws Exception {
	// step1
	Document document = new Document(PageSize.A4, 10, 10, 10, 10);
	// step2
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("SplitTable.pdf"));
	// step3
	document.open();
	// step4

	PdfContentByte cb = writer.getDirectContent();
	PdfPTable table = new PdfPTable(10);
	for (int k = 1; k <= 100; ++k) {
		table.addCell("The number " + k);
	}
	table.setTotalWidth(800);
	table.writeSelectedRows(0, 5, 0, -1, 50, 650, cb);
	document.newPage();
	table.writeSelectedRows(5, -1, 0, -1, 50, 650, cb);
	document.close();

	// step5
	document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:30,代碼來源:SplitTableTest.java

示例2: createTempFile

import com.lowagie.text.Document; //導入方法依賴的package包/類
private void createTempFile(String filename, String[] pageContents) throws Exception{
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(filename));
    document.open();
    
    for (int i = 0; i < pageContents.length; i++) {
        if (i != 0)
            document.newPage();

        String content = pageContents[i];
        Chunk contentChunk = new Chunk(content);
        document.add(contentChunk);
    }
    
    
    document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:18,代碼來源:TestPdfCopyAndStamp.java

示例3: main

import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
 * Space Word Ratio.
 */
@Test
public void main() throws Exception {
	// step 1
	Document document = new Document(PageSize.A4, 50, 350, 50, 50);
	// step 2
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("spacewordratio.pdf"));
	// step 3
	document.open();
	// step 4
	String text = "Flanders International Filmfestival Ghent - Internationaal Filmfestival van Vlaanderen Gent";
	Paragraph p = new Paragraph(text);
	p.setAlignment(Element.ALIGN_JUSTIFIED);
	document.add(p);
	document.newPage();
	writer.setSpaceCharRatio(PdfWriter.NO_SPACE_CHAR_RATIO);
	document.add(p);

	// step 5
	document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:24,代碼來源:SpaceWordRatioTest.java

示例4: main

import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
 * Creates a document that jumps to a Local Destination upon opening.
 * 
 */
@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("LocalDestination.pdf"));
	// step 3: we open the document
	document.open();
	// step 4: we add some content
	document.add(new Paragraph("Page 1"));
	document.newPage();
	document.add(new Paragraph("This PDF file jumps directly to page 2 when opened"));
	PdfContentByte cb = writer.getDirectContent();
	cb.localDestination("page2", new PdfDestination(PdfDestination.XYZ, -1, 10000, 0));
	writer.setOpenAction("page2");

	// step 5: we close the document
	document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:25,代碼來源:LocalDestinationTest.java

示例5: testSimplePdf

import com.lowagie.text.Document; //導入方法依賴的package包/類
@Test
public void testSimplePdf() throws FileNotFoundException, DocumentException {
	// create document
	Document document = PdfTestBase.createPdf("testSimplePdf.pdf");
	try {
		// new page with a rectangle
		document.open();
		document.newPage();
		Annotation ann = new Annotation("Title", "Text");
		Rectangle rect = new Rectangle(100, 100);
		document.add(ann);
		document.add(rect);
	} finally {
		// close document
		if (document != null)
			document.close();
	}

}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:20,代碼來源:SimplePdfTest.java

示例6: generateBlankPdf

import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
 * Genera un pdf vac�o
 * @param os
 * @throws Exception
 */
public static void generateBlankPdf(OutputStream os) throws Exception
{
	Document document = new Document(PageSize.A4);
	PdfWriter writer = PdfWriter.getInstance(document,os);
	writer.setEncryption(null, null, PdfWriter.AllowCopy | PdfWriter.AllowPrinting, PdfWriter.STRENGTH40BITS);
	document.open();		
	document.newPage();
	writer.setPageEmpty(false);   					
	document.close();
}
 
開發者ID:GovernIB,項目名稱:sistra,代碼行數:16,代碼來源:UtilPDF.java

示例7: testGetLink

import com.lowagie.text.Document; //導入方法依賴的package包/類
@Ignore("validity of test needs to be resolved")
   @Test
   public void testGetLink() throws Exception {
PdfReader currentReader = new PdfReader(PdfTestBase.RESOURCES_DIR +"getLinkTest1.pdf");
Document document = new Document(PageSize.A4, 0, 0, 0, 0);
PdfWriter writer = PdfWriter.getInstance(document, new
	ByteArrayOutputStream());
document.open();
document.newPage();
List<?> links = currentReader.getLinks(1);
PdfAnnotation.PdfImportedLink link =
	(PdfAnnotation.PdfImportedLink) links.get(0);
writer.addAnnotation(link.createAnnotation(writer));
document.close();
   }
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:16,代碼來源:PdfReaderTest.java

示例8: main

import com.lowagie.text.Document; //導入方法依賴的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();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:39,代碼來源:ActionsTest.java

示例9: testCreateTable

import com.lowagie.text.Document; //導入方法依賴的package包/類
@Test
public void testCreateTable() throws FileNotFoundException,
		DocumentException {
	// create document
	Document document = PdfTestBase.createPdf("testCreateTable.pdf");
	try {
		// new page with a table
		document.open();
		document.newPage();

		PdfPTable table = createPdfTable(2);

		for (int i = 0; i < 10; i++) {
			PdfPCell cell = new PdfPCell();
			cell.setRowspan(2);
			table.addCell(cell);

		}
		table.calculateHeights(true);
		document.add(table);
		document.newPage();

	} finally {
		// close document
		if (document != null)
			document.close();
	}

}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:30,代碼來源:TablePdfTest.java

示例10: main

import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
 * Creates a PDF document with pages in portrait/landscape.
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Document document = new Document(PageSize.A4.rotate());

	// step 2:
	// we create a writer that listens to the document
	// and directs a PDF-stream to a file

	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("LandscapePortrait.pdf"));

	// step 3: we open the document
	document.open();

	// step 4: we add some content
	document.add(new Paragraph(
			"To create a document in landscape format, just make the height smaller than the width. For instance by rotating the PageSize Rectangle: PageSize.A4.rotate()"));
	document.setPageSize(PageSize.A4);
	document.newPage();
	document.add(new Paragraph("This is portrait again"));

	// step 5: we close the document
	document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:29,代碼來源:LandscapePortraitTest.java

示例11: main

import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
 * Creates a PDF document with a certain pagesize
 * 
 * @param args
 *            no arguments needed here
 */
@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("DefaultPageSize.pdf"));

	// step 3: we open the document
	document.open();

	// step 4: we add some paragraphs to the document
	document.add(new Paragraph("The default PageSize is DIN A4."));
	document.setPageSize(PageSize.A3);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A3."));
	document.setPageSize(PageSize.A2);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A2."));
	document.setPageSize(PageSize.A1);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A1."));
	document.setPageSize(PageSize.A0);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A0."));
	document.setPageSize(PageSize.A5);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A5."));
	document.setPageSize(PageSize.A6);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A6."));
	document.setPageSize(PageSize.A7);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A7."));
	document.setPageSize(PageSize.A8);
	document.newPage();
	document.add(new Paragraph("This PageSize is DIN A8."));
	document.setPageSize(PageSize.LETTER);
	document.newPage();
	document.add(new Paragraph("This PageSize is LETTER."));
	document.add(new Paragraph("A lot of other standard PageSizes are available."));

	// step 5: we close the document
	document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:56,代碼來源:DefaultPageSizeTest.java

示例12: main

import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
   
    */
@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("templates.pdf"));

	// step 3: we open the document
	document.open();

	// step 4: we grab the ContentByte and do some stuff with it
	PdfContentByte cb = writer.getDirectContent();

	// we create a PdfTemplate
	PdfTemplate template = cb.createTemplate(500, 200);

	// we add some graphics
	template.moveTo(0, 200);
	template.lineTo(500, 0);
	template.stroke();
	template.setRGBColorStrokeF(255f, 0f, 0f);
	template.circle(250f, 100f, 80f);
	template.stroke();

	// we add some text
	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 100,100 (relative to the template!)");
	template.endText();
	template.sanityCheck();

	// we add the template on different positions
	cb.addTemplate(template, 0, 0);
	cb.addTemplate(template, 0, 1, -1, 0, 500, 200);
	cb.addTemplate(template, .5f, 0, 0, .5f, 100, 400);

	// we go to a new page
	document.newPage();
	cb.addTemplate(template, 0, 400);
	cb.addTemplate(template, 2, 0, 0, 2, -200, 400);
	cb.sanityCheck();

	// step 5: we close the document
	document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:56,代碼來源:TemplatesTest.java

示例13: print

import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
 * Print the table into a PDF file
 */
private void print() {
    Document document = new Document(PageSize.A4.rotate());
    try {
        PdfWriter writer =
        PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "jTable.pdf"));
        
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        
        // Create the graphics as shapes
        cb.saveState();
        Graphics2D g2 = cb.createGraphicsShapes(500, 500);
        // Print the table to the graphics
        Shape oldClip = g2.getClip();
        g2.clipRect(0, 0, 500, 500);
        table.print(g2);
        g2.setClip(oldClip);
        
        g2.dispose();
        cb.restoreState();
        
        document.newPage();
        
        // Create the graphics with pdf fonts
        cb.saveState();
        g2 = cb.createGraphics(500, 500);
        
        // Print the table to the graphics
        oldClip = g2.getClip();
        g2.clipRect(0, 0, 500, 500);
        table.print(g2);
        g2.setClip(oldClip);
        
        g2.dispose();
        cb.restoreState();
        
    } catch (Exception e) {
    	e.printStackTrace();
        System.err.println(e.getMessage());
    }
    
    document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:47,代碼來源:JTable2Pdf.java

示例14: main

import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
 * Generic page event.
 * 
 */
@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 writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Glossary.pdf"));
	GlossaryTest generic = new GlossaryTest();
	writer.setPageEvent(generic);

	// step 3: we open the document
	document.open();
	// step 4:
	String[] f = new String[14];
	f[0] = "Courier";
	f[1] = "Courier Bold";
	f[2] = "Courier Italic";
	f[3] = "Courier Bold Italic";
	f[4] = "Helvetica";
	f[5] = "Helvetica bold";
	f[6] = "Helvetica italic";
	f[7] = "Helvetica bold italic";
	f[8] = "Times New Roman";
	f[9] = "Times New Roman bold";
	f[10] = "Times New Roman italic";
	f[11] = "Times New Roman bold italic";
	f[12] = "Symbol";
	f[13] = "Zapfdingbats";
	Font[] fonts = new Font[14];
	fonts[0] = FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL);
	fonts[1] = FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLD);
	fonts[2] = FontFactory.getFont(FontFactory.COURIER, 12, Font.ITALIC);
	fonts[3] = FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLD | Font.ITALIC);
	fonts[4] = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
	fonts[5] = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
	fonts[6] = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC);
	fonts[7] = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD | Font.ITALIC);
	fonts[8] = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL);
	fonts[9] = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD);
	fonts[10] = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.ITALIC);
	fonts[11] = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD | Font.ITALIC);
	fonts[12] = FontFactory.getFont(FontFactory.SYMBOL, 12, Font.NORMAL);
	fonts[13] = FontFactory.getFont(FontFactory.ZAPFDINGBATS, 12, Font.NORMAL);
	for (int i = 0; i < 14; i++) {
		Chunk chunk = new Chunk("This is font ", fonts[i]);
		Paragraph p = new Paragraph(chunk);
		p.add(new Phrase(new Chunk(f[i], fonts[i]).setGenericTag(f[i])));
		document.add(p);
		if (i % 4 == 3) {
			document.newPage();
		}
	}

	// we add the glossary
	document.newPage();
	for (Iterator<String> i = generic.glossary.keySet().iterator(); i.hasNext();) {
		String key = (String) i.next();
		int page = ((Integer) generic.glossary.get(key)).intValue();
		Paragraph g = new Paragraph(key);
		g.add(" : page ");
		g.add(String.valueOf(page));
		document.add(g);
	}

	// step 5: we close the document
	document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:73,代碼來源:GlossaryTest.java

示例15: main

import com.lowagie.text.Document; //導入方法依賴的package包/類
/**
 * Demonstrates some PageLabel functionality.
 * 
 */
@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("OutlineActions.pdf"));
	PdfWriter.getInstance(remote, PdfTestBase.getOutputStream("remote.pdf"));
	// step 3:
	writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
	document.open();
	remote.open();
	// step 4:
	// we add some content
	document.add(new Paragraph("Outline action example"));
	// we add the outline
	PdfContentByte cb = writer.getDirectContent();
	PdfOutline root = cb.getRootOutline();
	PdfOutline links = new PdfOutline(root, new PdfAction("http://www.lowagie.com/iText/links.html"),
			"Useful links");
	links.setColor(new Color(0x00, 0x80, 0x80));
	links.setStyle(Font.BOLD);
	new PdfOutline(links, new PdfAction("http://www.lowagie.com/iText"), "Bruno's iText site");
	new PdfOutline(links, new PdfAction("http://itextpdf.sourceforge.net/"), "Paulo's iText site");
	new PdfOutline(links, new PdfAction("http://sourceforge.net/projects/itext/"), "iText @ SourceForge");
	PdfOutline other = new PdfOutline(root, new PdfDestination(PdfDestination.FIT), "other actions", false);
	other.setStyle(Font.ITALIC);
	new PdfOutline(other, new PdfAction("remote.pdf", 1), "Go to yhe first page of a remote file");
	new PdfOutline(other, new PdfAction("remote.pdf", "test"), "Go to a local destination in a remote file");
	new PdfOutline(other, PdfAction.javaScript("app.alert('Hello');\r", writer), "Say Hello");

	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();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:47,代碼來源:OutlineActionsTest.java


注:本文中的com.lowagie.text.Document.newPage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。