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