Example usage for org.apache.pdfbox.pdmodel.interactive.annotation PDAnnotationTextMarkup setPrinted

List of usage examples for org.apache.pdfbox.pdmodel.interactive.annotation PDAnnotationTextMarkup setPrinted

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.interactive.annotation PDAnnotationTextMarkup setPrinted.

Prototype

public void setPrinted(boolean printed) 

Source Link

Document

Set the printed flag.

Usage

From source file:com.infoimage.infotrac.pdfbox.PDFTextAnnotator.java

License:Apache License

/**
 * Highlights a pattern within the PDF with the default color
 * Returns the list of added annotations for further modification
 * Note: it will process every page, but cannot process patterns that span multiple pages
 * Note: it will not work for top-bottom text (such as Chinese)
 *
 * @param pdf//from   ww  w .  j a va  2s  .  c  o  m
 *          PDDocument
 * @param pattern
 *          Pattern (regex)
 * @throws Exception
 */
public List<PDAnnotationTextMarkup> highlight(PDDocument pdf, Pattern pattern) throws Exception {
    if (textCache == null) {
        throw new Exception("TextCache was not initilized, please run initialize on the document first");
    }

    List<PDPage> pages = pdf.getDocumentCatalog().getAllPages();

    ArrayList<PDAnnotationTextMarkup> highligts = new ArrayList<PDAnnotationTextMarkup>();

    for (int pageIndex = getStartPage() - 1; pageIndex < getEndPage()
            && pageIndex < pages.size(); pageIndex++) {
        PDPage page = pages.get(pageIndex);
        List<PDAnnotation> annotations = page.getAnnotations();

        List<Match> matches = this.textCache.getTextPositions(pageIndex + 1, pattern);

        for (Match match : matches) {
            List<PDRectangle> textBoundingBoxes = getTextBoundingBoxes(match.positions);

            PDAnnotationTextMarkup markup = new PDAnnotationTextMarkup(
                    PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT);
            if (textBoundingBoxes.size() > 0) {
                markup.setRectangle(textBoundingBoxes.get(0));

                float[] quads = new float[8 * textBoundingBoxes.size()];
                int cursor = 0;
                for (PDRectangle rect : textBoundingBoxes) {
                    float[] tmp = computeQuads(rect);
                    for (int i = 0; i < tmp.length; i++) {
                        quads[cursor + i] = tmp[i];
                    }
                    cursor = cursor + 8;
                }

                markup.setQuadPoints(quads);

                markup.setConstantOpacity((float) 0.8);
                markup.setColour(getDefaultColor());
                markup.setPrinted(true);
                markup.setContents(match.str);

                annotations.add(markup);
                highligts.add(markup);
            }
        }
    }
    return highligts;
}

From source file:hightlighting.PDFTextAnnotator.java

License:Apache License

/**
 * Highlights a pattern within the PDF with the default color 
 * Returns the list of added annotations for further modification
 * Note: it will process every page, but cannot process patterns that span multiple pages 
 * Note: it will not work for top-bottom text (such as Chinese)
 * //from  w  ww . j a  v  a 2s.c o  m
 * @param pdf
 *          PDDocument
 * @param pattern
 *          Pattern (regex)
 * @throws Exception
 */
public List<PDAnnotationTextMarkup> highlight(PDDocument pdf, Pattern pattern) throws Exception {
    if (textCache == null) {
        throw new Exception("TextCache was not initilized, please run initialize on the document first");
    }

    List<PDPage> pages = pdf.getDocumentCatalog().getAllPages();

    ArrayList<PDAnnotationTextMarkup> highligts = new ArrayList<PDAnnotationTextMarkup>();

    for (int pageIndex = getStartPage() - 1; pageIndex < getEndPage()
            && pageIndex < pages.size(); pageIndex++) {
        PDPage page = pages.get(pageIndex);
        List<PDAnnotation> annotations = page.getAnnotations();

        List<Match> matches = this.textCache.getTextPositions(pageIndex + 1, pattern);

        for (Match match : matches) {
            List<PDRectangle> textBoundingBoxes = getTextBoundingBoxes(match.positions);

            if (textBoundingBoxes.size() > 0) {

                float[] quads = new float[8];
                int cursor = 0;
                for (PDRectangle rect : textBoundingBoxes) {
                    PDAnnotationTextMarkup markup = new PDAnnotationTextMarkup(
                            PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT);
                    markup.setRectangle(rect);
                    float[] tmp = computeQuads(rect);
                    for (int i = 0; i < tmp.length; i++) {
                        quads[cursor + i] = tmp[i];
                    }
                    //cursor = cursor + 8;
                    markup.setQuadPoints(quads);

                    markup.setConstantOpacity((float) 0.8);
                    markup.setColour(getDefaultColor());
                    markup.setPrinted(true);
                    markup.setContents(match.str);

                    annotations.add(markup);
                    highligts.add(markup);
                }
            }
        }
    }
    return highligts;
}

From source file:vortext.TextHighlight.java

License:Apache License

/**
 * Highlights a pattern within the PDF with the default color. Returns the
 * list of added annotations for further modification. Note: it will process
 * every page, but cannot process patterns that span multiple pages. Note: it
 * will not work for top-bottom text (such as Chinese)
 *
 * @param pattern/* w  w  w. j  a v  a 2 s  .c  o m*/
 *          Pattern (regex)
 * @throws IOException
 */
public List<PDAnnotationTextMarkup> highlightDefault(final Pattern pattern) throws IOException {
    final List<PDAnnotationTextMarkup> highlights = this.highlight(pattern,
            PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT);
    for (final PDAnnotationTextMarkup highlight : highlights) {
        highlight.setConstantOpacity((float) 0.8);
        highlight.setColour(getDefaultColor());
        highlight.setPrinted(true);
    }
    return highlights;
}