当前位置: 首页>>代码示例>>Java>>正文


Java PdfWriter.getDirectContent方法代码示例

本文整理汇总了Java中com.lowagie.text.pdf.PdfWriter.getDirectContent方法的典型用法代码示例。如果您正苦于以下问题:Java PdfWriter.getDirectContent方法的具体用法?Java PdfWriter.getDirectContent怎么用?Java PdfWriter.getDirectContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.lowagie.text.pdf.PdfWriter的用法示例。


在下文中一共展示了PdfWriter.getDirectContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: exportVectorGraphics

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
private void exportVectorGraphics(String formatName, File outputFile) throws ImageExportException {
	Component component = printableComponent.getExportComponent();
	int width = component.getWidth();
	int height = component.getHeight();
	try (FileOutputStream fs = new FileOutputStream(outputFile)) {
		switch (formatName) {
			case PDF:
				// create pdf document with slightly increased width and height
				// (otherwise the image gets cut off)
				Document document = new Document(new Rectangle(width + 5, height + 5));
				PdfWriter writer = PdfWriter.getInstance(document, fs);
				document.open();
				PdfContentByte cb = writer.getDirectContent();
				PdfTemplate tp = cb.createTemplate(width, height);
				Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper());
				component.print(g2);
				g2.dispose();
				cb.addTemplate(tp, 0, 0);
				document.close();
				break;
			case SVG:
				exportFreeHep(component, fs, new SVGGraphics2D(fs, new Dimension(width, height)));
				break;
			case EPS:
				exportFreeHep(component, fs, new PSGraphics2D(fs, new Dimension(width, height)));
				break;
			default:
				// cannot happen
				break;
		}
	} catch (Exception e) {
		throw new ImageExportException(I18N.getMessage(I18N.getUserErrorMessagesBundle(),
				"error.image_export.export_failed"), e);
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:36,代码来源:ImageExporter.java

示例2: onEndPage

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
   * Print footer string on each page
   * @param writer
   * @param document
   */
  public void onEndPage(PdfWriter writer, Document document) {
   
  	if(getDateTime() == null) {
  		setDateTime(new Date());
  	}
  	
PdfContentByte cb = writer.getDirectContent();
cb.beginText();
cb.setFontAndSize(getBaseFont(), getFontSize());
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, getDateFormat().format(getDateTime()), 
	    document.left(), 20, 0);
cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, String.valueOf(document.getPageNumber()), 
	    document.right(), 20, 0);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, MESSAGES.pdfCopyright(Constants.getVersion()),
		(document.left() + document.right()) / 2, 20, 0);
cb.endText();
	
      return;
  }
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:25,代码来源:PdfEventHandler.java

示例3: onEndPage

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
 * Adds promo text, date and current page number to each page
 * 
 * @param writer
 * @param document
 */
