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


Java PdfContentByte.showTextAligned方法代碼示例

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


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

示例1: 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

示例2: stampTextChanged

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
/**
 * The OP's code transformed into Java changed with the work-around.
 */
void stampTextChanged(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.setFontAndSize(bf, tSize);
    cb.beginText();
    cb.setColorFill(new BaseColor(255,200,200));
    cb.showTextAligned(Element.ALIGN_CENTER, mark, width, height, angle);
    cb.endText();
    stamper.close();
    reader.close();
}
 
開發者ID:mkl-public,項目名稱:testarea-itext5,代碼行數:24,代碼來源:StampColoredText.java

示例3: onStartPage

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
/**
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onStartPage(com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
 */
public void onStartPage(PdfWriter writer, Document document) {
    if (writer.getPageNumber() < 3) {
        PdfContentByte cb = writer.getDirectContentUnder();
        cb.saveState();
        cb.setColorFill(BaseColor.PINK);
        cb.beginText();
        cb.setFontAndSize(helv, 48);
        cb.showTextAligned(Element.ALIGN_CENTER, "My Watermark Under " + writer.getPageNumber(), document.getPageSize().getWidth() / 2, document.getPageSize().getHeight() / 2, 45);
        cb.endText();
        cb.restoreState();
    }
}
 
開發者ID:ltrr-arizona-edu,項目名稱:tellervo,代碼行數:16,代碼來源:PageNumbersWatermark.java

示例4: createFile

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
private void createFile(String finalPDF, ByteArrayOutputStream outputStream) throws FileNotFoundException, IOException 
{
	if (outputStream == null || finalPDF == null)
		return;
	FileOutputStream fos = new FileOutputStream (new File(finalPDF)); 
	Document document = new Document();
	try
	{			
		fos.write(outputStream.toByteArray());
		fos.close();
		
		PdfWriter writer = PdfWriter.getInstance(document, fos);

		document.open();
		BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
		PdfContentByte cb = writer.getDirectContent();
		cb.beginText();
		cb.setFontAndSize(bf, 9);
		cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "This is a Draft Document, its contents might still change", 520, 5, 0);
		cb.endText();

		document.close();		       
	}
	catch (Exception e) 
	{
		engine.createSystemLogEntry(SystemLogType.REPORTS, SystemLogLevel.ERROR, "Error Converting DRAFT Document into PDF");
	}
	finally 
	{		
		fos.close();
		if (document.isOpen()) {
			document.close();		
		}
	}
}
 
開發者ID:IMS-MAXIMS,項目名稱:openMAXIMS,代碼行數:36,代碼來源:Logic.java

示例5: createFile

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
public static void createFile(String finalPDF, ByteArrayOutputStream outputStream, UIEngine engine) throws FileNotFoundException, IOException 
{
	if (outputStream == null || finalPDF == null)
		return;
	
	FileOutputStream fos = new FileOutputStream (new File(finalPDF)); 
	Document document = new Document();
	try
	{			
		fos.write(outputStream.toByteArray());
		fos.close();
		
		PdfWriter writer = PdfWriter.getInstance(document, fos);

		document.open();
		BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
		PdfContentByte cb = writer.getDirectContent();
		cb.beginText();
		cb.setFontAndSize(bf, 9);
		cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "This is a Draft Document, its contents might still change", 520, 5, 0);
		cb.endText();

		document.close();		       
	}
	catch (Exception e) 
	{
		engine.createSystemLogEntry(SystemLogType.REPORTS, SystemLogLevel.ERROR, "Error Converting DRAFT Document into PDF");
	}
	finally 
	{		
		fos.close();
		if (document.isOpen()) {
			document.close();		
		}
	}
}
 
開發者ID:IMS-MAXIMS,項目名稱:openMAXIMS,代碼行數:37,代碼來源:DocumentHelper.java

示例6: addText

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
private void addText(String text, int x, int y, BaseFont font,int fontSize,PdfWriter writer) throws DocumentException, IOException {
    PdfContentByte cb = writer.getDirectContent();
    cb.saveState();
    cb.beginText();
    cb.setFontAndSize(font, fontSize);
    float n = 0;
    cb.showTextAligned(PdfContentByte.ALIGN_CENTER, text, x, y, n);
    cb.endText();
    cb.restoreState();
}
 
開發者ID:rbraam,項目名稱:vanenapp,代碼行數:11,代碼來源:PrintCertificateActionBean.java

