Java Code Examples for com.lowagie.text.Rectangle

The following examples show how to use com.lowagie.text.Rectangle. These examples are extracted from open source projects. 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 Project: unitime   Author: UniTime   File: PdfExamGridTable.java    License: Apache License 2.0 6 votes vote down vote up
public void export(OutputStream out) throws Exception {
    int nrCols = getNrColumns();
    iDocument = (iForm.getDispMode()==sDispModeInRowHorizontal || iForm.getDispMode()==sDispModeInRowVertical ?
        new Document(new Rectangle(Math.max(PageSize.LETTER.getWidth(),60.0f+100.0f*nrCols),Math.max(PageSize.LETTER.getHeight(),60.0f+150f*nrCols)).rotate(), 30, 30, 30, 30)
    :
        new Document(new Rectangle(Math.max(PageSize.LETTER.getWidth(),60.0f+100.0f*nrCols),Math.max(PageSize.LETTER.getHeight(),60.0f+150f*nrCols)), 30, 30, 30, 30));

    PdfEventHandler.initFooter(iDocument, out);
    iDocument.open();
    
    printTable();

    printLegend();

    iDocument.close();
}
 
Example #2
Source Project: itext2   Author: albfernandez   File: PdfCopy.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
void applyRotation(PdfDictionary pageN, ByteBuffer out) {
    if (!cstp.rotateContents)
        return;
    Rectangle page = reader.getPageSizeWithRotation(pageN);
    int rotation = page.getRotation();
    switch (rotation) {
        case 90:
            out.append(PdfContents.ROTATE90);
            out.append(page.getTop());
            out.append(' ').append('0').append(PdfContents.ROTATEFINAL);
            break;
        case 180:
            out.append(PdfContents.ROTATE180);
            out.append(page.getRight());
            out.append(' ');
            out.append(page.getTop());
            out.append(PdfContents.ROTATEFINAL);
            break;
        case 270:
            out.append(PdfContents.ROTATE270);
            out.append('0').append(' ');
            out.append(page.getRight());
            out.append(PdfContents.ROTATEFINAL);
            break;
    }
}
 
Example #3
Source Project: gcs   Author: richardwilkes   File: PdfAnnotation.java    License: Mozilla Public License 2.0 6 votes vote down vote up
/**
 * @param writer
 * @param rect
 * @param title
 * @param contents
 * @param open
 * @param icon
 * @return a PdfAnnotation
 */
public static PdfAnnotation createText(PdfWriter writer, Rectangle rect, String title, String contents, boolean open, String icon) {
	PdfAnnotation annot = new PdfAnnotation(writer, rect);
	annot.put(PdfName.SUBTYPE, PdfName.TEXT);
	if (title != null) {
		annot.put(PdfName.T, new PdfString(title, PdfObject.TEXT_UNICODE));
	}
	if (contents != null) {
		annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
	}
	if (open) {
		annot.put(PdfName.OPEN, PdfBoolean.PDFTRUE);
	}
	if (icon != null) {
		annot.put(PdfName.NAME, new PdfName(icon));
	}
	return annot;
}
 
Example #4
Source Project: gcs   Author: richardwilkes   File: PdfReader.java    License: Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Gets the box size. Allowed names are: "crop", "trim", "art", "bleed" and "media".
 *
 * @param index the page number. The first page is 1
 * @param boxName the box name
 * @return the box rectangle or null
 */
public Rectangle getBoxSize(int index, String boxName) {
	PdfDictionary page = pageRefs.getPageNRelease(index);
	PdfArray box = null;
	if (boxName.equals("trim")) {
		box = (PdfArray) getPdfObjectRelease(page.get(PdfName.TRIMBOX));
	} else if (boxName.equals("art")) {
		box = (PdfArray) getPdfObjectRelease(page.get(PdfName.ARTBOX));
	} else if (boxName.equals("bleed")) {
		box = (PdfArray) getPdfObjectRelease(page.get(PdfName.BLEEDBOX));
	} else if (boxName.equals("crop")) {
		box = (PdfArray) getPdfObjectRelease(page.get(PdfName.CROPBOX));
	} else if (boxName.equals("media")) {
		box = (PdfArray) getPdfObjectRelease(page.get(PdfName.MEDIABOX));
	}
	if (box == null) {
		return null;
	}
	return getNormalizedRectangle(box);
}
 
