Search in sources :

Example 1 with PdfRectangle

use of com.lowagie.text.pdf.PdfRectangle in project OpenPDF by LibrePDF.

the class PdfAnnotationsImp method rotateAnnotations.

public PdfArray rotateAnnotations(PdfWriter writer, Rectangle pageSize) {
    PdfArray array = new PdfArray();
    int rotation = pageSize.getRotation() % 360;
    int currentPage = writer.getCurrentPageNumber();
    for (Object annotation : annotations) {
        PdfAnnotation dic = (PdfAnnotation) annotation;
        int page = dic.getPlaceInPage();
        if (page > currentPage) {
            delayedAnnotations.add(dic);
            continue;
        }
        if (dic.isForm()) {
            if (!dic.isUsed()) {
                Map<PdfTemplate, Object> templates = dic.getTemplates();
                if (templates != null)
                    acroForm.addFieldTemplates(templates);
            }
            PdfFormField field = (PdfFormField) dic;
            if (field.getParent() == null)
                acroForm.addDocumentField(field.getIndirectReference());
        }
        if (dic.isAnnotation()) {
            array.add(dic.getIndirectReference());
            if (!dic.isUsed()) {
                PdfRectangle rect = (PdfRectangle) dic.get(PdfName.RECT);
                if (rect != null) {
                    switch(rotation) {
                        case 90:
                            dic.put(PdfName.RECT, new PdfRectangle(pageSize.getTop() - rect.bottom(), rect.left(), pageSize.getTop() - rect.top(), rect.right()));
                            break;
                        case 180:
                            dic.put(PdfName.RECT, new PdfRectangle(pageSize.getRight() - rect.left(), pageSize.getTop() - rect.bottom(), pageSize.getRight() - rect.right(), pageSize.getTop() - rect.top()));
                            break;
                        case 270:
                            dic.put(PdfName.RECT, new PdfRectangle(rect.bottom(), pageSize.getRight() - rect.left(), rect.top(), pageSize.getRight() - rect.right()));
                            break;
                    }
                }
            }
        }
        if (!dic.isUsed()) {
            dic.setUsed();
            try {
                writer.addToBody(dic, dic.getIndirectReference());
            } catch (IOException e) {
                throw new ExceptionConverter(e);
            }
        }
    }
    return array;
}
Also used : ExceptionConverter(com.lowagie.text.ExceptionConverter) PdfArray(com.lowagie.text.pdf.PdfArray) PdfFormField(com.lowagie.text.pdf.PdfFormField) PdfAnnotation(com.lowagie.text.pdf.PdfAnnotation) PdfRectangle(com.lowagie.text.pdf.PdfRectangle) PdfObject(com.lowagie.text.pdf.PdfObject) IOException(java.io.IOException) PdfTemplate(com.lowagie.text.pdf.PdfTemplate)

Example 2 with PdfRectangle

use of com.lowagie.text.pdf.PdfRectangle in project OpenPDF by LibrePDF.

the class FieldPositioningEvents method onGenericTag.

/**
 * @see com.lowagie.text.pdf.PdfPageEvent#onGenericTag(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document, com.lowagie.text.Rectangle, java.lang.String)
 */
public void onGenericTag(PdfWriter writer, Document document, Rectangle rect, String text) {
    rect.setBottom(rect.getBottom() - 3);
    PdfFormField field = genericChunkFields.get(text);
    if (field == null) {
        TextField tf = new TextField(writer, new Rectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)), text);
        tf.setFontSize(14);
        try {
            field = tf.getTextField();
        } catch (Exception e) {
            throw new ExceptionConverter(e);
        }
    } else {
        field.put(PdfName.RECT, new PdfRectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)));
    }
    if (parent == null)
        writer.addAnnotation(field);
    else
        parent.addKid(field);
}
Also used : ExceptionConverter(com.lowagie.text.ExceptionConverter) PdfFormField(com.lowagie.text.pdf.PdfFormField) Rectangle(com.lowagie.text.Rectangle) PdfRectangle(com.lowagie.text.pdf.PdfRectangle) TextField(com.lowagie.text.pdf.TextField) PdfRectangle(com.lowagie.text.pdf.PdfRectangle) IOException(java.io.IOException) DocumentException(com.lowagie.text.DocumentException)

Example 3 with PdfRectangle

use of com.lowagie.text.pdf.PdfRectangle in project itext2 by albfernandez.

the class FieldPositioningEvents method onGenericTag.

/**
 * @see com.lowagie.text.pdf.PdfPageEvent#onGenericTag(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document, com.lowagie.text.Rectangle, java.lang.String)
 */
