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


Java PdfContentByte.setColorStroke方法代码示例

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


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

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

示例2: drawFooter

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void drawFooter(PdfContentByte canvas, PageInfos pageInfos) {
    if (pageInfos.getRawPageNumber() == 1 && !footerOnFirstPage)
        return;

    if (drawLine) {
        BaseColor lineColor = styles.getColorOrDefault(HEADER_LINE_COLOR);
        canvas.saveState();
        canvas.setColorStroke(lineColor);
        canvas.setLineWidth(1.2f);
        canvas.moveTo(rect.getLeft(), rect.getBottom() - 6);
        canvas.lineTo(rect.getRight(), rect.getBottom() - 6);
        canvas.stroke();
        canvas.restoreState();
    }

    float bottom = rect.getBottom() - 20;
    Phrase footer = footerText(pageInfos);
    if (footer != null) {
        showTextAligned(canvas, Element.ALIGN_LEFT, footer, rect.getLeft(), bottom, 0);
    }

    Font footerFont = styles.getFontOrDefault(FOOTER_FONT);

    Phrase page = new Phrase(pageInfos.getFormattedPageNumber(), footerFont);
    showTextAligned(canvas, Element.ALIGN_RIGHT, page, rect.getRight(), bottom, 0);
}
 
开发者ID:Arnauld,项目名称:gutenberg,代码行数:27,代码来源:HeaderFooter.java

示例3: drawFooter

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void drawFooter(PdfContentByte canvas, PageInfos pageInfos) {
    if (lineColor != null) {
        canvas.saveState();
        canvas.setColorStroke(lineColor);
        canvas.setLineWidth(1.2f);
        canvas.moveTo(rect.getLeft(), rect.getBottom() - 6);
        canvas.lineTo(rect.getRight(), rect.getBottom() - 6);
        canvas.stroke();
        canvas.restoreState();
    }

    float bottom = rect.getBottom() - 20;
    Phrase footer = footerText();
    if (footer != null) {
        showTextAligned(canvas, Element.ALIGN_LEFT, footer, rect.getLeft(), bottom, 0);
    }

    Phrase page = new Phrase(pageInfos.getFormattedPageNumber(), footerFont);
    showTextAligned(canvas, Element.ALIGN_RIGHT, page, rect.getRight(), bottom, 0);
}
 
开发者ID:Arnauld,项目名称:cucumber-contrib,代码行数:21,代码来源:HeaderFooter.java

示例4: bulidCellBorder

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
private PdfContentByte bulidCellBorder(PdfContentByte[] canvases,Border border){
	PdfContentByte cb=canvases[PdfPTable.LINECANVAS];
	cb.saveState();
	BigDecimal w=new BigDecimal(border.getWidth());
	cb.setLineWidth(w.divide(new BigDecimal(2),10,RoundingMode.HALF_UP).floatValue());
	if(border.getStyle().equals(BorderStyle.dashed)){
		cb.setLineDash(new float[]{2f,3f,1f},2);
	}
	String borderColor[]=border.getColor().split(",");
	cb.setColorStroke(new BaseColor(Integer.valueOf(borderColor[0]),Integer.valueOf(borderColor[1]),Integer.valueOf(borderColor[2])));
	return cb;
}
 
开发者ID:youseries,项目名称:ureport,代码行数:13,代码来源:CellBorderEvent.java

示例5: testCreateTableLikeUser7968180

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/43807931/creating-table-in-pdf-on-last-page-bottom-wrong-official-solution">
 * Creating table in pdf on last page bottom (wrong official solution)
 * </a>
 * <p>
 * Indeed, there is an error in the official sample which effectively
 * applies the margins twice.
 * </p>
 */