Example #5
Source Project: gcs   Author: richardwilkes   File: PdfAnnotation.java    License: Mozilla Public License 2.0 6 votes vote down vote up
public static PdfAnnotation createMarkup(PdfWriter writer, Rectangle rect, String contents, int type, float quadPoints[]) {
	PdfAnnotation annot = new PdfAnnotation(writer, rect);
	PdfName name = PdfName.HIGHLIGHT;
	switch (type) {
		case MARKUP_UNDERLINE:
			name = PdfName.UNDERLINE;
			break;
		case MARKUP_STRIKEOUT:
			name = PdfName.STRIKEOUT;
			break;
		case MARKUP_SQUIGGLY:
			name = PdfName.SQUIGGLY;
			break;
	}
	annot.put(PdfName.SUBTYPE, name);
	annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
	PdfArray array = new PdfArray();
	for (float quadPoint : quadPoints) {
		array.add(new PdfNumber(quadPoint));
	}
	annot.put(PdfName.QUADPOINTS, array);
	return annot;
}
 
Example #6
private void insertTable_ProgramStage( PdfPTable mainTable, PdfWriter writer, ProgramStage programStage )
    throws IOException, DocumentException
{
    Rectangle rectangle = new Rectangle( TEXTBOXWIDTH, PdfDataEntryFormUtil.CONTENT_HEIGHT_DEFAULT );

    // Add Program Stage Sections
    if ( programStage.getProgramStageSections().size() > 0 )
    {
        // Sectioned Ones
        for ( ProgramStageSection section : programStage.getProgramStageSections() )
        {
            insertTable_ProgramStageSections( mainTable, rectangle, writer, section.getDataElements() );
        }
    }
    else
    {
        // Default one
        insertTable_ProgramStageSections( mainTable, rectangle, writer, programStage.getDataElements() );
    }
}
 
Example #7
/**
 * Add image in the document.
 *
 * @param context
 *            PDF context
 * @param imageResult
 *            image
 * @throws BadElementException
 *             PDF construction problem
 * @throws IOException
 *             PDF construction problem
 */
protected void addImage(PdfContext context, ImageResult imageResult) throws BadElementException, IOException {
	Bbox imageBounds = imageResult.getRasterImage().getBounds();
	float scaleFactor = (float) (72 / getMap().getRasterResolution());
	float width = (float) imageBounds.getWidth() * scaleFactor;
	float height = (float) imageBounds.getHeight() * scaleFactor;
	// subtract screen position of lower-left corner
	float x = (float) (imageBounds.getX() - rasterScale * bbox.getMinX()) * scaleFactor;
	// shift y to lowerleft corner, flip y to user space and subtract
	// screen position of lower-left
	// corner
	float y = (float) (-imageBounds.getY() - imageBounds.getHeight() - rasterScale * bbox.getMinY()) * scaleFactor;
	if (log.isDebugEnabled()) {
		log.debug("adding image, width=" + width + ",height=" + height + ",x=" + x + ",y=" + y);
	}
	// opacity
	log.debug("before drawImage");
	context.drawImage(Image.getInstance(imageResult.getImage()), new Rectangle(x, y, x + width, y + height),
			getSize(), getOpacity());
	log.debug("after drawImage");
}
 
Example #8
private void drawPoint(PdfContext context, Rectangle iconRect, Color fillColor, Color strokeColor) {
	float baseWidth = iconRect.getWidth() / 10;
	SymbolInfo symbol = styleInfo.getSymbol();
	if (symbol.getImage() != null) {
		try {
			Image pointImage = Image.getInstance(symbol.getImage().getHref());
			context.drawImage(pointImage, iconRect, iconRect);
		} catch (Exception ex) { // NOSONAR
			log.error("Not able to create image for POINT Symbol", ex);
		}
	} else if (symbol.getRect() != null) {
		context.fillRectangle(iconRect, fillColor);
		context.strokeRectangle(iconRect, strokeColor, baseWidth / 2);
	} else {
		context.fillEllipse(iconRect, fillColor);
		context.strokeEllipse(iconRect, strokeColor, baseWidth / 2);
	}
}
 
