Java Code Examples for org.apache.pdfbox.pdmodel.edit.PDPageContentStream#setStrokingColor()

The following examples show how to use org.apache.pdfbox.pdmodel.edit.PDPageContentStream#setStrokingColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HorizontalRuler.java    From pdfbox-layout with MIT License 6 votes vote down vote up
@Override
   public void draw(PDDocument pdDocument, PDPageContentStream contentStream,
    Position upperLeft, DrawListener drawListener) throws IOException {
if (getColor() != null) {
    contentStream.setStrokingColor(getColor());
}
if (getStroke() != null) {
    getStroke().applyTo(contentStream);
    float x = upperLeft.getX();
    float y = upperLeft.getY() - getStroke().getLineWidth() / 2;
    contentStream.addLine(x, y, x + getWidth(), y);
    contentStream.stroke();
}
if (drawListener != null) {
    drawListener.drawn(this, upperLeft, getWidth(), getHeight());
}
   }
 
Example 2
Source File: AbstractShape.java    From pdfbox-layout with MIT License 6 votes vote down vote up
@Override
   public void draw(PDDocument pdDocument, PDPageContentStream contentStream,
    Position upperLeft, float width, float height, Color color,
    Stroke stroke, DrawListener drawListener) throws IOException {

add(pdDocument, contentStream, upperLeft, width, height);

if (stroke != null) {
    stroke.applyTo(contentStream);
}
if (color != null) {
    contentStream.setStrokingColor(color);
}
contentStream.stroke();

if (drawListener != null) {
    drawListener.drawn(this, upperLeft, width, height);
}

   }
 
Example 3
Source File: PDFUtil.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void renderLine(PDPageContentStream contentStream, org.phoenixctms.ctsms.enumeration.Color color, float xStart, float yStart, float xEnd, float yEnd,
		float lineWidth, LineStyle lineStyle)
		throws IOException {
	if (contentStream != null && lineWidth > 0.0f) {
		contentStream.setStrokingColor(CommonUtil.convertColor(color));
		setLineDashPattern(contentStream, lineStyle);
		contentStream.setLineWidth(lineWidth);
		contentStream.addLine(xStart, yStart, xEnd, yEnd);
		contentStream.closeAndStroke();
	}
}
 
Example 4
Source File: UnderlineAnnotationProcessor.java    From pdfbox-layout with MIT License 5 votes vote down vote up
public void draw(PDPageContentStream contentStream) throws IOException {
    if (color != null) {
	contentStream.setStrokingColor(color);
    }
    if (stroke != null) {
	stroke.applyTo(contentStream);
    }
    contentStream.drawLine(start.getX(), start.getY(), end.getX(),
	    end.getY());
}
 
Example 5
Source File: PDFUtil.java    From ctsms with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void renderFrame(PDPageContentStream contentStream, org.phoenixctms.ctsms.enumeration.Color color, float x, float y, float width, float height, Alignment align,
		float lineWidth, LineStyle lineStyle) throws IOException {
	if (contentStream != null && lineWidth > 0.0f) {
		float left = x;
		float bottom = y - height;
		if (align != null) {
			switch (align) {
				case TOP_CENTER:
					left = x - width / 2.0f;
					bottom = y - height;
					break;
				case TOP_RIGHT:
					left = x - width;
					bottom = y - height;
					break;
				case MIDDLE_LEFT:
					left = x;
					bottom = y - height / 2.0f;
					break;
				case MIDDLE_CENTER:
					left = x - width / 2.0f;
					bottom = y - height / 2.0f;
					break;
				case MIDDLE_RIGHT:
					left = x - width;
					bottom = y - height / 2.0f;
					break;
				case BOTTOM_LEFT:
					left = x;
					bottom = y;
					break;
				case BOTTOM_CENTER:
					left = x - width / 2.0f;
					bottom = y;
					break;
				case BOTTOM_RIGHT:
					left = x - width;
					bottom = y;
					break;
				default: // topleft else...
			}
		}
		contentStream.setStrokingColor(CommonUtil.convertColor(color));
		setLineDashPattern(contentStream, lineStyle);
		contentStream.setLineWidth(lineWidth);
		contentStream.addRect(left, bottom, width, height);
		contentStream.closeAndStroke();
	}
}