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


Java PageSize.A4屬性代碼示例

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


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

示例1: createDoc

public void createDoc() throws FileNotFoundException{
	 /** 創建Document對象(word文檔)  */
       Rectangle rectPageSize = new Rectangle(PageSize.A4);
       rectPageSize = rectPageSize.rotate();
       // 創建word文檔,並設置紙張的大小
       doc = new Document(PageSize.A4);
       file=new File(path+docFileName);
       fileOutputStream=new FileOutputStream(file);
       /** 建立一個書寫器與document對象關聯,通過書寫器可以將文檔寫入到輸出流中 */
       RtfWriter2.getInstance(doc, fileOutputStream );
       doc.open();
       //設置頁邊距,上、下25.4毫米,即為72f,左、右31.8毫米,即為90f  
       doc.setMargins(90f, 90f, 72f, 72f);
       //設置標題字體樣式,粗體、二號、華文中宋  
       tfont  = DocStyleUtils.setFontStyle("華文中宋", 22f, Font.BOLD);  
       //設置正文內容的字體樣式,常規、三號、仿宋_GB2312  
       bfont = DocStyleUtils.setFontStyle("仿宋_GB2312", 16f, Font.NORMAL);
}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:18,代碼來源:DocExportUtil.java

示例2: pdfTableForInstructionalOfferings

public void pdfTableForInstructionalOfferings(
  		OutputStream out,
          ClassAssignmentProxy classAssignment,
          ExamAssignmentProxy examAssignment,
          InstructionalOfferingListForm form, 
          String[] subjectAreaIds, 
          SessionContext context,
          boolean displayHeader,
          boolean allCoursesAreGiven) throws Exception{
  	
  	setVisibleColumns(form);
  	
  	iDocument = new Document(PageSize.A4, 30f, 30f, 30f, 30f); 
iWriter = PdfEventHandler.initFooter(iDocument, out);

  	for (String subjectAreaId: subjectAreaIds) {
      	pdfTableForInstructionalOfferings(out, classAssignment, examAssignment,
      			form.getInstructionalOfferings(Long.valueOf(subjectAreaId)), 
      			Long.valueOf(subjectAreaId),
      			context,
      			displayHeader, allCoursesAreGiven,
      			new ClassCourseComparator(form.getSortBy(), classAssignment, false));
  	}
 	
iDocument.close();
  }
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:26,代碼來源:PdfInstructionalOfferingTableBuilder.java

示例3: main

/**
 * Adds some annotated images to a PDF file.
 */
@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("annotated_images.pdf"));
	// step 3: we open the document
	document.open();
	// step 4: we add some content
	Image jpeg = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
	jpeg.setAnnotation(new Annotation("picture", "This is my dog", 0, 0, 0, 0));
	jpeg.setAbsolutePosition(100f, 550f);
	document.add(jpeg);
	Image wmf = Image.getInstance(PdfTestBase.RESOURCES_DIR + "iText.wmf");
	wmf.setAnnotation(new Annotation(0, 0, 0, 0, "http://www.lowagie.com/iText"));
	wmf.setAbsolutePosition(100f, 200f);
	document.add(wmf);

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

示例4: main

/**
 * 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,代碼行數:23,代碼來源:SpaceWordRatioTest.java

示例5: generate

public void generate(OutputStream os) throws Exception
{
	document = new Document(PageSize.A4, 36, 36, 36, 50);
	writer = PdfWriter.getInstance(document,os);		
	writer.setEncryption(null, null, PdfWriter.AllowCopy | PdfWriter.AllowPrinting, PdfWriter.STRENGTH40BITS);
	writer.setPageEvent(new EndPage(this.getCabecera(),this.getPie(),this.getBarcode(),this.isPaginar()));		
	document.open();				
	//Pintar la cabecera que proceda: No pitar, cabecera normal o cabecera peque�a
	if(!noCabecera) {
		if (tipocabecera.equals(TYPE_HEAD_SMALL)) writeCabecera2();
		else writeCabecera();
	}

	
	for(int i=0; i<secciones.size(); i++)
	{
		Seccion obj = (Seccion)secciones.get(i);
		obj.write(this);
	}		
	
	document.close();
}
 
開發者ID:GovernIB,項目名稱:sistra,代碼行數:22,代碼來源:PDFDocument.java

示例6: generateReportFile

protected MemoryFileDTO generateReportFile(BaseReportDto reportData, String fileName) {
    Document document = new Document(PageSize.A4);
    MemoryFileDTO report = new MemoryFileDTO();
    report.setFileName(fileName);
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(this);
        writer.setFullCompression();
        document.open();
        generateReportBody(document, reportData);
        writer.flush();
        document.close();
        report.setFileData(baos.toByteArray());
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return null;
    } 
    return report;
}
 
開發者ID:Biblivre,項目名稱:Biblivre-3,代碼行數:20,代碼來源:BaseBiblivreReport.java

示例7: main

/**
 * Space Word Ratio.
 * 
 * @param args
 *            no arguments needed
 */