Example #9
Source Project: MesquiteCore   Author: MesquiteProject   File: PdfReader.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/** Gets the box size. Allowed names are: "crop", "trim", "art", "bleed" and "media".
 * @param index the page number. The first page is 1
 * @param boxName the box name
 * @return the box rectangle or null
 */
public Rectangle getBoxSize(int index, String boxName) {
    PdfDictionary page = pageRefs.getPageNRelease(index);
    PdfArray box = null;
    if (boxName.equals("trim"))
        box = (PdfArray)getPdfObjectRelease(page.get(PdfName.TRIMBOX));
    else if (boxName.equals("art"))
        box = (PdfArray)getPdfObjectRelease(page.get(PdfName.ARTBOX));
    else if (boxName.equals("bleed"))
        box = (PdfArray)getPdfObjectRelease(page.get(PdfName.BLEEDBOX));
    else if (boxName.equals("crop"))
        box = (PdfArray)getPdfObjectRelease(page.get(PdfName.CROPBOX));
    else if (boxName.equals("media"))
        box = (PdfArray)getPdfObjectRelease(page.get(PdfName.MEDIABOX));
    if (box == null)
        return null;
    return getNormalizedRectangle(box);
}
 
Example #10
/**
 * Add image with a exception message in the PDF document.
 *
 * @param context
 *            PDF context
 * @param e
 *            exception to put in image
 */
protected void addLoadError(PdfContext context, ImageException e) {
	Bbox imageBounds = e.getRasterImage().getBounds();
	float scaleFactor = (float) (72 / getMap().getRasterResolution());
	float width = (float) imageBounds.getWidth() * scaleFactor;
	float height = (float) imageBounds.getHeight() * scaleFactor;
	// subtract screen position of lower-left corner
	float x = (float) (imageBounds.getX() - rasterScale * bbox.getMinX()) * scaleFactor;
	// shift y to lower left corner, flip y to user space and subtract
	// screen position of lower-left
	// corner
	float y = (float) (-imageBounds.getY() - imageBounds.getHeight() - rasterScale * bbox.getMinY()) * scaleFactor;
	if (log.isDebugEnabled()) {
		log.debug("adding failed message=" + width + ",height=" + height + ",x=" + x + ",y=" + y);
	}
	float textHeight = context.getTextSize("failed", ERROR_FONT).getHeight() * 3f;
	Rectangle rec = new Rectangle(x, y, x + width, y + height);
	context.strokeRectangle(rec, Color.RED, 0.5f);
	context.drawText(getNlsString("RasterLayerComponent.loaderror.line1"), ERROR_FONT, new Rectangle(x, y
			+ textHeight, x + width, y + height), Color.RED);
	context.drawText(getNlsString("RasterLayerComponent.loaderror.line2"), ERROR_FONT, rec, Color.RED);
	context.drawText(getNlsString("RasterLayerComponent.loaderror.line3"), ERROR_FONT, new Rectangle(x, y
			- textHeight, x + width, y + height), Color.RED);
}
 
Example #11
Source Project: itext2   Author: albfernandez   File: PdfReader.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/** Gets the box size. Allowed names are: "crop", "trim", "art", "bleed" and "media".
 * @param index the page number. The first page is 1
 * @param boxName the box name
 * @return the box rectangle or null
 */
