Java Code Examples for com.lowagie.text.pdf.PdfWriter#getCurrentPageNumber()

The following examples show how to use com.lowagie.text.pdf.PdfWriter#getCurrentPageNumber() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PdfAnnotationsImp.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
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;
}
 
Example 2
Source File: PdfAnnotationsImp.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
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;
}