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


Java PdfContentByte類代碼示例

本文整理匯總了Java中com.itextpdf.text.pdf.PdfContentByte的典型用法代碼示例。如果您正苦於以下問題:Java PdfContentByte類的具體用法?Java PdfContentByte怎麽用?Java PdfContentByte使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: buildPdfDocument

import com.itextpdf.text.pdf.PdfContentByte; //導入依賴的package包/類
public void buildPdfDocument(OutputStream toWrite, final String name, final int treeCount, String[] codeFragments, String imagePath) throws Exception {
    // create pdf
    final Document doc = new Document();
    final PdfWriter pdfWriter = PdfWriter.getInstance(doc, toWrite);
    pdfWriter.setEncryption(null, null, PdfWriter.ALLOW_DEGRADED_PRINTING | PdfWriter.ALLOW_PRINTING, PdfWriter.STANDARD_ENCRYPTION_128);
    _imagePath = imagePath;

    doc.open();

    PdfContentByte cb = pdfWriter.getDirectContent();

    PdfHelper.createHeaderBlock(cb,1,1);
    PdfHelper.createCircleAndText(cb, "Gutschein", 298f, 705f, 75, textFontForCircle, 0x7F, 0xAD, 0x09);

    createBlueBlock(cb, treeCount);
    createGreyBlock(cb, codeFragments);

    pdfHelper.addLogo(cb, _imagePath, 262f, 35f);
    doc.close();
}
 
開發者ID:Dica-Developer,項目名稱:weplantaforest,代碼行數:21,代碼來源:PdfGiftView.java

示例2: build

import com.itextpdf.text.pdf.PdfContentByte; //導入依賴的package包/類
/**
 * Update NDA file with visitor name and visitor signature.
 * 
 * @param destFile 
 * @param signatureImage signature file
 * @param visitorName
 * @return File
 */
public static File build(Path destFile, File signatureImage, String visitorName) {
	try {
		PdfReader pdfReader = new PdfReader(ndaUrl);
		PdfStamper pdfStamper = new PdfStamper(pdfReader,
				new FileOutputStream(destFile.toString()));
		Image image = createNDAImage(signatureImage, 0, 0);
		PdfContentByte over = pdfStamper.getOverContent(5);
		over.addImage(image);
		PdfContentByte pdfContentByte = pdfStamper.getOverContent(5);
		pdfContentByte.beginText();
		pdfContentByte.setFontAndSize(BaseFont.createFont
				(BaseFont.HELVETICA, 
						BaseFont.CP1257, 
						BaseFont.EMBEDDED
						)
				, 10); 
		pdfContentByte.setTextMatrix(112, 428); 
		pdfContentByte.showText(visitorName);
		pdfContentByte.setTextMatrix(89, 406);
		pdfContentByte.showText(new SimpleDateFormat("E, dd MMM yyyy").format(new Date()));
		pdfContentByte.endText();
		pdfStamper.close();
		return destFile.toFile();
	} catch (IOException | DocumentException | NumberFormatException e) {
		logger.error("Exception while generating NDA file. ",e);
		return null;
	}
}
 
開發者ID:Zymr,項目名稱:visitormanagement,代碼行數:37,代碼來源:NdaBuilder.java

示例3: print

import com.itextpdf.text.pdf.PdfContentByte; //導入依賴的package包/類
public void print(String plot_pdf) {
	try {
		float width = jframe.getSize().width,
				height = jframe.getSize().height;
		Document document = new Document(new Rectangle(width, height));
		PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(plot_pdf));
		document.open();
		PdfContentByte canvas = writer.getDirectContent();
		PdfTemplate template = canvas.createTemplate(width, height);
		Graphics2D g2d = new PdfGraphics2D(template, width, height);
		jframe.paint(g2d);
		g2d.dispose();
		canvas.addTemplate(template, 0, 0);
		document.close();
	} catch (FileNotFoundException | DocumentException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
開發者ID:c-zhou,項目名稱:polyGembler,代碼行數:20,代碼來源:JfreeChart.java

示例4: writeChartToPDF

import com.itextpdf.text.pdf.PdfContentByte; //導入依賴的package包/類
/**
 * Save the chart as pdf.
 *
 * @param chart
 *            chart that should be saved
 * @param fileName
 *            file name under which chart should be saved
 */
public static void writeChartToPDF(final JFreeChart chart,
		final String fileName) {
	PdfWriter writer = null;

	com.itextpdf.text.Document document = new com.itextpdf.text.Document(
			PageSize.A4);
	final int width = (int) PageSize.A4.getWidth();
	final int height = (int) PageSize.A4.getHeight();

	try {
		writer = PdfWriter.getInstance(document, new FileOutputStream(
				fileName + ".pdf"));
		document.open();
		PdfContentByte contentByte = writer.getDirectContent();
		PdfTemplate template = contentByte.createTemplate(width, height);
		Graphics2D graphics2d = template.createGraphics(width, height,
				new DefaultFontMapper());
		Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width,
				height);

		chart.draw(graphics2d, rectangle2d);

		graphics2d.dispose();
		contentByte.addTemplate(template, 0, 0);

	} catch (Exception e) {
		e.printStackTrace();
	}
	document.close();
}
 