public Rectangle getBoxSize(int index, String boxName) {
    PdfDictionary page = pageRefs.getPageNRelease(index);
    PdfArray box = null;
    if (boxName.equals("trim"))
        box = (PdfArray)getPdfObjectRelease(page.get(PdfName.TRIMBOX));
    else if (boxName.equals("art"))
        box = (PdfArray)getPdfObjectRelease(page.get(PdfName.ARTBOX));
    else if (boxName.equals("bleed"))
        box = (PdfArray)getPdfObjectRelease(page.get(PdfName.BLEEDBOX));
    else if (boxName.equals("crop"))
        box = (PdfArray)getPdfObjectRelease(page.get(PdfName.CROPBOX));
    else if (boxName.equals("media"))
        box = (PdfArray)getPdfObjectRelease(page.get(PdfName.MEDIABOX));
    if (box == null)
        return null;
    return getNormalizedRectangle(box);
}
 
Example #12
Source Project: itext2   Author: albfernandez   File: SimplePdfTest.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void testSimplePdf() throws FileNotFoundException, DocumentException {
	// create document
	Document document = PdfTestBase.createPdf("testSimplePdf.pdf");
	try {
		// new page with a rectangle
		document.open();
		document.newPage();
		Annotation ann = new Annotation("Title", "Text");
		Rectangle rect = new Rectangle(100, 100);
		document.add(ann);
		document.add(rect);
	} finally {
		// close document
		if (document != null)
			document.close();
	}

}
 
Example #13
Source Project: pentaho-reporting   Author: pentaho   File: PdfDocumentWriter.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public void processLogicalPage( final LogicalPageKey key, final LogicalPageBox logicalPage ) throws DocumentException {

    final float width = (float) StrictGeomUtility.toExternalValue( logicalPage.getPageWidth() );
    final float height = (float) StrictGeomUtility.toExternalValue( logicalPage.getPageHeight() );

    final Rectangle pageSize = new Rectangle( width, height );

    final Document document = getDocument();
    document.setPageSize( pageSize );
    document.setMargins( 0, 0, 0, 0 );

    if ( awaitOpenDocument ) {
      document.open();
      awaitOpenDocument = false;
    }

    final Graphics2D graphics = new PdfGraphics2D( writer.getDirectContent(), width, height, metaData );
    // and now process the box ..
    final PdfLogicalPageDrawable logicalPageDrawable = createLogicalPageDrawable( logicalPage, null );
    logicalPageDrawable.draw( graphics, new Rectangle2D.Double( 0, 0, width, height ) );

    graphics.dispose();

    document.newPage();
  }
 
Example #14
Source Project: gcs   Author: richardwilkes   File: PdfAppearance.java    License: Mozilla Public License 2.0 6 votes vote down vote up
@Override
public PdfContentByte getDuplicate() {
	PdfAppearance tpl = new PdfAppearance();
	tpl.writer = writer;
	tpl.pdf = pdf;
	tpl.thisReference = thisReference;
	tpl.pageResources = pageResources;
	tpl.bBox = new Rectangle(bBox);
	tpl.group = group;
	tpl.layer = layer;
	if (matrix != null) {
		tpl.matrix = new PdfArray(matrix);
	}
	tpl.separator = separator;
	return tpl;
}
 
Example #15
Source Project: geomajas-project-server   Author: geomajas   File: PdfContext.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Move this rectangle to the specified bottom-left point.
 *
 * @param rect rectangle to move
 * @param x new x origin
 * @param y new y origin
 */
public void moveRectangleTo(Rectangle rect, float x, float y) {
	float width = rect.getWidth();
	float height = rect.getHeight();
	rect.setLeft(x);
	rect.setBottom(y);
	rect.setRight(rect.getLeft() + width);
	rect.setTop(rect.getBottom() + height);
}
 
Example #16
Source Project: itext2   Author: albfernandez   File: PdfTestBase.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Document createPdf(OutputStream out) throws DocumentException {
	// create a new document
	Rectangle rec = new Rectangle(PageSize.A4.getWidth(),
			PageSize.A4.getHeight());
	Document document = new Document(rec);

	// create a new file
	

	// generate file
	PdfWriter.getInstance(document, out);
	return document;
}
 
Example #17
Source Project: gcs   Author: richardwilkes   File: PdfAnnotation.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Creates a link.
 * 
 * @param writer
 * @param rect
 * @param highlight
 * @return A PdfAnnotation
 */
