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;
}
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);
}
}
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);
}
}
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;
}
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);
}
}
Aggregations