開發者ID:adamIqbal,項目名稱:Health,代碼行數:39,代碼來源:Histogram.java

示例5: testShowTextAlignedVsSimpleColumnTopAlignment

import com.itextpdf.text.pdf.PdfContentByte; //導入依賴的package包/類
/**
 * <a href="http://stackoverflow.com/questions/32162759/columntext-showtextaligned-vs-columntext-setsimplecolumn-top-alignment">
 * ColumnText.ShowTextAligned vs ColumnText.SetSimpleColumn Top Alignment
 * </a>
 * <p>
 * Indeed, the coordinates do not line up. The y coordinate of 
 * {@link ColumnText#showTextAligned(PdfContentByte, int, Phrase, float, float, float)}
 * denotes the baseline while {@link ColumnText#setSimpleColumn(Rectangle)} surrounds
 * the text to come.
 * </p>
 */
@Test
public void testShowTextAlignedVsSimpleColumnTopAlignment() throws DocumentException, IOException
{
    Document document = new Document(PageSize.A4);

    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "ColumnTextTopAligned.pdf")));
    document.open();

    Font fontQouteItems = new Font(BaseFont.createFont(), 12);
    PdfContentByte canvas = writer.getDirectContent();

    // Item Number
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("36222-0", fontQouteItems), 60, 450, 0);

    // Estimated Qty
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("47", fontQouteItems), 143, 450, 0);

    // Item Description
    ColumnText ct = new ColumnText(canvas); // Uses a simple column box to provide proper text wrapping
    ct.setSimpleColumn(new Rectangle(193, 070, 390, 450));
    ct.setText(new Phrase("In-Situ : Poly Cable - 100'\nPoly vented rugged black gable 100ft\nThis is an additional description. It can wrap an extra line if it needs to so this text is long.", fontQouteItems));
    ct.go();

    document.close();
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:37,代碼來源:UseColumnText.java

示例6: createLawTable

import com.itextpdf.text.pdf.PdfContentByte; //導入依賴的package包/類
private PdfPTable createLawTable(PdfContentByte cb) throws DocumentException {
    PdfPTable table = new PdfPTable(1);
    float[] rows = { 445f };
    table.setTotalWidth(rows);
    table.getDefaultCell()
         .setBorder(Rectangle.NO_BORDER);
    table.getDefaultCell()
         .setLeading(8f, 0);

    table.addCell(new Phrase(new Chunk("Es handelt sich nicht um den Verzicht auf Erstattung von Aufwendungen.", textFontLawText)));
    table.addCell(new Phrase(new Chunk("Die Gesellschaft ist wegen Förderung (begünstigter Zweck: Umweltschutz (§52 (2) S. 1 Nr.(n) 8 AO)) durch", textFontLawText)));
    table.addCell(new Phrase(new Chunk("Bescheinigung des Finanzamt Halle (Saale)-Nord, StNr. 110/108/91169, vom 19.11.2008 ab 01.01.2009", textFontLawText)));
    table.addCell(new Phrase(new Chunk("als gemeinnützig anerkannt. Letzter Freistellungsbescheid datiert auf den 20.06.2013.", textFontLawText)));
    table.addCell(new Phrase(new Chunk("Es wird bestätigt, dass die Zuwendung nur zur Förderung des Umweltschutzes verwendet wird.", textFontLawText)));

    PdfPCell emptyCell = new PdfPCell();
    emptyCell.setBorder(Rectangle.BOTTOM);
    emptyCell.setFixedHeight(15f);
    table.addCell(emptyCell);

    return table;
}
 
開發者ID:Dica-Developer,項目名稱:weplantaforest,代碼行數:23,代碼來源:PdfReceiptView.java

示例7: generate128