public void onEndPage(PdfWriter writer, Document document) {
	PdfContentByte cb = writer.getDirectContent();
	cb.saveState();

	float textBase = document.bottom() - getBaseOffset();
	float width = document.getPageSize().getWidth();
	float center = width / 2.0f;

	cb.beginText();
	cb.setFontAndSize(getFont(), getFontSize());

	cb.setTextMatrix(document.left(), textBase);
	cb.showTextAligned(PdfContentByte.ALIGN_CENTER, text, center, textBase, 0);
	cb.endText();
	cb.restoreState();
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:23,代码来源:PromoTextStamper.java

示例4: main

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
 * Writing vertical text.
 */
@Test
public void main() throws Exception {
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	texts[3] = convertCid(texts[0]);
	texts[4] = convertCid(texts[1]);
	texts[5] = convertCid(texts[2]);
	PdfWriter writer = PdfWriter.getInstance(document,PdfTestBase.getOutputStream("vertical.pdf"));
	int idx = 0;
	document.open();
	PdfContentByte cb = writer.getDirectContent();
	for (int j = 0; j < 2; ++j) {
		BaseFont bf = BaseFont.createFont("KozMinPro-Regular", encs[j],	false);
		cb.setRGBColorStroke(255, 0, 0);
		cb.setLineWidth(0);
		float x = 400;
		float y = 700;
		float height = 400;
		float leading = 30;
		int maxLines = 6;
		for (int k = 0; k < maxLines; ++k) {
			cb.moveTo(x - k * leading, y);
			cb.lineTo(x - k * leading, y - height);
		}
		cb.rectangle(x, y, -leading * (maxLines - 1), -height);
		cb.stroke();
		VerticalText vt = new VerticalText(cb);
		vt.setVerticalLayout(x, y, height, maxLines, leading);
		vt.addText(new Chunk(texts[idx++], new Font(bf, 20)));
		vt.addText(new Chunk(texts[idx++], new Font(bf, 20, 0, Color.blue)));
		vt.go();
		vt.setAlignment(Element.ALIGN_RIGHT);
		vt.addText(new Chunk(texts[idx++],	new Font(bf, 20, 0, Color.orange)));
		vt.go();
		document.newPage();
	}
	document.close();

}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:42,代码来源:VerticalTest.java

示例5: main

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
 * Generates an Acroform with a PushButton
 */
@Test
public void main() throws Exception {

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

	// step 2:
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("pushbutton.pdf"));

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

	// step 4:
	PdfFormField pushbutton = PdfFormField.createPushButton(writer);
	PdfContentByte cb = writer.getDirectContent();
	cb.moveTo(0, 0);
	PdfAppearance normal = cb.createAppearance(100, 50);
	normal.setColorFill(Color.GRAY);
	normal.rectangle(5, 5, 90, 40);
	normal.fill();
	PdfAppearance rollover = cb.createAppearance(100, 50);
	rollover.setColorFill(Color.RED);
	rollover.rectangle(5, 5, 90, 40);
	rollover.fill();
	PdfAppearance down = cb.createAppearance(100, 50);
	down.setColorFill(Color.BLUE);
	down.rectangle(5, 5, 90, 40);
	down.fill();
	pushbutton.setFieldName("PushMe");
	pushbutton.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, normal);
	pushbutton.setAppearance(PdfAnnotation.APPEARANCE_ROLLOVER, rollover);
	pushbutton.setAppearance(PdfAnnotation.APPEARANCE_DOWN, down);
	pushbutton.setWidget(new Rectangle(100, 700, 200, 750), PdfAnnotation.HIGHLIGHT_PUSH);
	writer.addAnnotation(pushbutton);

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:43,代码来源:FormPushButtonTest.java

示例6: paintToPDF

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
public void paintToPDF(JEditorPane jep,File file) {
  try {
    jep.setBounds(0, 0, (int) convertToPixels(612 - 58), (int) convertToPixels(792 - 60));

    Document document = new Document();
    FileOutputStream fos = new FileOutputStream(file);
    PdfWriter writer = PdfWriter.getInstance(document, fos);

    document.setPageSize(new com.lowagie.text.Rectangle(612, 792));
    document.open();
    PdfContentByte cb = writer.getDirectContent();

    cb.saveState();
    cb.concatCTM(1, 0, 0, 1, 0, 0);

    DefaultFontMapper mapper = new DefaultFontMapper();
    mapper.insertDirectory("c:/windows/fonts");

    Graphics2D g2 = cb.createGraphics(612, 792, mapper, true, .95f);

    AffineTransform at = new AffineTransform();
    at.translate(convertToPixels(20), convertToPixels(20));
    at.scale(pixelToPoint, pixelToPoint);

    g2.transform(at);

    g2.setColor(Color.WHITE);
    g2.fill(jep.getBounds());

    Rectangle alloc = getVisibleEditorRect(jep);
    jep.getUI().getRootView(jep).paint(g2, alloc);

    g2.setColor(Color.BLACK);
    g2.draw(jep.getBounds());

    g2.dispose();
    cb.restoreState();
    document.close();
    fos.flush();
    fos.close();
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
开发者ID:ksaluja24,项目名称:scratch-bench,代码行数:45,代码来源:MainMenu.java

示例7: saveAsPDF

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
 * @param file The file to save to.
 * @return <code>true</code> on success.
 */
public boolean saveAsPDF(File file) {
    HashSet<Row> changed = expandAllContainers();
    try {
        PrintManager settings = mCharacter.getPageSettings();
        PageFormat format = settings != null ? settings.createPageFormat() : createDefaultPageFormat();
        Paper paper = format.getPaper();
        float width = (float) paper.getWidth();
        float height = (float) paper.getHeight();

        adjustToPageSetupChanges(true);
        setPrinting(true);

        com.lowagie.text.Document pdfDoc = new com.lowagie.text.Document(new com.lowagie.text.Rectangle(width, height));
        try (FileOutputStream out = new FileOutputStream(file)) {
            PdfWriter writer = PdfWriter.getInstance(pdfDoc, out);
            int pageNum = 0;
            PdfContentByte cb;

            pdfDoc.open();
            cb = writer.getDirectContent();
            while (true) {
                PdfTemplate template = cb.createTemplate(width, height);
                Graphics2D g2d = template.createGraphics(width, height, new DefaultFontMapper());

                if (print(g2d, format, pageNum) == NO_SUCH_PAGE) {
                    g2d.dispose();
                    break;
                }
                if (pageNum != 0) {
                    pdfDoc.newPage();
                }
                g2d.setClip(0, 0, (int) width, (int) height);
                print(g2d, format, pageNum++);
                g2d.dispose();
                cb.addTemplate(template, 0, 0);
            }
            pdfDoc.close();
        }
        return true;
    } catch (Exception exception) {
        return false;
    } finally {
        setPrinting(false);
        closeContainers(changed);
    }
}
 
开发者ID:richardwilkes,项目名称:gcs,代码行数:51,代码来源:CharacterSheet.java

示例8: main

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
    * Demonstrates how to group optional content.
    */
@Test
public void main() throws Exception {
       	// step 1
           Document document = new Document(PageSize.A4, 50, 50, 50, 50);
           // step 2
           PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "contentgroups.pdf"));
           writer.setPdfVersion(PdfWriter.VERSION_1_5);
           writer.setViewerPreferences(PdfWriter.PageModeUseOC);
           // step 3
           document.open();
           // step 4
           PdfContentByte cb = writer.getDirectContent();
           Phrase explanation = new Phrase("Layer grouping", new Font(Font.HELVETICA, 20, 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);
           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, 0);
           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();
           cb.sanityCheck();
           
           PdfOCProperties p = writer.getOCProperties();
           PdfArray order = new PdfArray();
           order.add(l1.getRef());
           PdfArray group = new PdfArray();
           group.add(new PdfString("A group of two", PdfObject.TEXT_UNICODE));
           group.add(l2.getRef());
           group.add(l3.getRef());
           order.add(group);
           PdfDictionary d = new PdfDictionary();
           d.put(PdfName.ORDER, order);
           p.put(PdfName.D, d);
           // step 5
           document.close();
   }
 