protected static PdfAnnotation createLink(PdfWriter writer, Rectangle rect, PdfName highlight) {
	PdfAnnotation annot = new PdfAnnotation(writer, rect);
	annot.put(PdfName.SUBTYPE, PdfName.LINK);
	if (!highlight.equals(HIGHLIGHT_INVERT)) {
		annot.put(PdfName.H, highlight);
	}
	return annot;
}
 
Example #18
Source Project: rapidminer-studio   Author: rapidminer   File: ImageExporter.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
private void exportVectorGraphics(String formatName, File outputFile) throws ImageExportException {
	Component component = printableComponent.getExportComponent();
	int width = component.getWidth();
	int height = component.getHeight();
	try (FileOutputStream fs = new FileOutputStream(outputFile)) {
		switch (formatName) {
			case PDF:
				// create pdf document with slightly increased width and height
				// (otherwise the image gets cut off)
				Document document = new Document(new Rectangle(width + 5, height + 5));
				PdfWriter writer = PdfWriter.getInstance(document, fs);
				document.open();
				PdfContentByte cb = writer.getDirectContent();
				PdfTemplate tp = cb.createTemplate(width, height);
				Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper());
				component.print(g2);
				g2.dispose();
				cb.addTemplate(tp, 0, 0);
				document.close();
				break;
			case SVG:
				exportFreeHep(component, fs, new SVGGraphics2D(fs, new Dimension(width, height)));
				break;
			case EPS:
				exportFreeHep(component, fs, new PSGraphics2D(fs, new Dimension(width, height)));
				break;
			default:
				// cannot happen
				break;
		}
	} catch (Exception e) {
		throw new ImageExportException(I18N.getMessage(I18N.getUserErrorMessagesBundle(),
				"error.image_export.export_failed"), e);
	}
}
 
Example #19
Source Project: itext2   Author: albfernandez   File: FieldPositioningEvents.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
 */
public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvases) {
	if (cellField == null || (fieldWriter == null && parent == null)) throw new ExceptionConverter(new IllegalArgumentException("You have used the wrong constructor for this FieldPositioningEvents class."));
	cellField.put(PdfName.RECT, new PdfRectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)));
	if (parent == null)
		fieldWriter.addAnnotation(cellField);
	else
		parent.addKid(cellField);
}
 
Example #20
Source Project: itext2   Author: albfernandez   File: PdfReader.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Gets the rotated page from a page dictionary.
 * @param page the page dictionary
 * @return the rotated page
 */
public Rectangle getPageSizeWithRotation(PdfDictionary page) {
    Rectangle rect = getPageSize(page);
    int rotation = getPageRotation(page);
    while (rotation > 0) {
        rect = rect.rotate();
        rotation -= 90;
    }
    return rect;
}
 
Example #21
Source Project: gcs   Author: richardwilkes   File: PdfAnnotation.java    License: Mozilla Public License 2.0 5 votes vote down vote up
public static PdfAnnotation createInk(PdfWriter writer, Rectangle rect, String contents, float inkList[][]) {
	PdfAnnotation annot = new PdfAnnotation(writer, rect);
	annot.put(PdfName.SUBTYPE, PdfName.INK);
	annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
	PdfArray outer = new PdfArray();
	for (float[] deep : inkList) {
		PdfArray inner = new PdfArray();
		for (float element : deep) {
			inner.add(new PdfNumber(element));
		}
		outer.add(inner);
	}
	annot.put(PdfName.INKLIST, outer);
	return annot;
}
 
Example #22
Source Project: geomajas-project-server   Author: geomajas   File: PrintComponentImpl.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Calculates the size based constraint width and height if present, otherwise from children sizes.
 */