public static void main(String[] args) {
	System.out.println("Space Word Ratio");
	// step 1
	Document document = new Document(PageSize.A4, 50, 350, 50, 50);
	try {
		// step 2
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "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);
	} catch (Exception de) {
		de.printStackTrace();
	}
	// step 5
	document.close();
}
 
開發者ID:fc-dream,項目名稱:PDFTestForAndroid,代碼行數:29,代碼來源:SpaceWordRatio.java

示例8: main

/**
 * Demonstrates the use of PageEvents.
 * 
 * @param args
 *            no arguments needed
 */
public static void main(String[] args) {
	Document document = new Document(PageSize.A4, 50, 50, 70, 70);
	try {
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "endpage.pdf"));
		writer.setPageEvent(new EndPage());
		document.open();
		String text = "Lots of text. ";
		for (int k = 0; k < 10; ++k)
			text += text;
		document.add(new Paragraph(text));
		document.close();
	} catch (Exception de) {
		de.printStackTrace();
	}
}
 
開發者ID:fc-dream,項目名稱:PDFTestForAndroid,代碼行數:21,代碼來源:EndPage.java

示例9: main

/**
 * Generates a document with a header containing Page x of y and with a
 * Watermark on every page.
 * 
 * @param args
 *            no arguments needed
 */
public static void main(String args[]) {
	try {
		// 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, new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + java.io.File.separator + "droidtext" + java.io.File.separator + "pageNumbersWatermark.pdf"));
		// step 3: initialisations + opening the document
		writer.setPageEvent(new PageNumbersWatermark());
		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();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:fc-dream,項目名稱:PDFTestForAndroid,代碼行數:29,代碼來源:PageNumbersWatermark.java

示例10: pdfTableForInstructionalOffering

public void pdfTableForInstructionalOffering(
 		OutputStream out,
 		ClassAssignmentProxy classAssignment, 
 		ExamAssignmentProxy examAssignment,
         Long instructionalOfferingId, 
         SessionContext context,
         Comparator classComparator) throws Exception{
 	
 	if (instructionalOfferingId != null && context != null){
      InstructionalOfferingDAO idao = new InstructionalOfferingDAO();
      InstructionalOffering io = idao.get(instructionalOfferingId);
      Long subjectAreaId = io.getControllingCourseOffering().getSubjectArea().getUniqueId();
      
      // Get Configuration
      TreeSet ts = new TreeSet();
      ts.add(io);
      WebInstructionalOfferingTableBuilder iotbl = new WebInstructionalOfferingTableBuilder();
      iotbl.setDisplayDistributionPrefs(false);
      setVisibleColumns(COLUMNS);
      
  	iDocument = new Document(PageSize.A4, 30f, 30f, 30f, 30f); 
iWriter = PdfEventHandler.initFooter(iDocument, out);

   pdfTableForInstructionalOfferings(out,
	        classAssignment, examAssignment,
	        ts, subjectAreaId, context, false, false, classComparator);
   
   iDocument.close();
 	}
 }
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:30,代碼來源:PdfInstructionalOfferingTableBuilder.java

示例11: main

/**
    * Add an image using different transformation matrices.
    */
@Test
public void main() throws Exception {
       Document.compress = false;
       // step 1: creation of a document-object
       Document document = new Document(PageSize.A4);
       
       try {
           // step 2: creation of the writer
           PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "transformimage.pdf"));
           
           // step 3: we open the document
           document.open();
           
           // step 4:
           PdfContentByte cb = writer.getDirectContent();
           Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR + "hitchcock.png");
           cb.addImage(img, 271, -50, -30, 550, 100, 100);
           cb.sanityCheck();
  
       }
       catch(DocumentException de) {
           System.err.println(de.getMessage());
       }
       catch(IOException ioe) {
           System.err.println(ioe.getMessage());
       }
       
       // step 5: we close the document
       document.close();
   }
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:33,代碼來源:TransformImageTest.java

示例12: main

/**
 * General example using cell events.
 * 
 */
