List of usage examples for com.lowagie.text.pdf PdfContentByte fill
public void fill()
From source file:org.kuali.kfs.module.tem.pdf.Coversheet.java
License:Open Source License
protected void upperRightAlignmentMark(final PdfContentByte cb) { cb.saveState();/*from w w w .j av a 2s .c o m*/ cb.rectangle(LETTER.width() - (ALIGNMENT_MARGIN * 4) - ALIGNMENT_MARK_WIDTH, (LETTER.height() + TOP_MARGIN) - ALIGNMENT_MARGIN - ALIGNMENT_MARK_HEIGHT, ALIGNMENT_MARK_WIDTH, ALIGNMENT_MARK_HEIGHT); cb.setColorFill(BLACK); cb.fill(); cb.restoreState(); }
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 w w w . j a v a 2 s . co m*/ 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.BarScalebarDrawer.java
License:Open Source License
protected void drawBar(PdfContentByte dc) { float subIntervalWidth = intervalWidth / subIntervals; for (int i = 0; i < block.getIntervals() * subIntervals; ++i) { float pos = i * subIntervalWidth; final Color color = i % 2 == 0 ? block.getBarBgColorVal() : block.getColorVal(); if (color != null) { dc.setColorFill(color);/*from w ww . ja v a 2s . co m*/ dc.rectangle(pos, 0, subIntervalWidth, barSize); dc.fill(); } } dc.rectangle(0, 0, intervalWidth * block.getIntervals(), barSize); dc.stroke(); }
From source file:org.xhtmlrenderer.pdf.ITextOutputDevice.java
License:Open Source License
private void followPath(Shape s, int drawType) { PdfContentByte cb = _currentPage; if (s == null) return;//from w w w . j ava 2 s . c o m if (drawType == STROKE) { if (!(_stroke instanceof BasicStroke)) { s = _stroke.createStrokedShape(s); followPath(s, FILL); return; } } if (drawType == STROKE) { setStrokeDiff(_stroke, _oldStroke); _oldStroke = _stroke; ensureStrokeColor(); } else if (drawType == FILL) { ensureFillColor(); } PathIterator points; if (drawType == CLIP) { points = s.getPathIterator(IDENTITY); } else { points = s.getPathIterator(_transform); } float[] coords = new float[6]; int traces = 0; while (!points.isDone()) { ++traces; int segtype = points.currentSegment(coords); normalizeY(coords); switch (segtype) { case PathIterator.SEG_CLOSE: cb.closePath(); break; case PathIterator.SEG_CUBICTO: cb.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case PathIterator.SEG_LINETO: cb.lineTo(coords[0], coords[1]); break; case PathIterator.SEG_MOVETO: cb.moveTo(coords[0], coords[1]); break; case PathIterator.SEG_QUADTO: System.out.println("Quad to " + coords[0] + " " + coords[1] + " " + coords[2] + " " + coords[3]); cb.curveTo(coords[0], coords[1], coords[2], coords[3]); break; } points.next(); } switch (drawType) { case FILL: if (traces > 0) { if (points.getWindingRule() == PathIterator.WIND_EVEN_ODD) cb.eoFill(); else cb.fill(); } break; case STROKE: if (traces > 0) cb.stroke(); break; default: // drawType==CLIP if (traces == 0) cb.rectangle(0, 0, 0, 0); if (points.getWindingRule() == PathIterator.WIND_EVEN_ODD) cb.eoClip(); else cb.clip(); cb.newPath(); } }
From source file:questions.directcontent.Logo.java
public static void main(String[] args) { Rectangle rect = new Rectangle(36, 726, 136, 786); Document document = new Document(rect); try {/*from w w w .jav a 2s .co m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); PdfContentByte canvas = writer.getDirectContent(); canvas.moveTo(63.73f, 735.47f); canvas.curveTo(72.13f, 737.94f, 75.73f, 758.15f, 79.67f, 768.04f); canvas.curveTo(84.82f, 767.79f, 94.41f, 772.38f, 85.69f, 772.97f); canvas.curveTo(83.19f, 768.56f, 63.84f, 779.61f, 60.55f, 779.7f); canvas.curveTo(48.58f, 780.03f, 74.62f, 769.75f, 74.68f, 769.99f); canvas.curveTo(74.64f, 769.8f, 69.43f, 743.55f, 66.08f, 740.12f); canvas.curveTo(59.24f, 733.11f, 52.73f, 745.57f, 53.35f, 752.21f); canvas.curveTo(53.6f, 754.85f, 64.32f, 747.14f, 57.21f, 755.02f); canvas.curveTo(45.66f, 767.82f, 49.11f, 731.17f, 63.73f, 735.47f); canvas.moveTo(93.61f, 741.57f); canvas.curveTo(109.15f, 721.02f, 112.42f, 746.51f, 118.3f, 761.57f); canvas.curveTo(124.73f, 761.48f, 129.8f, 765.3f, 124f, 765.62f); canvas.curveTo(119.84f, 761.88f, 108.12f, 770.22f, 100.92f, 771.57f); canvas.curveTo(94.24f, 769.12f, 115.02f, 764.34f, 114.24f, 761.53f); canvas.curveTo(109.9f, 751.94f, 107.5f, 721.65f, 95.84f, 744.74f); canvas.curveTo(100.15f, 747.38f, 109.63f, 766.92f, 95.28f, 748.57f); canvas.curveTo(91.45f, 743.68f, 89.6f, 766.35f, 77.99f, 754.83f); canvas.curveTo(74.22f, 751.07f, 84.27f, 747.81f, 81.6f, 745.28f); canvas.curveTo(67.39f, 750.93f, 74.66f, 719.55f, 93.61f, 741.57f); canvas.moveTo(78.37f, 743.72f); canvas.curveTo(78.19f, 743.22f, 89.27f, 744.04f, 82.46f, 749.7f); canvas.curveTo(76.28f, 754.83f, 85.17f, 760.2f, 90.72f, 746.97f); canvas.curveTo(94f, 739.15f, 73.88f, 730.88f, 78.37f, 743.72f); canvas.setCMYKColorFillF(1, 0.5f, 0, 0.467f); canvas.fill(); canvas.setCMYKColorFillF(0, 0.467f, 1, 0); canvas.moveTo(58f, 764.8f); canvas.curveTo(58f, 767.01f, 56.21f, 768.8f, 54f, 768.8f); canvas.curveTo(51.79f, 768.8f, 50f, 767.01f, 50f, 764.8f); canvas.curveTo(50f, 762.59f, 51.79f, 760.8f, 54f, 760.8f); canvas.curveTo(56.21f, 760.8f, 58f, 762.59f, 58f, 764.8f); canvas.fill(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } document.close(); }
From source file:questions.markedcontent.ObjectData.java
public static void main(String[] args) { Document document = new Document(PageSize.A5.rotate()); try {// ww w. j av a 2 s . c om PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); writer.setTagged(); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfStructureTreeRoot tree = writer.getStructureTreeRoot(); PdfStructureElement se = new PdfStructureElement(tree, new PdfName("Figure")); PdfStructureElement element = new PdfStructureElement(se, new PdfName("Element")); PdfDictionary userproperties = new PdfDictionary(); userproperties.put(PdfName.O, PdfName.USERPROPERTIES); userproperties.put(PdfName.S, new PdfName("Figure")); PdfArray properties = new PdfArray(); PdfDictionary property1 = new PdfDictionary(); property1.put(PdfName.N, new PdfString("Name1")); property1.put(PdfName.V, new PdfString("Value1")); properties.add(property1); PdfDictionary property2 = new PdfDictionary(); property2.put(PdfName.N, new PdfString("Name2")); property2.put(PdfName.V, new PdfString("Value2")); properties.add(property2); PdfDictionary property3 = new PdfDictionary(); property3.put(PdfName.N, new PdfString("Name3")); property3.put(PdfName.V, new PdfString("Value3")); properties.add(property3); userproperties.put(PdfName.P, properties); element.put(PdfName.A, userproperties); PdfLayer lay1 = new PdfLayer("My object", writer); cb.beginMarkedContentSequence(element); cb.beginLayer(lay1); cb.setColorFill(Color.BLUE); cb.rectangle(50, 50, 200, 200); cb.fill(); cb.endLayer(); cb.endMarkedContentSequence(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); }