use of com.tom_roush.pdfbox.pdmodel.common.PDRectangle in project PdfBox-Android by TomRoush.
the class PDVisibleSigBuilder method createSignatureRectangle.
@Override
public void createSignatureRectangle(PDSignatureField signatureField, PDVisibleSignDesigner properties) throws IOException {
PDRectangle rect = new PDRectangle();
rect.setUpperRightX(properties.getxAxis() + properties.getWidth());
rect.setUpperRightY(properties.getTemplateHeight() - properties.getyAxis());
rect.setLowerLeftY(properties.getTemplateHeight() - properties.getyAxis() - properties.getHeight());
rect.setLowerLeftX(properties.getxAxis());
signatureField.getWidgets().get(0).setRectangle(rect);
pdfStructure.setSignatureRectangle(rect);
Log.i("PdfBox-Android", "Signature rectangle has been created");
}
use of com.tom_roush.pdfbox.pdmodel.common.PDRectangle in project PdfBox-Android by TomRoush.
the class PDVisibleSigBuilder method createPage.
@Override
public void createPage(PDVisibleSignDesigner properties) {
PDPage page = new PDPage(new PDRectangle(properties.getPageWidth(), properties.getPageHeight()));
pdfStructure.setPage(page);
Log.i("PdfBox-Android", "PDF page has been created");
}
use of com.tom_roush.pdfbox.pdmodel.common.PDRectangle in project PdfBox-Android by TomRoush.
the class AppearanceGeneratorHelper method initializeAppearanceContent.
/**
* Initialize the content of the appearance stream.
*
* Get settings like border style, border width and colors to be used to draw a rectangle and background color
* around the widget
*
* @param widget the field widget
* @param appearanceStream the appearance stream to be used
* @throws IOException in case we can't write to the appearance stream
*/
private void initializeAppearanceContent(PDAnnotationWidget widget, PDAppearanceStream appearanceStream) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
PDPageContentStream contents = new PDPageContentStream(field.getAcroForm().getDocument(), appearanceStream, output);
PDAppearanceCharacteristicsDictionary appearanceCharacteristics = widget.getAppearanceCharacteristics();
// TODO: support more entries like patterns, etc.
if (appearanceCharacteristics != null) {
PDColor backgroundColour = appearanceCharacteristics.getBackground();
if (backgroundColour != null) {
contents.setNonStrokingColor(backgroundColour);
PDRectangle bbox = resolveBoundingBox(widget, appearanceStream);
contents.addRect(bbox.getLowerLeftX(), bbox.getLowerLeftY(), bbox.getWidth(), bbox.getHeight());
contents.fill();
}
float lineWidth = 0f;
PDColor borderColour = appearanceCharacteristics.getBorderColour();
if (borderColour != null) {
contents.setStrokingColor(borderColour);
lineWidth = 1f;
}
PDBorderStyleDictionary borderStyle = widget.getBorderStyle();
if (borderStyle != null && borderStyle.getWidth() > 0) {
lineWidth = borderStyle.getWidth();
}
if (lineWidth > 0 && borderColour != null) {
if (lineWidth != 1) {
contents.setLineWidth(lineWidth);
}
PDRectangle bbox = resolveBoundingBox(widget, appearanceStream);
PDRectangle clipRect = applyPadding(bbox, Math.max(DEFAULT_PADDING, lineWidth / 2));
contents.addRect(clipRect.getLowerLeftX(), clipRect.getLowerLeftY(), clipRect.getWidth(), clipRect.getHeight());
contents.closeAndStroke();
}
}
contents.close();
output.close();
writeToStream(output.toByteArray(), appearanceStream);
}
use of com.tom_roush.pdfbox.pdmodel.common.PDRectangle in project PdfBox-Android by TomRoush.
the class PDThreadBead method getRectangle.
/**
* The rectangle on the page that this bead is part of.
*
* @return The part of the page that this bead covers.
*/
public PDRectangle getRectangle() {
PDRectangle rect = null;
COSArray array = (COSArray) bead.getDictionaryObject(COSName.R);
if (array != null) {
rect = new PDRectangle(array);
}
return rect;
}
use of com.tom_roush.pdfbox.pdmodel.common.PDRectangle in project PdfBox-Android by TomRoush.
the class PDFRenderer method renderPageToGraphics.
/**
* Renders a given page to an AWT Graphics2D instance.
*
* @param pageIndex the zero-based index of the page to be converted
* @param paint the Paint that will be used to draw the page
* @param canvas the Canvas on which to draw the page
* @param scaleX the scale to draw the page at for the x-axis, where 1 = 72 DPI
* @param scaleY the scale to draw the page at for the y-axis, where 1 = 72 DPI
* @param destination controlling visibility of optional content groups
* @throws IOException if the PDF cannot be read
*/
public void renderPageToGraphics(int pageIndex, Paint paint, Canvas canvas, float scaleX, float scaleY, RenderDestination destination) throws IOException {
PDPage page = document.getPage(pageIndex);
// TODO need width/height calculations? should these be in PageDrawer?
transform(canvas, page, scaleX, scaleY);
PDRectangle cropBox = page.getCropBox();
canvas.drawRect(0, 0, cropBox.getWidth(), cropBox.getHeight(), paint);
// the end-user may provide a custom PageDrawer
PageDrawerParameters parameters = new PageDrawerParameters(this, page, subsamplingAllowed, destination);
PageDrawer drawer = createPageDrawer(parameters);
drawer.drawPage(paint, canvas, cropBox);
}
Aggregations