开发者ID:albfernandez,项目名称:itext2,代码行数:52,代码来源:ContentGroupsTest.java

示例9: main

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
 * Reads the pages of an existing PDF file and puts 2 pages from the
 * existing doc into one of the new doc.
 */
@Test
public void main() throws Exception {
	// we create a reader for a certain document
	PdfReader reader = new PdfReader(PdfTestBase.RESOURCES_DIR + "ChapterSection.pdf");
	// we retrieve the total number of pages
	int n = reader.getNumberOfPages();
	// we retrieve the size of the first page
	Rectangle psize = reader.getPageSize(1);
	float width = psize.getHeight();
	float height = psize.getWidth();

	// step 1: creation of a document-object
	Document document = new Document(new Rectangle(width, height));
	// step 2: we create a writer that listens to the document
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("2on1.pdf"));
	// step 3: we open the document
	document.open();
	// step 4: we add content
	PdfContentByte cb = writer.getDirectContent();
	int i = 0;
	int p = 0;
	while (i < n) {
		document.newPage();
		p++;
		i++;
		PdfImportedPage page1 = writer.getImportedPage(reader, i);
		cb.addTemplate(page1, .5f, 0, 0, .5f, 60, 120);
		if (i < n) {
			i++;
			PdfImportedPage page2 = writer.getImportedPage(reader, i);
			cb.addTemplate(page2, .5f, 0, 0, .5f, width / 2 + 60, 120);
		}
		BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
		cb.beginText();
		cb.setFontAndSize(bf, 14);
		cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "page " + p + " of " + ((n / 2) + (n % 2 > 0 ? 1 : 0)),
				width / 2, 40, 0);
		cb.endText();
	}
	// step 5: we close the document
	document.close();

}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:48,代码来源:TwoOnOneTest.java

示例10: main

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
 * Generates an Acroform with a TextField
 */
