本文整理汇总了Java中org.apache.pdfbox.pdmodel.edit.PDPageContentStream.addRect方法的典型用法代码示例。如果您正苦于以下问题:Java PDPageContentStream.addRect方法的具体用法?Java PDPageContentStream.addRect怎么用?Java PDPageContentStream.addRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.pdfbox.pdmodel.edit.PDPageContentStream
的用法示例。
在下文中一共展示了PDPageContentStream.addRect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clipPage
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
void clipPage(PDDocument document, PDPage page, BoundingBox clipBox) throws IOException
{
PDPageContentStream pageContentStream = new PDPageContentStream(document, page, true, false);
pageContentStream.addRect(clipBox.getLowerLeftX(), clipBox.getLowerLeftY(), clipBox.getWidth(), clipBox.getHeight());
pageContentStream.clipPath(PathIterator.WIND_NON_ZERO);
pageContentStream.close();
COSArray newContents = new COSArray();
COSStreamArray contents = (COSStreamArray) page.getContents().getStream();
newContents.add(contents.get(contents.getStreamCount()-1));
for (int i = 0; i < contents.getStreamCount()-1; i++)
{
newContents.add(contents.get(i));
}
page.setContents(new PDStream(new COSStreamArray(newContents)));
}
示例2: renderFrame
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
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();
}
}
示例3: drawReletivePartAndMovePosition
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
/**
* Actually draws the (drawble) part at the
* {@link RenderContext#getCurrentPosition()} and - depending on flag
* <code>movePosition</code> - moves to the new Y position. Any left or
* right margin is taken into account to calculate the position and
* alignment.
*
* @param renderContext
* the context providing all rendering state.
* @param drawable
* the drawable to draw.
* @param layoutHint
* the layout hint used to layout.
* @param movePosition
* indicates if the position should be moved (vertically) after
* drawing.
* @throws IOException
* by pdfbox
*/
protected void drawReletivePartAndMovePosition(
final RenderContext renderContext, Drawable drawable,
final LayoutHint layoutHint, final boolean movePosition)
throws IOException {
PDPageContentStream contentStream = renderContext.getContentStream();
PageFormat pageFormat = renderContext.getPageFormat();
float offsetX = 0;
if (layoutHint instanceof VerticalLayoutHint) {
VerticalLayoutHint verticalLayoutHint = (VerticalLayoutHint) layoutHint;
Alignment alignment = verticalLayoutHint.getAlignment();
float horizontalExtraSpace = getTargetWidth(renderContext)
- drawable.getWidth();
switch (alignment) {
case Right:
offsetX = horizontalExtraSpace
- verticalLayoutHint.getMarginRight();
break;
case Center:
offsetX = horizontalExtraSpace / 2f;
break;
default:
offsetX = verticalLayoutHint.getMarginLeft();
break;
}
}
contentStream.saveGraphicsState();
contentStream.addRect(0, pageFormat.getMarginBottom(), renderContext.getPageWidth(),
renderContext.getHeight());
CompatibilityHelper.clip(contentStream);
drawable.draw(renderContext.getPdDocument(), contentStream,
renderContext.getCurrentPosition().add(offsetX, 0),renderContext);
contentStream.restoreGraphicsState();
if (movePosition) {
renderContext.movePositionBy(0, -drawable.getHeight());
}
}
示例4: add
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream; //导入方法依赖的package包/类
@Override
public void add(PDDocument pdDocument, PDPageContentStream contentStream,
Position upperLeft, float width, float height) throws IOException {
contentStream.addRect(upperLeft.getX(), upperLeft.getY() - height,
width, height);
}