示例7: applyWatermarkOnAllPages

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
public static void applyWatermarkOnAllPages(
	PdfReader reader, PdfStamper stamper, String text, BaseColor color, float opacity
) throws DocumentException, IOException {
	
	int numberOfPages = reader.getNumberOfPages();
	
	PdfGState gs = new PdfGState();
	gs.setFillOpacity(opacity);

	for (int i = 1; i <= numberOfPages; i++) {
		Rectangle pageSize = reader.getPageSize(i);
		int pageRotation = reader.getPageRotation(i);
		
		boolean isLandscape = false;
		if(pageRotation > 0){
			isLandscape = true;
		}
		
		int pageDiagonalSize = getDiagonalSize(pageSize);
		int watermarkAngle = getDiagonalAngle(pageSize, pageDiagonalSize, isLandscape);
		
		LinkedHashSet<Integer> fontSizeSet = new LinkedHashSet<Integer>();
		float fontSize = determineFontSize(pageDiagonalSize, a4WatermarkFontSize, fontSizeSet);
		fontSize = fontSize - 1;
		
		int cornerPlacement = getCornerPlacementDiagonal(fontSize);
		
		PdfContentByte underContent = stamper.getUnderContent(i);
		underContent.setGState(gs);
		underContent.setFontAndSize(getWaterkmarkFont(), fontSize);
		underContent.setColorFill(color);
		underContent.beginText();
		underContent.showTextAligned(
			Element.ALIGN_BASELINE, text, 
			cornerPlacement/2,
			cornerPlacement/2,
			watermarkAngle
		);
		underContent.endText();
	}
}
 
開發者ID:MatheusArleson,項目名稱:PdfUtil,代碼行數:42,代碼來源:PdfWatermarker.java

示例8: onEndPage

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
/**
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
 */
public void onEndPage(PdfWriter writer, Document document) {
    PdfContentByte cb = writer.getDirectContent();
    cb.saveState();
    // write the headertable
    table.setTotalWidth(document.right() - document.left());
    table.writeSelectedRows(0, -1, document.left(), document.getPageSize().getHeight() - 50, cb);
    // compose the footer
    String text = "Page " + writer.getPageNumber() + " of ";
    float textSize = helv.getWidthPoint(text, 12);
    float textBase = document.bottom() - 20;
    cb.beginText();
    cb.setFontAndSize(helv, 12);
    // for odd pagenumbers, show the footer at the left
    if ((writer.getPageNumber() & 1) == 1) {
        cb.setTextMatrix(document.left(), textBase);
        cb.showText(text);
        cb.endText();
        cb.addTemplate(tpl, document.left() + textSize, textBase);
    }
    // for even numbers, show the footer at the right
    else {
        float adjust = helv.getWidthPoint("0", 12);
        cb.setTextMatrix(document.right() - textSize - adjust, textBase);
        cb.showText(text);
        cb.endText();
        cb.addTemplate(tpl, document.right() - adjust, textBase);
    }
    cb.saveState();
    // draw a Rectangle around the page
    cb.setColorStroke(BaseColor.ORANGE);
    cb.setLineWidth(2);
    cb.rectangle(20, 20, document.getPageSize().getWidth() - 40, document.getPageSize().getHeight() - 40);
    cb.stroke();
    cb.restoreState();
    // starting on page 3, a watermark with an Image that is made transparent
    if (writer.getPageNumber() >= 3) {
        cb.setGState(gstate);
        cb.setColorFill(BaseColor.RED);
        cb.beginText();
        cb.setFontAndSize(helv, 48);
        cb.showTextAligned(Element.ALIGN_CENTER, "Watermark Opacity " + writer.getPageNumber(), document.getPageSize().getWidth() / 2, document.getPageSize().getHeight() / 2, 45);
        cb.endText();
        try {
            cb.addImage(headerImage, headerImage.getWidth(), 0, 0, headerImage.getHeight(), 440, 80);
        }
        catch(Exception e) {
            throw new ExceptionConverter(e);
        }
        cb.restoreState();
    }
    cb.sanityCheck();
}
 
開發者ID:ltrr-arizona-edu,項目名稱:tellervo,代碼行數:56,代碼來源:PageNumbersWatermark.java

示例9: writeAlignedText

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
/**
 * Writes text watermark to one of the 5 preconfigured locations
 * 
 * @param pcb
 * @param r
 * @param tokens
 * @param size
 * @param position
 */
