Search in sources :

Example 41 with PDRectangle

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");
}
Also used : PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

Example 42 with PDRectangle

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");
}
Also used : PDPage(com.tom_roush.pdfbox.pdmodel.PDPage) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

Example 43 with PDRectangle

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);
}
Also used : PDAppearanceCharacteristicsDictionary(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAppearanceCharacteristicsDictionary) PDPageContentStream(com.tom_roush.pdfbox.pdmodel.PDPageContentStream) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PDBorderStyleDictionary(com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDBorderStyleDictionary) PDColor(com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor)

Example 44 with PDRectangle

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;
}
Also used : COSArray(com.tom_roush.pdfbox.cos.COSArray) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

Example 45 with PDRectangle

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);
}
Also used : PDPage(com.tom_roush.pdfbox.pdmodel.PDPage) PDRectangle(com.tom_roush.pdfbox.pdmodel.common.PDRectangle)

Aggregations

PDRectangle (com.tom_roush.pdfbox.pdmodel.common.PDRectangle)82 IOException (java.io.IOException)19 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)13 PDAppearanceContentStream (com.tom_roush.pdfbox.pdmodel.PDAppearanceContentStream)12 PDColor (com.tom_roush.pdfbox.pdmodel.graphics.color.PDColor)11 Matrix (com.tom_roush.pdfbox.util.Matrix)11 COSArray (com.tom_roush.pdfbox.cos.COSArray)10 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)10 PDAppearanceStream (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream)9 Path (android.graphics.Path)8 AffineTransform (com.tom_roush.harmony.awt.geom.AffineTransform)7 PDFormXObject (com.tom_roush.pdfbox.pdmodel.graphics.form.PDFormXObject)6 COSBase (com.tom_roush.pdfbox.cos.COSBase)5 PDDocument (com.tom_roush.pdfbox.pdmodel.PDDocument)5 PDPageContentStream (com.tom_roush.pdfbox.pdmodel.PDPageContentStream)5 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)4 COSName (com.tom_roush.pdfbox.cos.COSName)4 PDExtendedGraphicsState (com.tom_roush.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState)4 PDAnnotationTextMarkup (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationTextMarkup)4 PDAnnotationWidget (com.tom_roush.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget)4