Java Code Examples for com.lowagie.text.pdf.PdfContentByte#setRGBColorFill()
The following examples show how to use
com.lowagie.text.pdf.PdfContentByte#setRGBColorFill() .
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: CirclesTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Draws some concentric circles. */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "circles.pdf")); // step 3: we open the document document.open(); // step 4: we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); cb.circle(250.0f, 500.0f, 200.0f); cb.circle(250.0f, 500.0f, 150.0f); cb.stroke(); cb.setRGBColorFill(0xFF, 0x00, 0x00); cb.circle(250.0f, 500.0f, 100.0f); cb.fillStroke(); cb.setRGBColorFill(0xFF, 0xFF, 0xFF); cb.circle(250.0f, 500.0f, 50.0f); cb.fill(); cb.sanityCheck(); } catch(DocumentException de) { System.err.println(de.getMessage()); } catch(IOException ioe) { System.err.println(ioe.getMessage()); } // step 5: we close the document document.close(); }
Example 2
Source File: LayersTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Draws different things into different layers. */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: creation of the writer PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("layers.pdf")); // step 3: we open the document document.open(); // step 4: // high level Paragraph p = new Paragraph(); for (int i = 0; i < 100; i++) p.add(new Chunk("Blah blah blah blah blah. ")); document.add(p); Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR + "hitchcock.png"); img.setAbsolutePosition(100, 500); document.add(img); // low level PdfContentByte cb = writer.getDirectContent(); PdfContentByte cbu = writer.getDirectContentUnder(); cb.setRGBColorFill(0xFF, 0xFF, 0xFF); cb.circle(250.0f, 500.0f, 50.0f); cb.fill(); cb.sanityCheck(); cbu.setRGBColorFill(0xFF, 0x00, 0x00); cbu.circle(250.0f, 500.0f, 100.0f); cbu.fill(); cbu.sanityCheck(); // step 5: we close the document document.close(); }
Example 3
Source File: ImageMasksTest.java From itext2 with GNU Lesser General Public License v3.0 | 4 votes |
/** * Applying masks to images. */ @Test public void main() throws Exception { Document document = new Document(PageSize.A4, 50, 50, 50, 50); try { PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "maskedImages.pdf")); document.open(); Paragraph p = new Paragraph("Some text behind a masked image."); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); document.add(p); PdfContentByte cb = writer.getDirectContent(); byte maskr[] = {(byte)0x3c, (byte)0x7e, (byte)0xe7, (byte)0xc3, (byte)0xc3, (byte)0xe7, (byte)0x7e, (byte)0x3c}; Image mask = Image.getInstance(8, 8, 1, 1, maskr); mask.makeMask(); mask.setInverted(true); Image image = Image.getInstance(PdfTestBase.RESOURCES_DIR +"otsoe.jpg"); image.setImageMask(mask); image.setAbsolutePosition(60, 550); // explicit masking cb.addImage(image); // stencil masking cb.setRGBColorFill(255, 0, 0); cb.addImage(mask, mask.getScaledWidth() * 8, 0, 0, mask.getScaledHeight() * 8, 100, 450); cb.setRGBColorFill(0, 255, 0); cb.addImage(mask, mask.getScaledWidth() * 8, 0, 0, mask.getScaledHeight() * 8, 100, 400); cb.setRGBColorFill(0, 0, 255); cb.addImage(mask, mask.getScaledWidth() * 8, 0, 0, mask.getScaledHeight() * 8, 100, 350); document.close(); } catch (Exception de) { de.printStackTrace(); } }