@Test
public void testCreateTableLikeUser7968180() throws FileNotFoundException, DocumentException
{
    Document document = new Document(PageSize.A4);
    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(new File(RESULT_FOLDER, "calendarUser7968180.pdf")));
    document.open();

    PdfPTable datatable = null;//createHeaderTable();
    //document.add(datatable);
    datatable = createFooterTable();

    drawTableAtTheEndOfPage(document, writer, datatable);

    // Marking the border
    PdfContentByte canvas = writer.getDirectContentUnder();
    canvas.setColorStroke(BaseColor.RED);
    canvas.setColorFill(BaseColor.PINK);
    canvas.rectangle(document.left(), document.bottom(), document.right() - document.left(), document.top() - document.bottom());
    Rectangle pageSize = document.getPageSize(); 
    canvas.rectangle(pageSize.getLeft(), pageSize.getBottom(), pageSize.getWidth(), pageSize.getHeight());
    canvas.eoFillStroke();

    document.close();
    System.out.println("done");
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:36,代码来源:CreateTableDirectContent.java

示例6: enhance

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
void enhance(PdfContentByte page, Collection<Rectangle2D> rectangles)
{
    for (Rectangle2D rectangle : rectangles)
    {
        page.setColorStroke(pickColor());
        page.rectangle((float) rectangle.getMinX(), (float) rectangle.getMinY(), (float) rectangle.getWidth(), (float) rectangle.getHeight());
        page.stroke();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:10,代码来源:FindFreeSpace.java

示例7: colorRectangle

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
public void colorRectangle(PdfContentByte canvas,
                                  BaseColor color, float x, float y, float width, float height) {
    canvas.saveState();
    canvas.setColorFill(color);
    canvas.setColorStroke(color);
    canvas.rectangle(x, y, width, height);
    canvas.fillStroke();
    canvas.restoreState();
}
 
开发者ID:snavruzov,项目名称:cvbuilder_lib,代码行数:10,代码来源:ModelFactory.java

示例8: addTextAndImage

import com.itextpdf.text.pdf.PdfContentByte; //导入方法依赖的package包/类
private void addTextAndImage(PcGtsType pc, int cutoffLeft, int cutoffTop, Image img, boolean imageOnly) throws DocumentException, IOException {
		lineAndColorList.clear();
		
		PdfContentByte cb = writer.getDirectContentUnder();

		cb.setColorFill(BaseColor.BLACK);
		cb.setColorStroke(BaseColor.BLACK);
		//BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, "UTF-8", BaseFont.NOT_EMBEDDED);
		if (!imageOnly){
			cb.beginLayer(ocrLayer);
			cb.setFontAndSize(bfArial, 32);
					
			List<TrpRegionType> regions = pc.getPage().getTextRegionOrImageRegionOrLineDrawingRegion();
			
			/*
			 * use reading order comparator for sorting since at this time reading order is more trustable
			 * other sorting is not transitive and seldomly produces "Comparison violates its general contract" exception
			 */
			Collections.sort(regions, new TrpElementReadingOrderComparator<RegionType>(true));
	
			for(RegionType r : regions){
				//TODO add paths for tables etc.
				if(r instanceof TextRegionType){
					TextRegionType tr = (TextRegionType)r;
					//PageXmlUtils.buildPolygon(tr.getCoords().getPoints()).getBounds().getMinX();
					addTextFromTextRegion(tr, cb, cutoffLeft, cutoffTop, bfArial);
				}
			}
			
			//scale after calculating lineMeanHeightForAllRegions
			//lineMeanHeight = lineMeanHeight/scaleFactorX;
			
			cb.endLayer();
		}
				
		cb.beginLayer(imgLayer);		
		cb.addImage(img);
		cb.endLayer();
		
		if (highlightTags){
			
			highlightAllTagsOnImg(lineAndColorList, cb, cutoffLeft, cutoffTop);
		}
		
		/*
		 * draw tag lines
		 */
		

		
//		addTocLinks(doc, page,cutoffTop);
	}
 
开发者ID:Transkribus,项目名称:TranskribusCore,代码行数:53,代码来源:TrpPdfDocument.java

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


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