@Test
public void main() throws Exception {

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

	// step 2:
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("textfield.pdf"));

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

	// step 4:
	BaseFont helv = BaseFont.createFont("Helvetica", "winansi", false);
	PdfContentByte cb = writer.getDirectContent();
	cb.moveTo(0, 0);
	String text = "Some start text";
	float fontSize = 12;
	Color textColor = new GrayColor(0f);
	PdfFormField field = PdfFormField.createTextField(writer, false, false, 0);
	field.setWidget(new Rectangle(171, 750, 342, 769), PdfAnnotation.HIGHLIGHT_INVERT);
	field.setFlags(PdfAnnotation.FLAGS_PRINT);
	field.setFieldName("ATextField");
	field.setValueAsString(text);
	field.setDefaultValueAsString(text);
	field.setBorderStyle(new PdfBorderDictionary(2, PdfBorderDictionary.STYLE_SOLID));
	field.setPage();
	PdfAppearance tp = cb.createAppearance(171, 19);
	PdfAppearance da = (PdfAppearance) tp.getDuplicate();
	da.setFontAndSize(helv, fontSize);
	da.setColorFill(textColor);
	field.setDefaultAppearanceString(da);
	tp.beginVariableText();
	tp.saveState();
	tp.rectangle(2, 2, 167, 15);
	tp.clip();
	tp.newPath();
	tp.beginText();
	tp.setFontAndSize(helv, fontSize);
	tp.setColorFill(textColor);
	tp.setTextMatrix(4, 5);
	tp.showText(text);
	tp.endText();
	tp.restoreState();
	tp.endVariableText();
	field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
	writer.addAnnotation(field);

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:55,代码来源:FormTextFieldTest.java

示例11: gravaPdf

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
public boolean gravaPdf(String sArquivo) {
	boolean bRetorno = false;
	com.lowagie.text.Document document = new com.lowagie.text.Document();

	try {

		// step 2:
		// we create a writer that listens to the document
		// and directs a PDF-stream to a file
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(sArquivo));

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

		// step 4: we grab the ContentByte and do some stuff with it

		// we create a fontMapper and read all the fonts in the font
		// directory
		// DefaultFontMapper mapper = new DefaultFontMapper();
		// mapper.insertDirectory("c:\\windows\\fonts");
		// we create a template and a Graphics2D object that corresponds
		// with it
		int wt = 0;
		int ht = 0;
		// int wg = 0;
		// int hg = 0;
		PdfContentByte cb = writer.getDirectContent();
		PdfTemplate tp = null;
		Graphics2D g2 = null;
		PrinterJob printJob = PrinterJob.getPrinterJob();
		Paper paper = printJob.defaultPage().getPaper();
		PaginaPad pf = new PaginaPad(paper);
		wt = ( int ) ( pf.getWidth() );
		ht = ( int ) ( pf.getHeight() );
		if (( iMXPdf != -1 ) && ( iMYPdf != -1 )) {
			paper.setImageableArea(iMXPdf, iMYPdf, wt, ht);
			pf = new PaginaPad(paper);
		}
		// wg = (int)(pf.getImageableWidth());
		// hg = (int)(pf.getImageableHeight());
		// System.out.println("wt:"+wt+"  ht:"+ht+"  wg:"+wg+"  hg:"+hg);
		// PrintRequestAttributeSet aset = Funcoes.getImpAtrib();
		// w = printJob.

		for (int i = 0; i < getNumPags(); i++) {
			if (i > 0) {
				document.newPage();
			}
			tp = cb.createTemplate(wt, ht);
			g2 = tp.createGraphics(wt, ht);
			try {
				prepPagina(g2, pf, i);
			}
			catch (PrinterException pe) {
				Funcoes.mensagemErro(null, "Erro criando graphics: " + pe.getMessage());
			}
			tp.setWidth(wt);
			tp.setHeight(ht);
			g2.dispose();
			cb.addTemplate(tp, 0, 0);

		}

	}
	catch (DocumentException de) {
		System.err.println(de.getMessage());
	}
	catch (IOException ioe) {
		System.err.println(ioe.getMessage());
	}

	// step 5: we close the document
	document.close();

	return bRetorno;
}
 
开发者ID:cams7,项目名称:erp,代码行数:77,代码来源:ImprimeLayout.java

示例12: main

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
 * Demonstrates the use of nested layers
 * 
 * @param args
 *            no arguments needed
 */