private void writeAlignedText(PdfContentByte pcb, Rectangle r, Vector<String> tokens, float size, String position)
{
    // get the dimensions of our 'rectangle' for text
    float height = size * tokens.size();
    float width = 0;
    float centerX = 0, startY = 0;
    for (int i = 0; i < tokens.size(); i++)
    {
        if (pcb.getEffectiveStringWidth(tokens.get(i), false) > width)
        {
            width = pcb.getEffectiveStringWidth(tokens.get(i), false);
        }
    }

    // now that we have the width and height, we can calculate the center
    // position for
    // the rectangle that will contain our text.
    if (position.equals(POSITION_BOTTOMLEFT))
    {
        centerX = width / 2 + PAD;
        startY = 0 + PAD + height;
    }
    else if (position.equals(POSITION_BOTTOMRIGHT))
    {
        centerX = r.getWidth() - (width / 2) - PAD;
        startY = 0 + PAD + height;
    }
    else if (position.equals(POSITION_TOPLEFT))
    {
        centerX = width / 2 + PAD;
        startY = r.getHeight() - (PAD * 2);
    }
    else if (position.equals(POSITION_TOPRIGHT))
    {
        centerX = r.getWidth() - (width / 2) - PAD;
        startY = r.getHeight() - (PAD * 2);
    }
    else if (position.equals(POSITION_CENTER))
    {
        centerX = r.getWidth() / 2;
        startY = (r.getHeight() / 2) + (height / 2);
    }

    // apply text to PDF
    pcb.beginText();

    for (int t = 0; t < tokens.size(); t++)
    {
        pcb.showTextAligned(PdfContentByte.ALIGN_CENTER, tokens.get(t), centerX, startY - (size * t), 0);
    }

    pcb.endText();

}
 
開發者ID:teqnology,項目名稱:alfresco-pdf-toolkit,代碼行數:64,代碼來源:PDFWatermarkActionExecuter.java

示例10: renderMergedOutputModel

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
        
        // IE workaround: write into byte array first.
        ByteArrayOutputStream baos = createTemporaryOutputStream();

        // Apply preferences and build metadata.
        Document document = newDocument();
        PdfWriter writer = newWriter(document, baos);
        prepareWriter(model, writer, request);
        buildPdfMetadata(model, document, request);

        // Build PDF document.
        document.open();
        buildPdfDocument(model, document, writer, request, response);
        document.close();
        
        //Add Page Number
        PdfReader reader = new PdfReader(baos.toByteArray());
        reader.makeRemoteNamedDestinationsLocal();
        baos = new ByteArrayOutputStream();
        PdfStamper stamper = new PdfStamper(reader, baos);
        BaseFont bf = BaseFont.createFont(getServletContext().getRealPath("/resources/fonts/tahoma.ttf"),BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
        PdfContentByte cb;

        int n = reader.getNumberOfPages();

        for (int i = 1; i <= n; i++) {
            
            cb = stamper.getOverContent(i);
            float x = cb.getPdfDocument().getPageSize().getWidth() / 2;
            cb.beginText();
            cb.setFontAndSize(bf, 12);

            cb.showTextAligned(PdfContentByte.ALIGN_CENTER,"" + i, x, 5, 0);

            cb.endText();
        }
        
        stamper.close();
        
        // Flush to HTTP response.
        writeToResponse(response, baos);
}
 
開發者ID:iliaschalkidis,項目名稱:nomothesia-api,代碼行數:45,代碼來源:AbstractITextPdfView.java

示例11: createPdf

import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
/**
 * Creates a PDF document.
 * @param filename the path to the new PDF document, UPC SKU BinRack
 * Can be null, Default values set statically
 * @throws    DocumentException 
 * @throws    IOException
 */
public static void createPdf(String filename, String upc, String sku, String binRack) 
		throws IOException, DocumentException {
	if(filename==null || filename.isEmpty())
		filename = RESULT;
	if(upc==null || upc.isEmpty()){
		upc = getUpc();
	}else{
		setUpc(upc);
	}
	if(sku==null || sku.isEmpty()){
		sku = getSku();
	}else{
		setSku(sku.toUpperCase());
	}
	if(binRack==null || binRack.isEmpty()){
		getBinRack();
	}
	else{
		setBinRack(binRack);
	}
	
    // step 1
	// 1 inch = 72
	// thus 2.25" x 1.25" = 162 x 90 
    Document document = new Document();
    
    document.setPageSize(new Rectangle(WIDTH,HEIGHT));

    // step 2
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
    // step 3
    document.open();
    // step 4
    PdfContentByte cb = writer.getDirectContent();

    // UPC A
    
    //Generate Image of UPC-A
    Image barImage = generateUPC(cb,upc);
    //barImage.setRotationDegrees(90f);
    barImage.setAbsolutePosition(7,10);
    barImage.setRotationDegrees(90f);
    //Add this Image to Document
    document.add(barImage);
    
    //Coda128
    barImage = generate128(cb,sku);
    //barImage.setRotationDegrees(90f);
    barImage.setAbsolutePosition(37,10);
    barImage.setRotationDegrees(90f);
    //Add this Image to Document
    document.add(barImage);
    
    //Text - BinRack
    BaseFont bf = BaseFont.createFont();
    cb.beginText();
    cb.setFontAndSize(bf, 24);
    cb.showTextAligned(PdfContentByte.ALIGN_LEFT, binRack, 27, 90, 90f);
    cb.endText();
    
    
    // step 5
    document.close();
    
}
 
開發者ID:VDuda,項目名稱:SyncRunner-Pub,代碼行數:73,代碼來源:Barcodes.java


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