import com.itextpdf.text.pdf.PdfContentByte; //導入依賴的package包/類
private static Image generate128(PdfContentByte cb, String sku){
	Barcode128 code128 = new Barcode128();
	code128.setCodeType(Barcode128.CODE_A);
	code128.setGuardBars(true);
    code128.setCode(sku);
    code128.setSize(7);
    code128.setBaseline(6f);
    code128.setBarHeight(27f);
    code128.setX(.70f);
    
    return code128.createImageWithBarcode(cb, null, null);
}
 
開發者ID:VDuda,項目名稱:SyncRunner-Pub,代碼行數:13,代碼來源:Barcodes.java

示例8: onEndPage

import com.itextpdf.text.pdf.PdfContentByte; //導入依賴的package包/類
@Override
public void onEndPage(final PdfWriter writer,
                      final Document document) {
  final PdfContentByte cb = writer.getDirectContent();
  cb.saveState();

  // compose the footer
  final String text = "Page "
      + writer.getPageNumber() + " of ";
  final float textSize = _headerFooterFont.getWidthPoint(text, 12);
  final float textBase = document.bottom() - 20;
  cb.beginText();
  cb.setFontAndSize(_headerFooterFont, 12);

  final float adjust = _headerFooterFont.getWidthPoint("0", 12);
  cb.setTextMatrix(document.right()
      - textSize - adjust, textBase);
  cb.showText(text);
  cb.endText();
  cb.addTemplate(_tpl, document.right()
      - adjust, textBase);

  cb.restoreState();
}
 
開發者ID:jpschewe,項目名稱:fll-sw,代碼行數:25,代碼來源:SimpleFooterHandler.java

示例9: getImageByFile

import com.itextpdf.text.pdf.PdfContentByte; //導入依賴的package包/類
public ImageInstance getImageByFile( PdfContentByte cb , File file ) throws IOException, BadElementException{
	Image image = null;
	ImageInstance instance = null;
	if( file.getName().toLowerCase().endsWith( ".pdf")){	
		PdfReader reader = new PdfReader( file.getAbsolutePath() );
		PdfImportedPage p = cb.getPdfWriter().getImportedPage(reader, 1);
		image = Image.getInstance(p);
		instance = new ImageInstance(image, reader);
	}else{
		image = Image.getInstance( file.getAbsolutePath() );
		instance = new ImageInstance(image, null);
	}
	
	instances.add(instance);
	

	return instance;
}
 
開發者ID:Billes,項目名稱:pdf-renderer,代碼行數:19,代碼來源:ImageFactory.java

示例10: createRoundRectangle

import com.itextpdf.text.pdf.PdfContentByte; //導入依賴的package包/類
public void createRoundRectangle(PdfContentByte cb, Block block ){
	PdfDocument request =  getPdfDocument(block);
	float[] positions = getBoundsInPs(block);
	float[] mmPositions = getBoundsInMMIncludeCutmark(block);
	PdfTemplate tp = cb.createTemplate(positions[2],positions[3]);

	tp.roundRectangle(
			0, 
			0, 
			positions[2], 
			positions[3], 
			SizeFactory.millimetersToPostscriptPoints( block.getRadius() )
	);
	
	
	
	
	// because pdf i calculated from bottom up
	cb.addTemplate(
			tp, 
			positions[0], 
			SizeFactory.millimetersToPostscriptPoints( request.getSize()[1] - ( mmPositions[1] + mmPositions[3]))
	);

}
 
開發者ID:Billes,項目名稱:pdf-renderer,代碼行數:26,代碼來源:BlockFactory.java

示例11: onRender

import com.itextpdf.text.pdf.PdfContentByte; //導入依賴的package包/類
@Override
public void onRender(PdfContentByte cb) throws PdfRenderException {
	
	Integer[] pageSizes = getPage().getPdfDocument().getSize();
	float[] pos = getPosition();
	float[] moveTo = getMoveTo();
	cb.setLineWidth( getThickness() );
	cb.setColorStroke(  getBaseColor() );		
	float y1 = pageSizes[1] + SizeFactory.CUT_MARK - pos[1]; // seams strange but pdf starts bottom and up.
	float y2 = pageSizes[1] + SizeFactory.CUT_MARK - moveTo[1];
	// x , y. y is backward in pdf so start pos is the entire page height
	cb.moveTo( SizeFactory.millimetersToPostscriptPoints( pos[0] + SizeFactory.CUT_MARK ) , SizeFactory.millimetersToPostscriptPoints( y1 ) );
	cb.lineTo( SizeFactory.millimetersToPostscriptPoints(  moveTo[0] + SizeFactory.CUT_MARK ) , SizeFactory.millimetersToPostscriptPoints( y2 ) );
	cb.stroke();
	
}
 