public void calculateSize(PdfContext context) {
	float width = 0;
	float height = 0;
	for (PrintComponent<?> child : children) {
		child.calculateSize(context);
		float cw = child.getBounds().getWidth() + 2 * child.getConstraint().getMarginX();
		float ch = child.getBounds().getHeight() + 2 * child.getConstraint().getMarginY();
		switch (getConstraint().getFlowDirection()) {
			case LayoutConstraint.FLOW_NONE:
				width = Math.max(width, cw);
				height = Math.max(height, ch);
				break;
			case LayoutConstraint.FLOW_X:
				width += cw;
				height = Math.max(height, ch);
				break;
			case LayoutConstraint.FLOW_Y:
				width = Math.max(width, cw);
				height += ch;
				break;
			default:
				throw new IllegalStateException("Unknown flow direction " + getConstraint().getFlowDirection());
		}
	}
	if (getConstraint().getWidth() != 0) {
		width = getConstraint().getWidth();
	}
	if (getConstraint().getHeight() != 0) {
		height = getConstraint().getHeight();
	}
	setBounds(new Rectangle(0, 0, width, height));
}
 
Example #23
Source Project: gcs   Author: richardwilkes   File: PdfAnnotation.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Adds a popup to your document.
 * 
 * @param writer
 * @param rect
 * @param contents
 * @param open
 * @return A PdfAnnotation
 */
public static PdfAnnotation createPopup(PdfWriter writer, Rectangle rect, String contents, boolean open) {
	PdfAnnotation annot = new PdfAnnotation(writer, rect);
	annot.put(PdfName.SUBTYPE, PdfName.POPUP);
	if (contents != null) {
		annot.put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
	}
	if (open) {
		annot.put(PdfName.OPEN, PdfBoolean.PDFTRUE);
	}
	return annot;
}
 
Example #24
Source Project: kfs   Author: kuali   File: CashReceiptCoverSheetServiceImpl.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Responsible for creating a new PDF page and workspace through <code>{@link PdfContentByte}</code> for direct writing to the
 * PDF.
 *
 * @param writer The PDF writer used to write to the new page with.
 * @param reader The PDF reader used to read information from the PDF file.
 * @param pageNumber The current number of pages in the PDF file, which will be incremented by one inside this method.
 *
 * @return The PDFContentByte used to access the new PDF page.
 * @exception DocumentException
 * @exception IOException
 */
protected PdfContentByte startNewPage(PdfWriter writer, PdfReader reader, ModifiableInteger pageNumber) throws DocumentException, IOException {
    PdfContentByte retval;
    PdfContentByte under;
    Rectangle pageSize;
    Document pdfDoc;
    PdfImportedPage newPage;

    pageNumber.increment();
    pageSize = reader.getPageSize(FRONT_PAGE);
    retval = writer.getDirectContent();
    // under = writer.getDirectContentUnder();

    if (pageNumber.getInt() > FRONT_PAGE) {
        newPage = writer.getImportedPage(reader, CHECK_PAGE_NORMAL);
        setCurrentRenderingYPosition(pageSize.top(TOP_MARGIN + CHECK_DETAIL_HEADING_HEIGHT));
    }
    else {
        newPage = writer.getImportedPage(reader, FRONT_PAGE);
        setCurrentRenderingYPosition(pageSize.top(TOP_FIRST_PAGE));
    }

    pdfDoc = retval.getPdfDocument();
    pdfDoc.newPage();
    retval.addTemplate(newPage, 0, 0);
    retval.setFontAndSize(getTextFont(), 8);

    return retval;
}
 
Example #25
Source Project: gcs   Author: richardwilkes   File: PdfPTable.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Sets the percentage width of the table from the absolute column width.
 * 
 * @param columnWidth the absolute width of each column
 * @param pageSize the page size
 * @throws DocumentException
 */
public void setWidthPercentage(float columnWidth[], Rectangle pageSize) throws DocumentException {
	if (columnWidth.length != getNumberOfColumns()) {
		throw new IllegalArgumentException("Wrong number of columns.");
	}
	float totalWidth = 0;
	for (float element : columnWidth) {
		totalWidth += element;
	}
	widthPercentage = totalWidth / (pageSize.getRight() - pageSize.getLeft()) * 100f;
	setWidths(columnWidth);
}
 
