本文整理匯總了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();
}
示例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);
}
示例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);
}
示例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;
}
示例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");
}
示例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();
}
}
示例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();
}
示例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);
}
示例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();
}