List of usage examples for org.apache.pdfbox.pdmodel.common PDRectangle getHeight
public float getHeight()
From source file:airviewer.AnnotationGenerator.java
/** * * @param a/*from w w w .j ava 2s.c om*/ * @param d * @param p * @param shouldResize * @return */ public static PDAppearanceStream generateSquareAppearance(PDAnnotation a, PDDocument d, PDPage p, boolean shouldResize) { assert null != a; assert null != d; assert null != p; PDAppearanceStream annotationAppearanceStream = null; try { if (shouldResize) { resizeAnnotationToContent(a); } final String contents = a.getContents(); final boolean hasContents = null != contents && 0 < contents.length(); float borderWidth = 0; if (a instanceof PDAnnotationMarkup) { final PDBorderStyleDictionary borderStyle = ((PDAnnotationMarkup) a).getBorderStyle(); if (null != a.getColor() && null != borderStyle) { borderWidth = Math.abs(borderStyle.getWidth()); } } final float fontSize = FONT_SIZE_PDF_POINTS; final float textHeight = fontSize; final float margin = MARGIN_SIZE_PDF_POINTS; PDRectangle position = a.getRectangle(); final float lowerLeftX = position.getLowerLeftX(); final float lowerLeftY = position.getLowerLeftY(); float width = position.getWidth(); float height = position.getHeight(); annotationAppearanceStream = new PDAppearanceStream(d); annotationAppearanceStream.setBBox(position); annotationAppearanceStream.setMatrix(new AffineTransform()); annotationAppearanceStream.setResources(p.getResources()); try (PDPageContentStream appearanceContent = new PDPageContentStream(d, annotationAppearanceStream)) { appearanceContent.transform(new Matrix()); // Identity transform // Rect is inset by half border width to prevent border leaking // outside bounding box final float insetLowerLeftX = lowerLeftX + borderWidth * 0.5f; final float insetLowerLeftY = lowerLeftY + borderWidth * 0.5f; final float insetWidth = width - borderWidth; final float insetheight = height - borderWidth; appearanceContent.addRect(insetLowerLeftX, insetLowerLeftY, insetWidth, insetheight); appearanceContent.setLineWidth(borderWidth); appearanceContent.setNonStrokingColor(GRAY); if (null != a.getColor() && 0 < borderWidth) { appearanceContent.setStrokingColor(a.getColor()); appearanceContent.fillAndStroke(); } else { appearanceContent.fill(); } if (hasContents) { appearanceContent.moveTo(0, 0); appearanceContent.beginText(); // Center vertically, left justified inside border with margin appearanceContent.newLineAtOffset(lowerLeftX + borderWidth + margin, lowerLeftY + (height + LINE_SPACE_SIZE_PDF_POINTS) * 0.5f - textHeight * 0.5f); appearanceContent.setFont(FONT, fontSize); if (null != a.getColor()) { appearanceContent.setNonStrokingColor(a.getColor()); // Sets color of text } else { appearanceContent.setNonStrokingColor(BLACK); // Sets color of text } appearanceContent.showText(a.getContents()); appearanceContent.endText(); } } } catch (IOException ex) { Logger.getLogger(AnnotationGenerator.class.getName()).log(Level.SEVERE, null, ex); } return annotationAppearanceStream; }
From source file:airviewer.AnnotationGenerator.java
/** * * @param a/*w w w .j a v a 2 s .c o m*/ * @param d * @param p * @param shouldResize * @return */ public static PDAppearanceStream generateCircleAppearance(PDAnnotation a, PDDocument d, PDPage p, boolean shouldResize) { assert null != a; assert null != d; assert null != p; PDAppearanceStream annotationAppearanceStream = null; try { if (shouldResize) { resizeAnnotationToContent(a); } final String contents = a.getContents(); final boolean hasContents = null != contents && 0 < contents.length(); float borderWidth = 0; if (a instanceof PDAnnotationMarkup) { final PDBorderStyleDictionary borderStyle = ((PDAnnotationMarkup) a).getBorderStyle(); if (null != a.getColor() && null != borderStyle) { borderWidth = Math.abs(borderStyle.getWidth()); } } final float fontSize = FONT_SIZE_PDF_POINTS; final float textHeight = fontSize; final float margin = MARGIN_SIZE_PDF_POINTS; PDRectangle position = a.getRectangle(); final float lowerLeftX = position.getLowerLeftX(); final float lowerLeftY = position.getLowerLeftY(); float width = position.getWidth(); float height = position.getHeight(); annotationAppearanceStream = new PDAppearanceStream(d); annotationAppearanceStream.setBBox(position); annotationAppearanceStream.setMatrix(new AffineTransform()); annotationAppearanceStream.setResources(p.getResources()); try (PDPageContentStream appearanceContent = new PDPageContentStream(d, annotationAppearanceStream)) { appearanceContent.transform(new Matrix()); // Identity transform // Rect is inset by half border width to prevent border leaking // outside bounding box final float insetLowerLeftX = lowerLeftX + borderWidth * 0.5f; final float insetLowerLeftY = lowerLeftY + borderWidth * 0.5f; final float insetWidth = width - borderWidth; final float insetheight = height - borderWidth; if (null != a.getColor()) { appearanceContent.setLineWidth(borderWidth); appearanceContent.moveTo(insetLowerLeftX, insetLowerLeftY + insetheight * 0.5f); appearanceContent.curveTo(insetLowerLeftX, insetLowerLeftY + insetheight * 0.75f, insetLowerLeftX + insetWidth * 0.25f, insetLowerLeftY + insetheight, insetLowerLeftX + insetWidth * 0.5f, insetLowerLeftY + insetheight); appearanceContent.curveTo(insetLowerLeftX + insetWidth * 0.75f, insetLowerLeftY + insetheight, insetLowerLeftX + insetWidth, insetLowerLeftY + insetheight * 0.75f, insetLowerLeftX + insetWidth, insetLowerLeftY + insetheight * 0.5f); appearanceContent.curveTo(insetLowerLeftX + insetWidth, insetLowerLeftY + insetheight * 0.25f, insetLowerLeftX + insetWidth * 0.75f, insetLowerLeftY, insetLowerLeftX + insetWidth * 0.5f, insetLowerLeftY); appearanceContent.curveTo(insetLowerLeftX + insetWidth * 0.25f, insetLowerLeftY, insetLowerLeftX, insetLowerLeftY + insetheight * 0.25f, insetLowerLeftX, insetLowerLeftY + insetheight * 0.5f); } appearanceContent.setNonStrokingColor(GRAY); if (null != a.getColor() && 0 < borderWidth) { appearanceContent.setStrokingColor(a.getColor()); appearanceContent.fillAndStroke(); } else { appearanceContent.fill(); } if (hasContents) { appearanceContent.moveTo(0, 0); appearanceContent.beginText(); // Center text vertically, left justified inside border with margin appearanceContent.newLineAtOffset(lowerLeftX + borderWidth + margin, lowerLeftY + (height + LINE_SPACE_SIZE_PDF_POINTS) * 0.5f - textHeight * 0.5f); appearanceContent.setFont(FONT, fontSize); appearanceContent.setNonStrokingColor(BLACK); // Sets color of text appearanceContent.showText(a.getContents()); appearanceContent.endText(); } } } catch (IOException ex) { Logger.getLogger(AnnotationGenerator.class.getName()).log(Level.SEVERE, null, ex); } return annotationAppearanceStream; }
From source file:at.asitplus.regkassen.core.modules.print.SimplePDFPrinterModule.java
License:Apache License
@Override public byte[] printReceipt(final ReceiptPackage receiptPackage, final ReceiptPrintType receiptPrintType) { //TODO Training/Storno! try {// w w w.j ava 2 s . co m //init PDF document final PDDocument document = new PDDocument(); final PDPage page = new PDPage(PDPage.PAGE_SIZE_A6); document.addPage(page); //init content objects final PDRectangle rect = page.getMediaBox(); final PDPageContentStream cos = new PDPageContentStream(document, page); //add taxtype-sums int line = 1; //get string that will be encoded as QR-Code final String qrCodeRepresentation = CashBoxUtils.getQRCodeRepresentationFromJWSCompactRepresentation( receiptPackage.getJwsCompactRepresentation()); addTaxTypeToPDF(cos, rect, line++, CashBoxUtils.getValueFromMachineCode(qrCodeRepresentation, MachineCodeValue.SUM_TAX_SET_NORMAL), TaxType.SATZ_NORMAL); addTaxTypeToPDF(cos, rect, line++, CashBoxUtils.getValueFromMachineCode(qrCodeRepresentation, MachineCodeValue.SUM_TAX_SET_ERMAESSIGT1), TaxType.SATZ_ERMAESSIGT_1); addTaxTypeToPDF(cos, rect, line++, CashBoxUtils.getValueFromMachineCode(qrCodeRepresentation, MachineCodeValue.SUM_TAX_SET_ERMAESSIGT2), TaxType.SATZ_ERMAESSIGT_2); addTaxTypeToPDF(cos, rect, line++, CashBoxUtils.getValueFromMachineCode(qrCodeRepresentation, MachineCodeValue.SUM_TAX_SET_BESONDERS), TaxType.SATZ_BESONDERS); addTaxTypeToPDF(cos, rect, line++, CashBoxUtils.getValueFromMachineCode(qrCodeRepresentation, MachineCodeValue.SUM_TAX_SET_NULL), TaxType.SATZ_NULL); final String signatureValue = CashBoxUtils.getValueFromMachineCode(qrCodeRepresentation, MachineCodeValue.SIGNATURE_VALUE); final String decodedSignatureValue = new String(CashBoxUtils.base64Decode(signatureValue, false)); final boolean secDeviceWasDamaged = "Sicherheitseinrichtung ausgefallen".equals(decodedSignatureValue); if (secDeviceWasDamaged) { final PDFont fontPlain = PDType1Font.HELVETICA; cos.beginText(); cos.setFont(fontPlain, 8); cos.moveTextPositionByAmount(20, rect.getHeight() - 20 * (line)); cos.drawString("SICHERHEITSEINRICHTUNG AUSGEFALLEN"); cos.endText(); line++; } //add OCR code or QR-code if (receiptPrintType == ReceiptPrintType.OCR) { addOCRCodeToPDF(document, cos, rect, line++, receiptPackage); } else { //create QRCode final BufferedImage image = createQRCode(receiptPackage); //add QRCode to PDF document final PDXObjectImage ximage = new PDPixelMap(document, image); final float scale = 2f; // alter this value to set the image size cos.drawXObject(ximage, 25, 0, ximage.getWidth() * scale, ximage.getHeight() * scale); } cos.close(); final ByteArrayOutputStream bOut = new ByteArrayOutputStream(); document.save(bOut); document.close(); return bOut.toByteArray(); } catch (final IOException e) { e.printStackTrace(); } catch (final COSVisitorException e) { e.printStackTrace(); } return null; }
From source file:at.asitplus.regkassen.core.modules.print.SimplePDFPrinterModule.java
License:Apache License
protected void addTaxTypeToPDF(final PDPageContentStream cos, final PDRectangle rect, final int line, final String sum, final TaxType taxType) { final PDFont fontPlain = PDType1Font.HELVETICA; try {//w w w . j av a 2 s . c om cos.beginText(); cos.setFont(fontPlain, 8); cos.moveTextPositionByAmount(20, rect.getHeight() - 20 * (line)); cos.drawString(taxType.getTaxTypeString() + ": " + sum); cos.endText(); } catch (final IOException e) { e.printStackTrace(); } }
From source file:at.asitplus.regkassen.core.modules.print.SimplePDFPrinterModule.java
License:Apache License
protected void addOCRCodeToPDF(final PDDocument doc, final PDPageContentStream cos, final PDRectangle rect, int line, final ReceiptPackage receiptPackage) { try {// w w w.j a va 2 s . c o m //load OCR-A font final InputStream inputStreamAFM = this.getClass().getClassLoader().getResourceAsStream("OCRA.afm"); final InputStream inputStreamPFB = this.getClass().getClassLoader().getResourceAsStream("OCRA.pfb"); final PDFont font = new PDType1AfmPfbFont(doc, inputStreamAFM, inputStreamPFB); //get machine code as OCR representation String ocrRepresentation = CashBoxUtils.getOCRCodeRepresentationFromJWSCompactRepresentation( receiptPackage.getJwsCompactRepresentation()); //print OCR rep to PDF document final int CHARS_PER_LINE = 40; int index = 0; while (index >= 0) { String partOCR; if (ocrRepresentation.length() > CHARS_PER_LINE) { partOCR = ocrRepresentation.substring(0, CHARS_PER_LINE); ocrRepresentation = ocrRepresentation.substring(CHARS_PER_LINE); } else { partOCR = ocrRepresentation.substring(0); index = -1; } cos.beginText(); cos.setFont(font, 8); cos.moveTextPositionByAmount(20, rect.getHeight() - 20 * (line)); cos.drawString(partOCR); cos.endText(); line++; } } catch (final IOException e) { e.printStackTrace(); } }
From source file:at.gv.egiz.pdfas.lib.impl.pdfbox.positioning.Positioning.java
License:EUPL
/** * Sets the width of the table according to the layout of the document and * calculates the y position where the PDFPTable should be placed. * * @param pdfDataSource//from w ww.j av a2s . co m * The PDF document. * @param pdf_table * The PDFPTable to be placed. * @return Returns the position where the PDFPTable should be placed. * @throws PdfAsException * F.e. */ public static PositioningInstruction adjustSignatureTableandCalculatePosition(final PDDocument pdfDataSource, IPDFVisualObject pdf_table, TablePos pos, boolean legacy32, boolean legacy40) throws PdfAsException { PdfBoxUtils.checkPDFPermissions(pdfDataSource); // get pages of currentdocument int doc_pages = pdfDataSource.getNumberOfPages(); int page = doc_pages; boolean make_new_page = pos.isNewPage(); if (!(pos.isNewPage() || pos.isPauto())) { // we should posit signaturtable on this page page = pos.getPage(); // System.out.println("XXXXPAGE="+page+" doc_pages="+doc_pages); if (page > doc_pages) { make_new_page = true; page = doc_pages; // throw new PDFDocumentException(227, "Page number is to big(=" // + page+ // ") cannot be parsed."); } } PDPage pdPage = (PDPage) pdfDataSource.getDocumentCatalog().getAllPages().get(page - 1); PDRectangle cropBox = pdPage.getCropBox(); // fallback to MediaBox if Cropbox not available! if (cropBox == null) { cropBox = pdPage.findCropBox(); } if (cropBox == null) { cropBox = pdPage.findMediaBox(); } // getPagedimensions // Rectangle psize = reader.getPageSizeWithRotation(page); // int page_rotation = reader.getPageRotation(page); // Integer rotation = pdPage.getRotation(); // int page_rotation = rotation.intValue(); int rotation = pdPage.findRotation(); logger.debug("Original CropBox: " + cropBox.toString()); cropBox = rotateBox(cropBox, rotation); logger.debug("Rotated CropBox: " + cropBox.toString()); float page_width = cropBox.getWidth(); float page_height = cropBox.getHeight(); logger.debug("CropBox width: " + page_width); logger.debug("CropBox heigth: " + page_height); // now we can calculate x-position float pre_pos_x = SIGNATURE_MARGIN_HORIZONTAL; if (!pos.isXauto()) { // we do have absolute x pre_pos_x = pos.getPosX(); } // calculate width // center float pre_width = page_width - 2 * pre_pos_x; if (!pos.isWauto()) { // we do have absolute width pre_width = pos.getWidth(); if (pos.isXauto()) { // center x pre_pos_x = (page_width - pre_width) / 2; } } final float pos_x = pre_pos_x; final float width = pre_width; // Signatur table dimensions are complete pdf_table.setWidth(width); pdf_table.fixWidth(); // pdf_table.setTotalWidth(width); // pdf_table.setLockedWidth(true); final float table_height = pdf_table.getHeight(); // now check pos_y float pos_y = pos.getPosY(); // in case an absolute y position is already given OR // if the table is related to an invisible signature // there is no need for further calculations // (fixed adding new page in case of invisible signatures) if (!pos.isYauto() || table_height == 0) { // we do have y-position too --> all parameters but page ok if (make_new_page) { page++; } return new PositioningInstruction(make_new_page, page, pos_x, pos_y, pos.rotation); } // pos_y is auto if (make_new_page) { // ignore footer in new page page++; pos_y = page_height - SIGNATURE_MARGIN_VERTICAL; return new PositioningInstruction(make_new_page, page, pos_x, pos_y, pos.rotation); } // up to here no checks have to be made if Tablesize and Pagesize are // fit // Now we have to getfreespace in page and reguard footerline float footer_line = pos.getFooterLine(); float pre_page_length = PDFUtilities.calculatePageLength(pdfDataSource, page - 1, page_height - footer_line, /* page_rotation, */ legacy32, legacy40); if (pre_page_length == Float.NEGATIVE_INFINITY) { // we do have an empty page or nothing in area above footerline pre_page_length = page_height; // no text --> SIGNATURE_BORDER pos_y = page_height - SIGNATURE_MARGIN_VERTICAL; if (pos_y - footer_line <= table_height) { make_new_page = true; if (!pos.isPauto()) { // we have to correct pagenumber page = pdfDataSource.getNumberOfPages(); } page++; // no text --> SIGNATURE_BORDER pos_y = page_height - SIGNATURE_MARGIN_VERTICAL; } return new PositioningInstruction(make_new_page, page, pos_x, pos_y, pos.rotation); } final float page_length = pre_page_length; // we do have text take SIGNATURE_MARGIN pos_y = page_height - page_length - SIGNATURE_MARGIN_VERTICAL; if (pos_y - footer_line <= table_height) { make_new_page = true; if (!pos.isPauto()) { // we have to correct pagenumber in case of absolute page and // not enough // space page = pdfDataSource.getNumberOfPages(); } page++; // no text --> SIGNATURE_BORDER pos_y = page_height - SIGNATURE_MARGIN_VERTICAL; } return new PositioningInstruction(make_new_page, page, pos_x, pos_y, pos.rotation); }
From source file:at.gv.egiz.pdfas.lib.impl.pdfbox2.positioning.Positioning.java
License:EUPL
/** * Sets the width of the table according to the layout of the document and * calculates the y position where the PDFPTable should be placed. * * @param pdfDataSource//ww w . j a v a 2 s. co m * The PDF document. * @param pdf_table * The PDFPTable to be placed. * @param settings * @return Returns the position where the PDFPTable should be placed. * @throws PdfAsException * F.e. */ public static PositioningInstruction adjustSignatureTableandCalculatePosition(final PDDocument pdfDataSource, IPDFVisualObject pdf_table, TablePos pos, ISettings settings) throws PdfAsException { PdfBoxUtils.checkPDFPermissions(pdfDataSource); // get pages of currentdocument int doc_pages = pdfDataSource.getNumberOfPages(); int page = doc_pages; boolean make_new_page = pos.isNewPage(); if (!(pos.isNewPage() || pos.isPauto())) { // we should posit signaturtable on this page page = pos.getPage(); // System.out.println("XXXXPAGE="+page+" doc_pages="+doc_pages); if (page > doc_pages) { make_new_page = true; page = doc_pages; // throw new PDFDocumentException(227, "Page number is to big(=" // + page+ // ") cannot be parsed."); } } PDPage pdPage = pdfDataSource.getPage(page - 1); PDRectangle cropBox = pdPage.getCropBox(); // fallback to MediaBox if Cropbox not available! if (cropBox == null) { cropBox = pdPage.getCropBox(); } if (cropBox == null) { cropBox = pdPage.getCropBox(); } // getPagedimensions // Rectangle psize = reader.getPageSizeWithRotation(page); // int page_rotation = reader.getPageRotation(page); // Integer rotation = pdPage.getRotation(); // int page_rotation = rotation.intValue(); int rotation = pdPage.getRotation(); logger.debug("Original CropBox: " + cropBox.toString()); cropBox = rotateBox(cropBox, rotation); logger.debug("Rotated CropBox: " + cropBox.toString()); float page_width = cropBox.getWidth(); float page_height = cropBox.getHeight(); logger.debug("CropBox width: " + page_width); logger.debug("CropBox heigth: " + page_height); // now we can calculate x-position float pre_pos_x = SIGNATURE_MARGIN_HORIZONTAL; if (!pos.isXauto()) { // we do have absolute x pre_pos_x = pos.getPosX(); } // calculate width // center float pre_width = page_width - 2 * pre_pos_x; if (!pos.isWauto()) { // we do have absolute width pre_width = pos.getWidth(); if (pos.isXauto()) { // center x pre_pos_x = (page_width - pre_width) / 2; } } final float pos_x = pre_pos_x; final float width = pre_width; // Signatur table dimensions are complete pdf_table.setWidth(width); pdf_table.fixWidth(); // pdf_table.setTotalWidth(width); // pdf_table.setLockedWidth(true); final float table_height = pdf_table.getHeight(); // now check pos_y float pos_y = pos.getPosY(); // in case an absolute y position is already given OR // if the table is related to an invisible signature // there is no need for further calculations // (fixed adding new page in case of invisible signatures) if (!pos.isYauto() || table_height == 0) { // we do have y-position too --> all parameters but page ok if (make_new_page) { page++; } return new PositioningInstruction(make_new_page, page, pos_x, pos_y, pos.rotation); } // pos_y is auto if (make_new_page) { // ignore footer in new page page++; pos_y = page_height - SIGNATURE_MARGIN_VERTICAL; return new PositioningInstruction(make_new_page, page, pos_x, pos_y, pos.rotation); } // up to here no checks have to be made if Tablesize and Pagesize are // fit // Now we have to getfreespace in page and reguard footerline float footer_line = pos.getFooterLine(); // float pre_page_length = PDFUtilities.calculatePageLength(pdfDataSource, // page - 1, page_height - footer_line, /* page_rotation, */ // legacy32, legacy40); float pre_page_length = Float.NEGATIVE_INFINITY; try { pre_page_length = PDFUtilities.getMaxYPosition(pdfDataSource, page - 1, pdf_table, SIGNATURE_MARGIN_VERTICAL, footer_line, settings); //pre_page_length = PDFUtilities.getFreeTablePosition(pdfDataSource, page-1, pdf_table,SIGNATURE_MARGIN_VERTICAL); } catch (IOException e) { logger.warn("Could not determine page length, using -INFINITY"); } if (pre_page_length == Float.NEGATIVE_INFINITY) { // we do have an empty page or nothing in area above footerline pre_page_length = page_height; // no text --> SIGNATURE_BORDER pos_y = page_height - SIGNATURE_MARGIN_VERTICAL; if (pos_y - footer_line <= table_height) { make_new_page = true; if (!pos.isPauto()) { // we have to correct pagenumber page = pdfDataSource.getNumberOfPages(); } page++; // no text --> SIGNATURE_BORDER pos_y = page_height - SIGNATURE_MARGIN_VERTICAL; } return new PositioningInstruction(make_new_page, page, pos_x, pos_y, pos.rotation); } final float page_length = pre_page_length; // we do have text take SIGNATURE_MARGIN pos_y = page_height - page_length - SIGNATURE_MARGIN_VERTICAL; if (pos_y - footer_line <= table_height) { make_new_page = true; if (!pos.isPauto()) { // we have to correct pagenumber in case of absolute page and // not enough // space page = pdfDataSource.getNumberOfPages(); } page++; // no text --> SIGNATURE_BORDER pos_y = page_height - SIGNATURE_MARGIN_VERTICAL; } return new PositioningInstruction(make_new_page, page, pos_x, pos_y, pos.rotation); }
From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.PDFAsVisualSignatureDesigner.java
License:EUPL
/** * Each page of document can be different sizes. * //from w w w .java 2 s .c om * @param document * @param page */ private void calculatePageSize(PDDocument document, int page, boolean newpage) { if (page < 1) { throw new IllegalArgumentException("First page of pdf is 1, not " + page); } List<?> pages = document.getDocumentCatalog().getAllPages(); if (newpage) { PDPage lastPage = (PDPage) pages.get(pages.size() - 1); PDRectangle mediaBox = lastPage.findMediaBox(); pageRotation = lastPage.findRotation() % 360; if (pageRotation == 90 || pageRotation == 270) { this.pageHeight(mediaBox.getWidth()); this.pageWidth = mediaBox.getHeight(); } else { this.pageHeight(mediaBox.getHeight()); this.pageWidth = mediaBox.getWidth(); } } else { PDPage firstPage = (PDPage) pages.get(page - 1); PDRectangle mediaBox = firstPage.findMediaBox(); pageRotation = firstPage.findRotation() % 360; if (pageRotation == 90 || pageRotation == 270) { this.pageHeight(mediaBox.getWidth()); this.pageWidth = mediaBox.getHeight(); } else { this.pageHeight(mediaBox.getHeight()); this.pageWidth = mediaBox.getWidth(); } } float x = this.pageWidth; float y = 0; this.pageWidth = this.pageWidth + y; float tPercent = (100 * y / (x + y)); this.imageSizeInPercents = 100 - tPercent; }
From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox2.PDFAsVisualSignatureDesigner.java
License:EUPL
/** * Each page of document can be different sizes. * //from w w w . ja v a 2 s . co m * @param document * @param page */ private void calculatePageSize(PDDocument document, int page, boolean newpage) { if (page < 1) { throw new IllegalArgumentException("First page of pdf is 1, not " + page); } PDPageTree pages = document.getDocumentCatalog().getPages(); if (newpage) { PDPage lastPage = (PDPage) pages.get(pages.getCount() - 1); PDRectangle mediaBox = lastPage.getMediaBox(); pageRotation = lastPage.getRotation() % 360; if (pageRotation == 90 || pageRotation == 270) { this.pageHeight(mediaBox.getWidth()); this.pageWidth = mediaBox.getHeight(); } else { this.pageHeight(mediaBox.getHeight()); this.pageWidth = mediaBox.getWidth(); } } else { PDPage firstPage = (PDPage) pages.get(page - 1); PDRectangle mediaBox = firstPage.getMediaBox(); pageRotation = firstPage.getRotation() % 360; if (pageRotation == 90 || pageRotation == 270) { this.pageHeight(mediaBox.getWidth()); this.pageWidth = mediaBox.getHeight(); } else { this.pageHeight(mediaBox.getHeight()); this.pageWidth = mediaBox.getWidth(); } } float x = this.pageWidth; float y = 0; this.pageWidth = this.pageWidth + y; float tPercent = (100 * y / (x + y)); this.imageSizeInPercents = 100 - tPercent; }
From source file:at.knowcenter.wag.egov.egiz.pdf.PDFPage.java
License:EUPL
/** * Registers a rectangle that bounds the path currently being drawn. * // w ww. j a v a 2 s. c o m * @param bounds * A rectangle depicting the bounds (coordinates originating from * bottom left). * @author Datentechnik Innovation GmbH */ public void registerPathBounds(Rectangle bounds) { if (!bounds.isEmpty()) { logger.debug("Registering path bounds: " + bounds); // vertical start of rectangle (counting from top of page) float upperBoundYPositionFromTop; // vertical end of rectangle (counting from top of page) // this depicts the current end of path-related page content float lowerBoundYPositionFromTop; PDRectangle boundaryBox = this.getCurrentPage().findCropBox(); if (boundaryBox == null) { boundaryBox = this.getCurrentPage().findMediaBox(); } float pageHeight; switch (this.getCurrentPage().findRotation()) { case 90: // CW pageHeight = boundaryBox.getWidth(); upperBoundYPositionFromTop = (float) bounds.getMinX(); lowerBoundYPositionFromTop = (float) bounds.getMaxX(); break; case 180: pageHeight = boundaryBox.getHeight(); upperBoundYPositionFromTop = (float) bounds.getMinY(); lowerBoundYPositionFromTop = (float) bounds.getMaxY(); break; case 270: // CCW pageHeight = boundaryBox.getWidth(); upperBoundYPositionFromTop = pageHeight - (float) bounds.getMaxX(); lowerBoundYPositionFromTop = pageHeight - (float) bounds.getMinX(); break; default: pageHeight = boundaryBox.getHeight(); upperBoundYPositionFromTop = pageHeight - (float) bounds.getMaxY(); lowerBoundYPositionFromTop = pageHeight - (float) bounds.getMinY(); break; } // new maximum ? if (lowerBoundYPositionFromTop > maxPathRelatedYPositionFromTop) { // Is the rectangle (at least partly) located above the footer // line? // (effective page height := page height - footer line) if (upperBoundYPositionFromTop <= effectivePageHeight) { // yes: update current end of path-related page content maxPathRelatedYPositionFromTop = lowerBoundYPositionFromTop; logger.trace("New max path related y position (from top): " + maxPathRelatedYPositionFromTop); } else { // no: rectangle is fully located below the footer line -> // ignore logger.trace("Ignoring path bound below the footer line."); } } } }