@Test
public void main() throws Exception {
	// step 1
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	// step 2
	PdfWriter writer = PdfWriter.getInstance(document,
			PdfTestBase.getOutputStream("nestedlayers.pdf"));
	writer.setPdfVersion(PdfWriter.VERSION_1_5);
	writer.setViewerPreferences(PdfWriter.PageModeUseOC);
	// step 3
	document.open();
	// step 4
	PdfContentByte cb = writer.getDirectContent();
	Phrase explanation = new Phrase("Layer nesting", new Font(
			Font.HELVETICA, 20, Font.BOLD, Color.red));
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50,
			650, 0);
	PdfLayer l1 = new PdfLayer("Layer 1", writer);
	PdfLayer l23 = new PdfLayer("Top Layer 2 3", writer);
	PdfLayer l2 = new PdfLayer("Layer 2", writer);
	PdfLayer l3 = new PdfLayer("Layer 3", writer);
	Phrase p1 = new Phrase("Text in layer 1");
	Phrase p2 = new Phrase("Text in layer 2");
	Phrase p3 = new Phrase("Text in layer 3");
	cb.beginLayer(l1);
	ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0);
	cb.endLayer();
	cb.beginLayer(l23);
	cb.beginLayer(l2);
	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();
	cb.endLayer();
	cb.sanityCheck();

	PdfOCProperties p = writer.getOCProperties();
	PdfArray order = new PdfArray();
	order.add(l1.getRef());
	order.add(l23.getRef());
	PdfArray group = new PdfArray();
	group.add(l2.getRef());
	group.add(l3.getRef());
	order.add(group);
	PdfDictionary d = new PdfDictionary();
	d.put(PdfName.ORDER, order);
	p.put(PdfName.D, d);
	// step 5
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:58,代码来源:NestedLayersTest.java

示例13: main

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
    * Draws some concentric circles.
    */
@Test
public void main() throws Exception {
       
       
       // step 1: creation of a document-object
       Document document = new Document();
       
       try {
           
           // step 2: creation of the writer
           PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "circles.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();

           cb.circle(250.0f, 500.0f, 200.0f);
           cb.circle(250.0f, 500.0f, 150.0f);
           cb.stroke();
           cb.setRGBColorFill(0xFF, 0x00, 0x00);
           cb.circle(250.0f, 500.0f, 100.0f);
           cb.fillStroke();
           cb.setRGBColorFill(0xFF, 0xFF, 0xFF);
           cb.circle(250.0f, 500.0f, 50.0f);
           cb.fill();
           
           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,代码行数:44,代码来源:CirclesTest.java

示例14: main

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
 * Demonstrates the Transparency functionality.
 */
@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 a writer
	PdfWriter writer = PdfWriter.getInstance(document,PdfTestBase.getOutputStream("softmask.pdf"));
	// step 3: we open the document
	document.open();
	// step 4: content
	PdfContentByte cb = writer.getDirectContent();
	String text = "text ";
	text += text;
	text += text;
	text += text;
	text += text;
	text += text;
	text += text;
	text += text;
	text += text;
	document.add(new Paragraph(text));
	Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR	+ "otsoe.jpg");
	img.setAbsolutePosition(100, 550);
	byte gradient[] = new byte[256];
	for (int k = 0; k < 256; ++k) {
		gradient[k] = (byte) k;
	}
	Image smask = Image.getInstance(256, 1, 1, 8, gradient);
	smask.makeMask();
	img.setImageMask(smask);
	cb.addImage(img);
	cb.sanityCheck();
	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:38,代码来源:SoftMaskTest.java

示例15: main

import com.lowagie.text.pdf.PdfWriter; //导入方法依赖的package包/类
/**
 * Demonstrating the use of ColumnText
 */
@Test
public void main() throws Exception {

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

	// step 2: creation of the writer
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("column.pdf"));

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

	// step 4:

	// we create some content
	BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
	Font font = new Font(bf, 11, Font.NORMAL);

	Phrase unicodes = new Phrase(15, "UNI\n", font);
	Phrase characters = new Phrase(15, "\n", font);
	Phrase names = new Phrase(15, "NAME\n", font);

	for (int i = 0; i < 27; i++) {
		unicodes.add(uni[i] + "\n");
		characters.add(code[i] + "\n");
		names.add(name[i] + "\n");
	}

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

	ColumnText ct = new ColumnText(cb);
	ct.setSimpleColumn(unicodes, 60, 300, 100, 300 + 28 * 15, 15, Element.ALIGN_CENTER);
	ct.go();
	cb.rectangle(103, 295, 52, 8 + 28 * 15);
	cb.stroke();
	ct.setSimpleColumn(characters, 105, 300, 150, 300 + 28 * 15, 15, Element.ALIGN_RIGHT);
	ct.go();
	ct.setSimpleColumn(names, 160, 300, 500, 300 + 28 * 15, 15, Element.ALIGN_LEFT);
	ct.go();

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:48,代码来源:ColumnTest.java


注:本文中的com.lowagie.text.pdf.PdfWriter.getDirectContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。