List of usage examples for com.lowagie.text Rectangle getBottom
public float getBottom()
From source file:org.geomajas.plugin.print.component.PdfContext.java
License:Open Source License
/** * Converts an absolute rectangle to a relative one wrt to the current coordinate system. * * @param rect absolute rectangle/*w ww . j a v a 2s. com*/ * @return relative rectangle */ public Rectangle toRelative(Rectangle rect) { return new Rectangle(rect.getLeft() - origX, rect.getBottom() - origY, rect.getRight() - origX, rect.getTop() - origY); }
From source file:org.geomajas.plugin.print.parser.RectangleConverter.java
License:Open Source License
@Override public String toString(Object obj) { Rectangle rectangle = (Rectangle) obj; if (obj == null) { return null; }//from w w w .jav a 2s .c o m return rectangle.getLeft() + "," + rectangle.getBottom() + "," + rectangle.getRight() + "," + rectangle.getTop(); }
From source file:org.jaffa.modules.printing.services.FormPrintEngineIText.java
License:Open Source License
/** * Any work to start off printing the document * @throws FormPrintException Thrown if there is any form processing problems *//*from w w w. j a va 2 s . co m*/ protected void startDocument() throws FormPrintException { log.debug("startDocument:"); Rectangle r = m_templateReader.getPageSize(getCurrentTemplatePage()); log.debug("Page Size : t=" + r.getTop() + ",l=" + r.getLeft() + ",b=" + r.getBottom() + ",r=" + r.getRight() + ", rot=" + r.getRotation()); r = m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage()); log.debug("Page Size w/Rot: t=" + r.getTop() + ",l=" + r.getLeft() + ",b=" + r.getBottom() + ",r=" + r.getRight() + ", rot=" + r.getRotation()); m_generatedDoc = new Document(m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage())); //m_generatedDoc = new Document(m_templateReader.getPageSize(getCurrentTemplatePage())); m_output = new ByteArrayOutputStream(); try { m_writer = PdfWriter.getInstance(m_generatedDoc, m_output); } catch (DocumentException e) { log.error("Error Creating Writer - " + e.getMessage(), e); throw new EngineProcessingException("Error Creating Writer - " + e.getMessage()); } if (getDocumentProperties() != null) { Properties dp = (Properties) getDocumentProperties().clone(); if (dp.getProperty(DOCUMENT_PROPERTY_TITLE) != null) { m_generatedDoc.addTitle(dp.getProperty(DOCUMENT_PROPERTY_TITLE)); dp.remove(DOCUMENT_PROPERTY_TITLE); } if (dp.getProperty(DOCUMENT_PROPERTY_SUBJECT) != null) { m_generatedDoc.addSubject(dp.getProperty(DOCUMENT_PROPERTY_SUBJECT)); dp.remove(DOCUMENT_PROPERTY_SUBJECT); } if (dp.getProperty(DOCUMENT_PROPERTY_KEYWORDS) != null) { m_generatedDoc.addKeywords(dp.getProperty(DOCUMENT_PROPERTY_KEYWORDS)); dp.remove(DOCUMENT_PROPERTY_KEYWORDS); } if (dp.getProperty(DOCUMENT_PROPERTY_CREATOR) != null) { m_generatedDoc.addCreator(dp.getProperty(DOCUMENT_PROPERTY_CREATOR, "Jaffa Print Engine")); dp.remove(DOCUMENT_PROPERTY_CREATOR); } if (dp.getProperty(DOCUMENT_PROPERTY_AUTHOR) != null) { m_generatedDoc.addAuthor(dp.getProperty(DOCUMENT_PROPERTY_AUTHOR)); dp.remove(DOCUMENT_PROPERTY_AUTHOR); } // loop through other properties and set them as header parameters for (Enumeration en = dp.elements(); en.hasMoreElements();) { Map.Entry e = (Map.Entry) en.nextElement(); if (e.getKey() != null && e.getValue() != null) m_generatedDoc.addHeader(e.getKey().toString(), e.getValue().toString()); } } m_generatedDoc.addCreationDate(); m_generatedDoc.open(); }
From source file:org.jaffa.modules.printing.services.FormPrintEngineIText.java
License:Open Source License
/** * Any work to start off printing a page of the document * m_currentPage will contain the page being printed, and * m_currentTemplatePage will contain the template page number to base this * new page on./*from w ww . j a v a 2 s.c o m*/ * @throws FormPrintException Thrown if there is any form processing problems */ protected void startPage() throws FormPrintException { log.debug("startPage: Page=" + getCurrentPage()); Rectangle r = m_templateReader.getPageSize(getCurrentTemplatePage()); log.debug("Page Size : t=" + r.getTop() + ",l=" + r.getLeft() + ",b=" + r.getBottom() + ",r=" + r.getRight() + ", rot=" + r.getRotation()); r = m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage()); log.debug("Page Size w/Rot: t=" + r.getTop() + ",l=" + r.getLeft() + ",b=" + r.getBottom() + ",r=" + r.getRight() + ", rot=" + r.getRotation()); // Get rotation quadrent 0..3 int q = (m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage()).getRotation() % 360) / 90; float tX = (q == 2 ? r.getTop() : 0) + (q == 3 ? r.getRight() : 0); float tY = (q == 1 ? r.getTop() : 0) + (q == 2 ? r.getRight() : 0); float sX = 1f, sY = 1f; double angle = -r.getRotation() * (Math.PI / 180f); double transformA = sX * Math.cos(angle); double transformB = sY * Math.sin(angle); double transformC = -sX * Math.sin(angle); double transformD = sY * Math.cos(angle); double transformE = tX; double transformF = tY; m_generatedDoc.setPageSize(m_templateReader.getPageSizeWithRotation(getCurrentTemplatePage())); //m_generatedDoc.setPageSize(m_templateReader.getPageSize(getCurrentTemplatePage()) ); /** * try { * m_generatedDoc.newPage(); * } catch (DocumentException e) { * log.error("Error Creating New Page - " + e.getMessage() ,e); * throw new EngineProcessingException("Error Creating New Page - " + e.getMessage()); * } **/ m_generatedDoc.newPage(); PdfImportedPage page = m_writer.getImportedPage(m_templateReader, getCurrentTemplatePage()); PdfContentByte cb = m_writer.getDirectContent(); //cb.addTemplate(page, 1f, 0, 0, 1f, 0, 0); cb.addTemplate(page, (float) transformA, (float) transformB, (float) transformC, (float) transformD, (float) transformE, (float) transformF); log.debug("Matrix = [A=" + transformA + ", B=" + transformB + ", C=" + transformC + ", D=" + transformD + ", E=" + transformE + ", F=" + transformF + " ]"); }
From source file:org.mapfish.print.map.MapChunkDrawer.java
License:Open Source License
public void renderImpl(Rectangle rectangle, PdfContentByte dc) { final PJsonObject parent = context.getGlobalParams(); PJsonArray layers = parent.getJSONArray("layers"); String srs = parent.getString("srs"); if (!context.getConfig().isScalePresent(transformer.getScale())) { throw new InvalidJsonValueException(params, "scale", transformer.getScale()); }//from www . ja va 2s . c om Transformer mainTransformer = null; if (!Double.isNaN(overviewMap)) { //manage the overview map mainTransformer = context.getLayout().getMainPage().getMap().createTransformer(context, params); transformer.zoom(mainTransformer, (float) (1.0 / overviewMap)); transformer.setRotation(0); //overview always north up! context.setStyleFactor((float) (transformer.getPaperW() / mainTransformer.getPaperW() / overviewMap)); layers = parent.optJSONArray("overviewLayers", layers); } transformer.setMapPos(rectangle.getLeft(), rectangle.getBottom()); if (rectangle.getWidth() < transformer.getPaperW() - 0.2) { throw new RuntimeException("The map width on the paper is wrong"); } if (rectangle.getHeight() < transformer.getPaperH() - 0.2) { throw new RuntimeException("The map height on the paper is wrong (" + rectangle.getHeight() + "!=" + transformer.getPaperH() + ")"); } //create the readers/renderers List<MapReader> readers = new ArrayList<MapReader>(layers.size()); for (int i = 0; i < layers.size(); ++i) { PJsonObject layer = layers.getJSONObject(i); if (mainTransformer == null || layer.optBool("overview", true)) { final String type = layer.getString("type"); MapReader.create(readers, type, context, layer); } } //check if we cannot merge a few queries for (int i = 1; i < readers.size();) { MapReader reader1 = readers.get(i - 1); MapReader reader2 = readers.get(i); if (reader1.testMerge(reader2)) { readers.remove(i); } else { ++i; } } //draw some background if (backgroundColor != null) { dc.saveState(); try { dc.setColorFill(backgroundColor); dc.rectangle(rectangle.getLeft(), rectangle.getBottom(), rectangle.getWidth(), rectangle.getHeight()); dc.fill(); } finally { dc.restoreState(); } } //Do the rendering. // //Since we need to load tiles in parallel from the //servers, what follows is not trivial. We don't write directly to the PDF's //DirectContent, we always go through the ParallelMapTileLoader that will //make sure that everything is added to the PDF in the correct order. // //All uses of the DirectContent (dc) or the PDFWriter is forbiden outside //of renderOnPdf methods and when they are used, one must take a lock on //context.getPdfLock(). That is done for you when renderOnPdf is called, but not done //in the readTile method. That's why PDFUtils.getImage needs to do it when //creating the template. // //If you don't follow those rules, you risk to have random inconsistency //in your PDF files and/or infinite loops in iText. ParallelMapTileLoader parallelMapTileLoader = new ParallelMapTileLoader(context, dc); dc.saveState(); try { final PdfLayer mapLayer = new PdfLayer(name, context.getWriter()); transformer.setClipping(dc); //START of the parallel world !!!!!!!!!!!!!!!!!!!!!!!!!!! for (int i = 0; i < readers.size(); i++) { final MapReader reader = readers.get(i); //mark the starting of a new PDF layer parallelMapTileLoader.addTileToLoad(new MapTileTask.RenderOnly() { public void renderOnPdf(PdfContentByte dc) throws DocumentException { PdfLayer pdfLayer = new PdfLayer(reader.toString(), context.getWriter()); mapLayer.addChild(pdfLayer); dc.beginLayer(pdfLayer); } }); //render the layer reader.render(transformer, parallelMapTileLoader, srs, i == 0); //mark the end of the PDF layer parallelMapTileLoader.addTileToLoad(new MapTileTask.RenderOnly() { public void renderOnPdf(PdfContentByte dc) throws DocumentException { dc.endLayer(); } }); } } finally { //wait for all the tiles to be loaded parallelMapTileLoader.waitForCompletion(); //END of the parallel world !!!!!!!!!!!!!!!!!!!!!!!!!! dc.restoreState(); } if (mainTransformer != null) { //only for key maps: draw the real map extent drawMapExtent(dc, mainTransformer); context.setStyleFactor(1.0f); } }
From source file:org.mapfish.print.scalebar.ScalebarDrawer.java
License:Open Source License
public void renderImpl(Rectangle rectangle, PdfContentByte dc) { dc.saveState();//from w ww .ja va 2 s . c o m try { //sets the transformation for drawing the labels and do it final AffineTransform rotate = getRotationTransform(block.getBarDirection()); final AffineTransform labelTransform = AffineTransform.getTranslateInstance(rectangle.getLeft(), rectangle.getBottom()); labelTransform.concatenate(rotate); labelTransform.translate(leftLabelMargin, maxLabelHeight); dc.transform(labelTransform); dc.setColorStroke(block.getColorVal()); dc.setFontAndSize(pdfFont.getCalculatedBaseFont(false), pdfFont.getSize()); drawLabels(dc); dc.restoreState(); dc.saveState(); //sets the transformation for drawing the bar and do it final AffineTransform lineTransform = AffineTransform.getTranslateInstance(rectangle.getLeft(), rectangle.getBottom()); lineTransform.concatenate(rotate); lineTransform.translate(leftLabelMargin, labelDistance + maxLabelHeight); dc.transform(lineTransform); dc.setLineWidth((float) block.getLineWidth()); dc.setColorStroke(block.getColorVal()); drawBar(dc); } finally { dc.restoreState(); } }
From source file:questions.ocg.AddOptionalWatermark.java
public static void main(String[] args) throws DocumentException, IOException { PdfReader reader = new PdfReader(RESOURCE); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); Image image1 = Image.getInstance(IMAGE_PRINTED); Image image2 = Image.getInstance(IMAGE_NOT_PRINTED); PdfLayer watermark_printed = new PdfLayer("printed", stamper.getWriter()); watermark_printed.setOn(false);/* w w w. j a v a 2 s . c o m*/ watermark_printed.setOnPanel(false); watermark_printed.setPrint("print", true); PdfLayer watermark_not_printed = new PdfLayer("not_printed", stamper.getWriter()); watermark_not_printed.setOn(true); watermark_not_printed.setOnPanel(false); watermark_not_printed.setPrint("print", false); for (int i = 0; i < stamper.getReader().getNumberOfPages();) { PdfContentByte cb = stamper.getUnderContent(++i); Rectangle rectangle = stamper.getReader().getPageSizeWithRotation(i); cb.beginLayer(watermark_printed); float AbsoluteX = rectangle.getLeft() + (rectangle.getWidth() - image1.getPlainWidth()) / 2; float AbsoluteY = rectangle.getBottom() + (rectangle.getHeight() - image1.getPlainHeight()) / 2; image1.setAbsolutePosition(AbsoluteX, AbsoluteY); cb.addImage(image1); cb.endLayer(); cb.beginLayer(watermark_not_printed); AbsoluteX = rectangle.getLeft() + (rectangle.getWidth() - image2.getPlainWidth()) / 2; AbsoluteY = rectangle.getBottom() + (rectangle.getHeight() - image2.getPlainHeight()) / 2; image2.setAbsolutePosition(AbsoluteX, AbsoluteY); cb.addImage(image2); cb.endLayer(); } stamper.close(); }