開發者ID:Billes,項目名稱:pdf-renderer,代碼行數:17,代碼來源:Line.java

示例12: closePassedStream

import com.itextpdf.text.pdf.PdfContentByte; //導入依賴的package包/類
/**
 * The <code>closePassedStream</code> method closes the stream passed.
 * 
 * @param reader {@link PdfReader}
 * @param document {@link Document}
 * @param contentByte {@link PdfContentByte}
 * @param writer {@link PdfWriter}
 * @param fileInputStream {@link FileInputStream}
 * @param fileOutputStream {@link FileOutputStream}
 * @throws IOException {@link} if unable to close input or output stream
 */
private static void closePassedStream(final PdfReader reader, final Document document,
		final PdfContentByte contentByte, final PdfWriter writer,
		final FileInputStream fileInputStream, final FileOutputStream fileOutputStream) throws IOException {
	if (null != reader) {
		reader.close();
	} 
	if (null != document) {
		document.close();
	}
	if (null != contentByte) {
		contentByte.closePath();
	}
	if (null != writer) {
		writer.close();
	}
	if (null != fileInputStream) {
		fileInputStream.close();
	}
	
	if (null != fileOutputStream) {
		fileOutputStream.flush();
		fileOutputStream.close();
	}
}
 
開發者ID:kuzavas,項目名稱:ephesoft,代碼行數:36,代碼來源:PDFUtil.java

示例13: split

import com.itextpdf.text.pdf.PdfContentByte; //導入依賴的package包/類
void split(PdfReader reader, int page) throws IOException
{
    PdfImportedPage importedPage = writer.getImportedPage(reader, page);

    Rectangle pageSizeToImport = reader.getPageSize(page);
    Iterable<Rectangle> rectangles = determineSplitRectangles(reader, page);

    for (Rectangle rectangle : rectangles) {
        newPage(rectangle);
        PdfContentByte directContent = writer.getDirectContent();
        directContent.saveState();
        directContent.rectangle(rectangle.getLeft(), rectangle.getBottom(), rectangle.getWidth(), rectangle.getHeight());
        directContent.clip();
        directContent.newPath();

        writer.getDirectContent().addTemplate(importedPage, -pageSizeToImport.getLeft(), -pageSizeToImport.getBottom());

        directContent.restoreState();
    }
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:21,代碼來源:Abstract2DPdfPageSplittingTool.java

示例14: cellLayout

import com.itextpdf.text.pdf.PdfContentByte; //導入依賴的package包/類
@Override
    public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
        PdfContentByte canvas = canvases[PdfPTable.BACKGROUNDCANVAS];

        float xTransition = position.getLeft() + (position.getRight() - position.getLeft()) * (percent/100.0f);
        float yTransition = (position.getTop() + position.getBottom()) / 2f;
        float radius = (position.getRight() - position.getLeft()) * 0.025f;
        PdfShading axial = PdfShading.simpleAxial(canvas.getPdfWriter(),
                xTransition - radius, yTransition, xTransition + radius, yTransition, leftColor, rightColor);
        PdfShadingPattern shading = new PdfShadingPattern(axial);

        canvas.saveState();
        canvas.setShadingFill(shading);
        canvas.rectangle(position.getLeft(), position.getBottom(), position.getWidth(), position.getHeight());
//        canvas.clip();
        canvas.fill();
        canvas.restoreState();
    }
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:19,代碼來源:PercentileCellBackground.java

示例15: stampTextOriginal

import com.itextpdf.text.pdf.PdfContentByte; //導入依賴的package包/類
/**
 * The OP's original code transformed into Java
 */
void stampTextOriginal(InputStream source, OutputStream target) throws DocumentException, IOException
{
    Date today = new Date();
    PdfReader reader = new PdfReader(source);
    PdfStamper stamper = new PdfStamper(reader, target);
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, BaseFont.EMBEDDED);
    int tSize = 24;
    String mark = "DRAFT " + today;
    int angle = 45;
    float height = reader.getPageSizeWithRotation(1).getHeight()/2;
    float width = reader.getPageSizeWithRotation(1).getWidth()/2;
    PdfContentByte cb = stamper.getOverContent(1);
    cb.setColorFill(new BaseColor(255,200,200));
    cb.setFontAndSize(bf, tSize);
    cb.beginText();
    cb.showTextAligned(Element.ALIGN_CENTER, mark, width, height, angle);
    cb.endText();
    stamper.close();
    reader.close();
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:24,代碼來源:StampColoredText.java


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