public void onGenericTag(PdfWriter writer, Document document, Rectangle rect, String text) {
    rect.setBottom(rect.getBottom() - 3);
    PdfFormField field = (PdfFormField) genericChunkFields.get(text);
    if (field == null) {
        TextField tf = new TextField(writer, new Rectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)), text);
        tf.setFontSize(14);
        try {
            field = tf.getTextField();
        } catch (Exception e) {
            throw new ExceptionConverter(e);
        }
    } else {
        field.put(PdfName.RECT, new PdfRectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)));
    }
    if (parent == null)
        writer.addAnnotation(field);
    else
        parent.addKid(field);
}
Also used : ExceptionConverter(com.lowagie.text.ExceptionConverter) PdfFormField(com.lowagie.text.pdf.PdfFormField) Rectangle(com.lowagie.text.Rectangle) PdfRectangle(com.lowagie.text.pdf.PdfRectangle) TextField(com.lowagie.text.pdf.TextField) PdfRectangle(com.lowagie.text.pdf.PdfRectangle) IOException(java.io.IOException) DocumentException(com.lowagie.text.DocumentException)

Example 4 with PdfRectangle

use of com.lowagie.text.pdf.PdfRectangle in project itext2 by albfernandez.

the class PdfAnnotationsImp method rotateAnnotations.

public PdfArray rotateAnnotations(PdfWriter writer, Rectangle pageSize) {
    PdfArray array = new PdfArray();
    int rotation = pageSize.getRotation() % 360;
    int currentPage = writer.getCurrentPageNumber();
    for (int k = 0; k < annotations.size(); ++k) {
        PdfAnnotation dic = (PdfAnnotation) annotations.get(k);
        int page = dic.getPlaceInPage();
        if (page > currentPage) {
            delayedAnnotations.add(dic);
            continue;
        }
        if (dic.isForm()) {
            if (!dic.isUsed()) {
                HashMap templates = dic.getTemplates();
                if (templates != null)
                    acroForm.addFieldTemplates(templates);
            }
            PdfFormField field = (PdfFormField) dic;
            if (field.getParent() == null)
                acroForm.addDocumentField(field.getIndirectReference());
        }
        if (dic.isAnnotation()) {
            array.add(dic.getIndirectReference());
            if (!dic.isUsed()) {
                PdfRectangle rect = (PdfRectangle) dic.get(PdfName.RECT);
                if (rect != null) {
                    switch(rotation) {
                        case 90:
                            dic.put(PdfName.RECT, new PdfRectangle(pageSize.getTop() - rect.bottom(), rect.left(), pageSize.getTop() - rect.top(), rect.right()));
                            break;
                        case 180:
                            dic.put(PdfName.RECT, new PdfRectangle(pageSize.getRight() - rect.left(), pageSize.getTop() - rect.bottom(), pageSize.getRight() - rect.right(), pageSize.getTop() - rect.top()));
                            break;
                        case 270:
                            dic.put(PdfName.RECT, new PdfRectangle(rect.bottom(), pageSize.getRight() - rect.left(), rect.top(), pageSize.getRight() - rect.right()));
                            break;
                    }
                }
            }
        }
        if (!dic.isUsed()) {
            dic.setUsed();
            try {
                writer.addToBody(dic, dic.getIndirectReference());
            } catch (IOException e) {
                throw new ExceptionConverter(e);
            }
        }
    }
    return array;
}
Also used : ExceptionConverter(com.lowagie.text.ExceptionConverter) PdfArray(com.lowagie.text.pdf.PdfArray) PdfFormField(com.lowagie.text.pdf.PdfFormField) HashMap(java.util.HashMap) PdfAnnotation(com.lowagie.text.pdf.PdfAnnotation) PdfRectangle(com.lowagie.text.pdf.PdfRectangle) IOException(java.io.IOException)

Aggregations

ExceptionConverter (com.lowagie.text.ExceptionConverter)4 PdfFormField (com.lowagie.text.pdf.PdfFormField)4 PdfRectangle (com.lowagie.text.pdf.PdfRectangle)4 IOException (java.io.IOException)4 DocumentException (com.lowagie.text.DocumentException)2 Rectangle (com.lowagie.text.Rectangle)2 PdfAnnotation (com.lowagie.text.pdf.PdfAnnotation)2 PdfArray (com.lowagie.text.pdf.PdfArray)2 TextField (com.lowagie.text.pdf.TextField)2 PdfObject (com.lowagie.text.pdf.PdfObject)1 PdfTemplate (com.lowagie.text.pdf.PdfTemplate)1 HashMap (java.util.HashMap)1