Example #26
Source Project: gcs   Author: richardwilkes   File: PdfStamperImp.java    License: Mozilla Public License 2.0 5 votes vote down vote up
void applyRotation(PdfDictionary pageN, ByteBuffer out) {
	if (!rotateContents) {
		return;
	}
	Rectangle page = reader.getPageSizeWithRotation(pageN);
	int rotation = page.getRotation();
	switch (rotation) {
		case 90:
			out.append(PdfContents.ROTATE90);
			out.append(page.getTop());
			out.append(' ').append('0').append(PdfContents.ROTATEFINAL);
			break;
		case 180:
			out.append(PdfContents.ROTATE180);
			out.append(page.getRight());
			out.append(' ');
			out.append(page.getTop());
			out.append(PdfContents.ROTATEFINAL);
			break;
		case 270:
			out.append(PdfContents.ROTATE270);
			out.append('0').append(' ');
			out.append(page.getRight());
			out.append(PdfContents.ROTATEFINAL);
			break;
	}
}
 
Example #27
Source Project: MesquiteCore   Author: MesquiteProject   File: PdfReader.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/** Normalizes a <CODE>Rectangle</CODE> so that llx and lly are smaller than urx and ury.
 * @param box the original rectangle
 * @return a normalized <CODE>Rectangle</CODE>
 */    
public static Rectangle getNormalizedRectangle(PdfArray box) {
    ArrayList rect = box.getArrayList();
    float llx = ((PdfNumber)rect.get(0)).floatValue();
    float lly = ((PdfNumber)rect.get(1)).floatValue();
    float urx = ((PdfNumber)rect.get(2)).floatValue();
    float ury = ((PdfNumber)rect.get(3)).floatValue();
    return new Rectangle(Math.min(llx, urx), Math.min(lly, ury),
    Math.max(llx, urx), Math.max(lly, ury));
}
 
Example #28
Source Project: itext2   Author: albfernandez   File: PdfDocument.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Sets the pagesize.
 *
 * @param pageSize the new pagesize
 * @return <CODE>true</CODE> if the page size was set
 */
public boolean setPageSize(Rectangle pageSize) {
    if (writer != null && writer.isPaused()) {
        return false;
    }
    nextPageSize = new Rectangle(pageSize);
    return true;
}
 
Example #29
Source Project: MesquiteCore   Author: MesquiteProject   File: PdfAcroForm.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @param radiogroup
 * @param value
 * @param llx
 * @param lly
 * @param urx
 * @param ury
 * @return a PdfFormField
 */
public PdfFormField addRadioButton(PdfFormField radiogroup, String value, float llx, float lly, float urx, float ury) {
    PdfFormField radio = PdfFormField.createEmpty(writer);
    radio.setWidget(new Rectangle(llx, lly, urx, ury), PdfAnnotation.HIGHLIGHT_TOGGLE);
    String name = ((PdfName)radiogroup.get(PdfName.V)).toString().substring(1);
    if (name.equals(value)) {
        radio.setAppearanceState(value);
    }
    else {
        radio.setAppearanceState("Off");
    }
    drawRadioAppearences(radio, value, llx, lly, urx, ury);
    radiogroup.addKid(radio);
    return radio;
}
 
Example #30
@Override
public void generatePDFDataEntryForm( Document document, PdfWriter writer, String dataSetUid, int typeId,
    Rectangle pageSize, PdfFormFontSettings pdfFormFontSettings, I18nFormat format )
{
    try
    {
        this.pdfFormFontSettings = pdfFormFontSettings;
        this.format = format;

        document.setPageSize( pageSize );

        document.open();

        if ( typeId == PdfDataEntryFormUtil.DATATYPE_DATASET )
        {
            setDataSet_DocumentContent( document, writer, dataSetUid );
        }
        else if ( typeId == PdfDataEntryFormUtil.DATATYPE_PROGRAMSTAGE )
        {
            setProgramStage_DocumentContent( document, writer, dataSetUid );
        }
    }
    catch ( Exception ex )
    {
        throw new RuntimeException( ex );
    }
    finally
    {
        document.close();
    }
}