@Test
public void main() throws Exception {
	// step1
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	// step2
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("CellEvents.pdf"));
	// step3
	document.open();
	// step4
	CellEventsTest event = new CellEventsTest();
	Image im = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
	im.setRotationDegrees(30);
	PdfPTable table = new PdfPTable(4);
	table.addCell("text 1");
	PdfPCell cell = new PdfPCell(im, true);
	cell.setCellEvent(event);
	table.addCell(cell);
	table.addCell("text 3");
	im.setRotationDegrees(0);
	table.addCell(im);
	table.setTotalWidth(300);
	PdfContentByte cb = writer.getDirectContent();
	table.writeSelectedRows(0, -1, 50, 600, cb);
	table.setHeaderRows(3);
	document.add(table);

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

示例13: main

/**
 * Demonstrates the use of layers.
 * 
 * @param args
 *            no arguments needed
 */
@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: creation of the writer
	PdfWriter writer = PdfWriter.getInstance(document,
			PdfTestBase.getOutputStream("optionalcontent.pdf"));
	writer.setPdfVersion(PdfWriter.VERSION_1_5);
	writer.setViewerPreferences(PdfWriter.PageModeUseOC);
	// step 3: opening the document
	document.open();
	// step 4: content
	PdfContentByte cb = writer.getDirectContent();
	Phrase explanation = new Phrase(
			"Automatic layers, form fields, images, templates and actions",
			new Font(Font.HELVETICA, 18, Font.BOLD, Color.red));
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50,
			650, 0);
	PdfLayer l1 = new PdfLayer("Layer 1", writer);
	PdfLayer l2 = new PdfLayer("Layer 2", writer);
	PdfLayer l3 = new PdfLayer("Layer 3", writer);
	PdfLayer l4 = new PdfLayer("Form and XObject Layer", writer);
	PdfLayerMembership m1 = new PdfLayerMembership(writer);
	m1.addMember(l2);
	m1.addMember(l3);
	Phrase p1 = new Phrase("Text in layer 1");
	Phrase p2 = new Phrase("Text in layer 2 or layer 3");
	Phrase p3 = new Phrase("Text in layer 3");
	cb.beginLayer(l1);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0f);
	cb.endLayer();
	cb.beginLayer(m1);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
	cb.endLayer();
	cb.beginLayer(l3);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
	cb.endLayer();
	TextField ff = new TextField(writer, new Rectangle(200, 600, 300, 620),
			"field1");
	ff.setBorderColor(Color.blue);
	ff.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
	ff.setBorderWidth(TextField.BORDER_WIDTH_THIN);
	ff.setText("I'm a form field");
	PdfFormField form = ff.getTextField();
	form.setLayer(l4);
	writer.addAnnotation(form);
	Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR
			+ "pngnow.png");
	img.setLayer(l4);
	img.setAbsolutePosition(200, 550);
	cb.addImage(img);
	PdfTemplate tp = cb.createTemplate(100, 20);
	Phrase pt = new Phrase("I'm a template", new Font(Font.HELVETICA, 12,
			Font.NORMAL, Color.magenta));
	ColumnText.showTextAligned(tp, Element.ALIGN_LEFT, pt, 0, 0, 0);
	tp.setLayer(l4);
	tp.setBoundingBox(new Rectangle(0, -10, 100, 20));
	cb.addTemplate(tp, 200, 500);
	ArrayList<Object> state = new ArrayList<Object>();
	state.add("toggle");
	state.add(l1);
	state.add(l2);
	state.add(l3);
	state.add(l4);
	PdfAction action = PdfAction.setOCGstate(state, true);
	Chunk ck = new Chunk("Click here to toggle the layers", new Font(
			Font.HELVETICA, 18, Font.NORMAL, Color.yellow)).setBackground(
			Color.blue).setAction(action);
	ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase(ck),
			250, 400, 0);
	cb.sanityCheck();

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

示例14: main

/**
 * 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();

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

示例15: main

/**
 * Shading example.
 */
@Test
public void main() throws Exception {
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	PdfWriter writer = PdfWriter.getInstance(document,
			PdfTestBase.getOutputStream("shading_pattern.pdf"));
	document.open();

	PdfShading shading = PdfShading.simpleAxial(writer, 100, 100, 400, 100,
			Color.red, Color.cyan);
	PdfShadingPattern shadingPattern = new PdfShadingPattern(shading);
	PdfContentByte cb = writer.getDirectContent();
	BaseFont bf = BaseFont.createFont(BaseFont.TIMES_BOLD,
			BaseFont.WINANSI, false);
	cb.setShadingFill(shadingPattern);
	cb.beginText();
	cb.setTextMatrix(100, 100);
	cb.setFontAndSize(bf, 40);
	cb.showText("Look at this text!");
	cb.endText();
	PdfShading shadingR = PdfShading.simpleRadial(writer, 200, 500, 50,
			300, 500, 100, new Color(255, 247, 148), new Color(247, 138,
					107), false, false);
	cb.paintShading(shadingR);
	cb.sanityCheck();
	document.close();

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


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