Search in sources :

Example 1 with ExceptionConverter

use of pdftk.com.lowagie.text.ExceptionConverter in project staplr by pridiltal.

the class PdfDocument method rotateAnnotations.

protected PdfArray rotateAnnotations() throws DocumentException {
    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)
                    getAcroForm().addFieldTemplates(templates);
            }
            PdfFormField field = (PdfFormField) dic;
            if (field.getParent() == null)
                getAcroForm().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.top() - rect.bottom(), rect.left(), pageSize.top() - rect.top(), rect.right()));
                            break;
                        case 180:
                            dic.put(PdfName.RECT, new PdfRectangle(pageSize.right() - rect.left(), pageSize.top() - rect.bottom(), pageSize.right() - rect.right(), pageSize.top() - rect.top()));
                            break;
                        case 270:
                            dic.put(PdfName.RECT, new PdfRectangle(rect.bottom(), pageSize.right() - rect.left(), rect.top(), pageSize.right() - 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(pdftk.com.lowagie.text.ExceptionConverter) HashMap(java.util.HashMap) IOException(java.io.IOException)

Example 2 with ExceptionConverter

use of pdftk.com.lowagie.text.ExceptionConverter in project staplr by pridiltal.

the class PdfDocument method ensureNewLine.

/**
 * Ensures that a new line has been started.
 */
private void ensureNewLine() {
    try {
        if ((lastElementType == Element.PHRASE) || (lastElementType == Element.CHUNK)) {
            newLine();
            flushLines();
        }
    } catch (DocumentException ex) {
        throw new ExceptionConverter(ex);
    }
}
Also used : ExceptionConverter(pdftk.com.lowagie.text.ExceptionConverter) DocumentException(pdftk.com.lowagie.text.DocumentException)

Example 3 with ExceptionConverter

use of pdftk.com.lowagie.text.ExceptionConverter in project staplr by pridiltal.

the class PdfDocument method open.

// methods to open and close a document
/**
 * Opens the document.
 * <P>
 * You have to open the document before you can begin to add content
 * to the body of the document.
 */
public void open() {
    if (!open) {
        super.open();
        writer.open();
        rootOutline = new PdfOutline(writer);
        currentOutline = rootOutline;
    }
    try {
        initPage();
    } catch (DocumentException de) {
        throw new ExceptionConverter(de);
    }
}
Also used : ExceptionConverter(pdftk.com.lowagie.text.ExceptionConverter) DocumentException(pdftk.com.lowagie.text.DocumentException)

Example 4 with ExceptionConverter

use of pdftk.com.lowagie.text.ExceptionConverter in project staplr by pridiltal.

the class PdfDocument method getCatalog.

/**
 * Gets the <CODE>PdfCatalog</CODE>-object.
 *
 * @param pages an indirect reference to this document pages
 * @return <CODE>PdfCatalog</CODE>
 */
PdfCatalog getCatalog(PdfIndirectReference pages) throws DocumentException {
    PdfCatalog catalog;
    if (rootOutline.getKids().size() > 0) {
        catalog = new PdfCatalog(pages, rootOutline.indirectReference(), writer);
    } else
        catalog = new PdfCatalog(pages, writer);
    if (openActionName != null) {
        PdfAction action = getLocalGotoAction(openActionName);
        catalog.setOpenAction(action);
    } else if (openActionAction != null)
        catalog.setOpenAction(openActionAction);
    if (additionalActions != null) {
        catalog.setAdditionalActions(additionalActions);
    }
    if (pageLabels != null)
        catalog.setPageLabels(pageLabels);
    catalog.addNames(localDestinations, documentJavaScript, writer);
    // ssteward: debug; catalog.setViewerPreferences(viewerPreferences);
    if (getAcroForm().isValid()) {
        try {
            catalog.setAcroForm(writer.addToBody(acroForm).getIndirectReference());
        } catch (IOException e) {
            throw new ExceptionConverter(e);
        }
    }
    return catalog;
}
Also used : ExceptionConverter(pdftk.com.lowagie.text.ExceptionConverter) IOException(java.io.IOException)

Example 5 with ExceptionConverter

use of pdftk.com.lowagie.text.ExceptionConverter in project staplr by pridiltal.

the class PdfCopyFieldsImp method getCatalog.

protected PdfDictionary getCatalog(PdfIndirectReference rootObj) throws DocumentException {
    try {
        // ssteward
        PdfDictionary cat = this.getPdfDocument().getCatalog(rootObj);
        if (form != null) {
            PdfIndirectReference ref = addToBody(form).getIndirectReference();
            cat.put(PdfName.ACROFORM, ref);
        }
        if (newBookmarks == null || newBookmarks.size() == 0)
            return cat;
        PdfDictionary top = new PdfDictionary();
        PdfIndirectReference topRef = getPdfIndirectReference();
        Object[] kids = SimpleBookmark.iterateOutlines(this, topRef, newBookmarks, false);
        top.put(PdfName.FIRST, (PdfIndirectReference) kids[0]);
        top.put(PdfName.LAST, (PdfIndirectReference) kids[1]);
        top.put(PdfName.COUNT, new PdfNumber(((Integer) kids[2]).intValue()));
        addToBody(top, topRef);
        cat.put(PdfName.OUTLINES, topRef);
        return cat;
    } catch (IOException e) {
        throw new ExceptionConverter(e);
    }
}
Also used : ExceptionConverter(pdftk.com.lowagie.text.ExceptionConverter) IOException(java.io.IOException)

Aggregations

ExceptionConverter (pdftk.com.lowagie.text.ExceptionConverter)46 IOException (java.io.IOException)34 DocumentException (pdftk.com.lowagie.text.DocumentException)17 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 SignatureException (java.security.SignatureException)5 InvalidKeyException (java.security.InvalidKeyException)4 NoSuchProviderException (java.security.NoSuchProviderException)4 CRLException (java.security.cert.CRLException)4 CertificateException (java.security.cert.CertificateException)4 ArrayList (java.util.ArrayList)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)3 ASN1OutputStream (org.bouncycastle.asn1.ASN1OutputStream)3 DEROctetString (org.bouncycastle.asn1.DEROctetString)3 DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)3 Color (java.awt.Color)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2