本文整理匯總了Java中com.itextpdf.text.pdf.PdfContentByte.lineTo方法的典型用法代碼示例。如果您正苦於以下問題:Java PdfContentByte.lineTo方法的具體用法?Java PdfContentByte.lineTo怎麽用?Java PdfContentByte.lineTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.itextpdf.text.pdf.PdfContentByte
的用法示例。
在下文中一共展示了PdfContentByte.lineTo方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: drawSexyTriangle
import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
private static void drawSexyTriangle(PdfWriter writer, boolean rotated)
{
PdfContentByte canvas = writer.getDirectContent();
float x = 36;
float y = 400;
float side = 70;
PdfShading axial = rotated ?
PdfShading.simpleAxial(writer, PageSize.A4.getRight() - y, x, PageSize.A4.getRight() - y, x + side, BaseColor.PINK, BaseColor.BLUE)
: PdfShading.simpleAxial(writer, x, y, x + side, y, BaseColor.PINK, BaseColor.BLUE);
PdfShadingPattern shading = new PdfShadingPattern(axial);
canvas.setShadingFill(shading);
canvas.moveTo(x,y);
canvas.lineTo(x + side, y);
canvas.lineTo(x + (side / 2), (float)(y + (side * Math.sin(Math.PI / 3))));
canvas.closePathFillStroke();
}
示例3: 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);
}
示例4: 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);
}
示例5: testSimple
import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
@Test
public void testSimple() throws FileNotFoundException, DocumentException
{
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "transparency.pdf")));
writer.setCompressionLevel(0);
document.open();
PdfContentByte content = writer.getDirectContent();
content.setRGBColorStroke(0, 255, 0);
for (int y = 0; y <= 400; y+= 10)
{
content.moveTo(0, y);
content.lineTo(500, y);
}
for (int x = 0; x <= 500; x+= 10)
{
content.moveTo(x, 0);
content.lineTo(x, 400);
}
content.stroke();
content.saveState();
PdfGState state = new PdfGState();
state.setFillOpacity(0.5f);
content.setGState(state);
content.setRGBColorFill(255, 0, 0);
content.moveTo(162, 86);
content.lineTo(162, 286);
content.lineTo(362, 286);
content.lineTo(362, 86);
content.closePath();
//content.fillStroke();
content.fill();
content.restoreState();
document.close();
}
示例6: render
import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
public void render(PdfWriter writer, Document document){
Cutmarks cutmarks = request.getCutmarks();
if( cutmarks != null && ! cutmarks.isIgnoreCutStroke() ){
float width = SizeFactory.CUT_MARK;
float height = SizeFactory.CUT_MARK;
float lineWidth = SizeFactory.CUT_MARK_LINE;
float lineHeight = SizeFactory.CUT_MARK_LINE;
Rectangle rect = document.getPageSize();
PdfContentByte cb = writer.getDirectContent();
cb.setLineWidth( 0.1f );
cb.moveTo( SizeFactory.millimetersToPostscriptPoints(width), 0);
cb.lineTo( SizeFactory.millimetersToPostscriptPoints(width),SizeFactory.millimetersToPostscriptPoints(lineHeight));
cb.stroke();
cb.moveTo( 0, SizeFactory.millimetersToPostscriptPoints(height));
cb.lineTo( SizeFactory.millimetersToPostscriptPoints(lineWidth),SizeFactory.millimetersToPostscriptPoints(height));
cb.stroke();
// Upper left cut mark
cb.moveTo( SizeFactory.millimetersToPostscriptPoints(width), rect.getHeight() );
cb.lineTo( SizeFactory.millimetersToPostscriptPoints(width), rect.getHeight() - SizeFactory.millimetersToPostscriptPoints(lineHeight));
cb.stroke();
cb.moveTo( 0, rect.getHeight() - SizeFactory.millimetersToPostscriptPoints(height));
cb.lineTo( SizeFactory.millimetersToPostscriptPoints(lineWidth),rect.getHeight() - SizeFactory.millimetersToPostscriptPoints(height));
cb.stroke();
/**
* Upper right cut mark
*/
cb.moveTo( rect.getWidth(), rect.getHeight() - SizeFactory.millimetersToPostscriptPoints(height));
cb.lineTo( rect.getWidth() - SizeFactory.millimetersToPostscriptPoints(lineWidth),rect.getHeight() - SizeFactory.millimetersToPostscriptPoints(height));
cb.stroke();
cb.moveTo( rect.getWidth() - SizeFactory.millimetersToPostscriptPoints(width), rect.getHeight() );
cb.lineTo( rect.getWidth() - SizeFactory.millimetersToPostscriptPoints(width),rect.getHeight() - SizeFactory.millimetersToPostscriptPoints(lineHeight));
cb.stroke();
/**
* Lower right cut mark
*/
cb.moveTo( rect.getWidth() - SizeFactory.millimetersToPostscriptPoints(width), 0 );
cb.lineTo( rect.getWidth() - SizeFactory.millimetersToPostscriptPoints(width),SizeFactory.millimetersToPostscriptPoints(lineHeight));
cb.stroke();
cb.moveTo( rect.getWidth() , SizeFactory.millimetersToPostscriptPoints(height) );
cb.lineTo( rect.getWidth() - SizeFactory.millimetersToPostscriptPoints(lineWidth),SizeFactory.millimetersToPostscriptPoints(height));
cb.stroke();
}
}
示例7: testComplex
import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
@Test
public void testComplex() throws FileNotFoundException, DocumentException
{
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "transparencyComplex.pdf")));
writer.setCompressionLevel(0);
document.open();
PdfContentByte content = writer.getDirectContent();
content.setRGBColorStroke(0, 255, 0);
for (int y = 0; y <= 400; y+= 10)
{
content.moveTo(0, y);
content.lineTo(500, y);
}
for (int x = 0; x <= 500; x+= 10)
{
content.moveTo(x, 0);
content.lineTo(x, 400);
}
content.stroke();
PdfTemplate template = content.createTemplate(500, 400);
PdfTransparencyGroup group = new PdfTransparencyGroup();
group.put(PdfName.CS, PdfName.DEVICEGRAY);
group.setIsolated(false);
group.setKnockout(false);
template.setGroup(group);
PdfShading radial = PdfShading.simpleRadial(writer, 262, 186, 10, 262, 186, 190, BaseColor.WHITE, BaseColor.BLACK, true, true);
template.paintShading(radial);
PdfDictionary mask = new PdfDictionary();
mask.put(PdfName.TYPE, PdfName.MASK);
mask.put(PdfName.S, new PdfName("Luminosity"));
mask.put(new PdfName("G"), template.getIndirectReference());
content.saveState();
PdfGState state = new PdfGState();
state.put(PdfName.SMASK, mask);
content.setGState(state);
content.setRGBColorFill(255, 0, 0);
content.moveTo(162, 86);
content.lineTo(162, 286);
content.lineTo(362, 286);
content.lineTo(362, 86);
content.closePath();
//content.fillStroke();
content.fill();
content.restoreState();
document.close();
}
示例8: markLineBoundaries
import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
void markLineBoundaries(String resource, int startPage, int endPage) throws IOException, DocumentException
{
String name = new File(resource).getName();
String target = String.format("%s-lines-%s-%s.pdf", name, startPage, endPage);
InputStream resourceStream = getClass().getResourceAsStream(resource);
try
{
PdfReader reader = new PdfReader(resourceStream);
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
System.out.printf("\nLine boundaries in %s\n", name);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(new File(RESULT_FOLDER, target)));
for (int page = startPage; page < endPage; page++)
{
System.out.printf("\n Page %s\n ", page);
TextLineFinder finder = new TextLineFinder();
parser.processContent(page, finder);
PdfContentByte over = stamper.getOverContent(page);
Rectangle mediaBox = reader.getPageSize(page);
for (float flip: finder.verticalFlips)
{
System.out.printf(" %s", flip);
over.moveTo(mediaBox.getLeft(), flip);
over.lineTo(mediaBox.getRight(), flip);
}
System.out.println();
over.stroke();
}
stamper.close();
}
finally
{
if (resourceStream != null)
resourceStream.close();
}
}
示例9: writePathIterator
import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
/**
* Write a path describing a graphic objects of straight lines, Bezier
* curves, potentially with holes and islands.
*
* @param iterator The path iterator to write.
* @param vectorSymbol The VectorSymbol specifying the appearance of pi.
*/
private void writePathIterator(GeoPathIterator iterator,
VectorSymbol vectorSymbol, PdfContentByte cb) {
// write colors and stroke width if necessary.
this.writePaintingAttributes(vectorSymbol, cb);
// write the path
// remember the last written segment type and the point position.
int lastSegmentType = GeoPathModel.NONE;
do {
final int type = iterator.getInstruction();
switch (type) {
case GeoPathModel.CLOSE:
cb.closePath();
writeFillStroke(vectorSymbol, true, cb); // !!! ??? needed?
break;
case GeoPathModel.MOVETO:
writeFillStroke(vectorSymbol, false, cb);// !!! ??? needed?
// start defintion of new path
cb.moveTo((float)xToPagePx(iterator.getX()),
(float)yToPagePx(iterator.getY()));
break;
case GeoPathModel.LINETO:
cb.lineTo((float)xToPagePx(iterator.getX()),
(float)yToPagePx(iterator.getY()));
break;
case GeoPathModel.QUADCURVETO:
cb.curveTo((float)xToPagePx(iterator.getX()),
(float)yToPagePx(iterator.getY()),
(float)xToPagePx(iterator.getX2()),
(float)yToPagePx(iterator.getY2()));
break;
case GeoPathModel.CURVETO:
cb.curveTo((float)xToPagePx(iterator.getX()),
(float)yToPagePx(iterator.getY()),
(float)xToPagePx(iterator.getX2()),
(float)yToPagePx(iterator.getY2()),
(float)xToPagePx(iterator.getX3()),
(float)yToPagePx(iterator.getY3()));
break;
}
lastSegmentType = type;
} while (iterator.next());
if (lastSegmentType != PathIterator.SEG_CLOSE
&& lastSegmentType != PathIterator.SEG_MOVETO) {
this.writeFillStroke(vectorSymbol, false, cb);
}
}
示例10: createGeometricObjects
import com.itextpdf.text.pdf.PdfContentByte; //導入方法依賴的package包/類
private void createGeometricObjects(PdfContentByte cb, long amountOfCarts, Document doc) {
// first big grey block
// float y 310 h 325
cb.saveState();
cb.setRGBColorFill(0xE0, 0xDE, 0xDF);
cb.rectangle(0.0f, 325f - (amountOfCarts + 1) * 16f, 595.0f, 310 + (amountOfCarts + 1) * 16f);
cb.fill();
cb.stroke();
cb.restoreState();
// name and address block
cb.saveState();
cb.setRGBColorFill(0xFC, 0xFC, 0xFC);
cb.rectangle(75.0f, 410.0f, 445.0f, 120.0f);
cb.fill();
cb.stroke();
cb.restoreState();
// price block
cb.saveState();
cb.setRGBColorFill(0xFC, 0xFC, 0xFC);
cb.rectangle(75.0f, 350f - (amountOfCarts + 1) * 16f, 295f, 45f + (amountOfCarts + 1) * 16f);
cb.fill();
cb.stroke();
cb.restoreState();
// date block
cb.saveState();
cb.setRGBColorFill(0xFC, 0xFC, 0xFC);
cb.rectangle(385.0f, 350f - (amountOfCarts + 1) * 16f, 135f, 45f + (amountOfCarts + 1) * 16f);
cb.fill();
cb.stroke();
cb.restoreState();
// small triangle in address block
cb.saveState();
cb.setRGBColorFill(0xE0, 0xDE, 0xDF);
cb.moveTo(74f, 455f);
cb.lineTo(74f, 485f);
cb.lineTo(82f, 470f);
cb.lineTo(74f, 455f);
cb.fill();
cb.closePathStroke();
cb.restoreState();
// small triangle in price block
cb.saveState();
cb.setRGBColorFill(0xE0, 0xDE, 0xDF);
cb.moveTo(74f, 350f);
cb.lineTo(74f, 380f);
cb.lineTo(82f, 365f);
cb.lineTo(74f, 350f);
cb.fill();
cb.closePathStroke();
cb.restoreState();
}