List of usage examples for com.lowagie.text Rectangle Rectangle
public Rectangle(float llx, float lly, float urx, float ury)
Rectangle
-object. From source file:questions.compression.CompressionLevelsEmbeddedFiles.java
public static void createPdf(int compressionLevel) { try {/*from www . j av a 2 s . c o m*/ Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT[compressionLevel + 1])); document.open(); document.add(new Paragraph("Hello World")); PdfFileSpecification fs1 = PdfFileSpecification.fileEmbedded(writer, null, "some.txt", "some text".getBytes(), compressionLevel); writer.addAnnotation(PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 750f, 120f, 770f), "This is some text", fs1)); PdfFileSpecification fs2 = PdfFileSpecification.fileEmbedded(writer, RESOURCE, "caesar.txt", null, compressionLevel); writer.addAnnotation(PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 780f, 120f, 800f), "Caesar", fs2)); document.close(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } }
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 {/*w w w .j a v a 2 s .c o 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.encryption.HelloWorldFullyEncrypted.java
public static void main(String[] args) { // step 1/*from w ww .j av a2 s. c om*/ Document document = new Document(); try { // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); writer.setEncryption("hello".getBytes(), "world".getBytes(), 0, PdfWriter.ENCRYPTION_AES_128); writer.createXmpMetadata(); // step 3 document.open(); // step 4 document.add(new Paragraph("Hello World")); writer.addAnnotation(PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 650f, 150f, 700f), "This is some text", "some text".getBytes(), null, "some.txt")); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5 document.close(); }
From source file:questions.encryption.HelloWorldMetadataNotEncrypted.java
public static void main(String[] args) { // step 1//from w w w. ja va 2 s.co m Document document = new Document(); try { // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); writer.setEncryption("hello".getBytes(), "world".getBytes(), 0, PdfWriter.ENCRYPTION_AES_128 | PdfWriter.DO_NOT_ENCRYPT_METADATA); writer.createXmpMetadata(); writer.setPdfVersion(PdfWriter.VERSION_1_5); // step 3 document.open(); // step 4 document.add(new Paragraph("Hello World")); writer.addAnnotation(PdfAnnotation.createFileAttachment(writer, new Rectangle(100f, 650f, 150f, 700f), "This is some text", "some text".getBytes(), null, "some.txt")); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5 document.close(); }
From source file:questions.forms.AddFieldToExistingForm.java
public static void main(String[] args) { PdfReader reader;//from ww w.ja v a 2 s.c o m try { reader = new PdfReader(FORM); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); TextField tf = new TextField(stamper.getWriter(), new Rectangle(100, 760, 400, 785), "added_field"); tf.setText("\u00e4\u00f4\u00df"); tf.setOptions(TextField.READ_ONLY); stamper.addAnnotation(tf.getTextField(), 1); AcroFields form = stamper.getAcroFields(); form.setField("Who", "\u00e4\u00f3\u00df\u00f4"); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:questions.forms.FormWithTooltips.java
/** * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, * com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[]) *///from ww w. j a va 2s .co m public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] cb) { kid.setWidget(new Rectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)), PdfAnnotation.HIGHLIGHT_INVERT); kid.setUserName(tooltip); try { parent.addKid(kid); } catch (Exception e) { throw new ExceptionConverter(e); } }
From source file:questions.forms.KidsOnDifferentPages.java
public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] cb) { kid.setWidget(new Rectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)), PdfAnnotation.HIGHLIGHT_INVERT); }
From source file:questions.forms.MultipleChoice.java
public static void createPdf() throws IOException, DocumentException { // step 1/*from ww w . j a v a 2s .c o m*/ Document document = new Document(); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 TextField field = new TextField(writer, new Rectangle(36, 750, 144, 806), "iText"); field.setFontSize(9); String[] list_options = { "JAVA", "C", "CS", "VB", "PHP" }; field.setChoiceExports(list_options); String[] list_values = { "Java", "C/C++", "C#", "VB", "PHP" }; field.setChoices(list_values); PdfFormField f = field.getListField(); f.setFieldFlags(PdfFormField.FF_MULTISELECT); f.put(PdfName.I, new PdfArray(new int[] { 0, 2 })); writer.addAnnotation(f); // step 5 document.close(); }
From source file:questions.forms.RadioButtonsOnDifferentPages.java
public static void main(String[] args) { Document document = new Document(); try {// w ww.j a v a 2s .co m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); String[] languages = { "English", "French", "Dutch" }; Rectangle rect; // create radio button field and its kids PdfFormField language = PdfFormField.createRadioButton(writer, true); language.setFieldName("language"); language.setValueAsName(languages[0]); for (int i = 0; i < languages.length; i++) { rect = new Rectangle(40, 806 - i * 40, 60, 788 - i * 40); addRadioButton(writer, rect, language, languages[i], i == 0, writer.getPageNumber() + i); } writer.addAnnotation(language); // add the page content for (int i = 0; i < languages.length; i++) { cb.beginText(); cb.setFontAndSize(bf, 18); cb.showTextAligned(Element.ALIGN_LEFT, languages[i], 70, 790 - i * 40, 0); cb.endText(); document.newPage(); } } catch (Exception e) { e.printStackTrace(); } // step 5: we close the document document.close(); }
From source file:questions.javascript.AddJavaScriptToForm.java
public static void createPdf(String filename) throws IOException, DocumentException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open();/* w ww. j a v a2 s.co m*/ BaseFont bf = BaseFont.createFont(); PdfContentByte directcontent = writer.getDirectContent(); directcontent.beginText(); directcontent.setFontAndSize(bf, 12); directcontent.showTextAligned(Element.ALIGN_LEFT, "Married?", 36, 770, 0); directcontent.showTextAligned(Element.ALIGN_LEFT, "YES", 58, 750, 0); directcontent.showTextAligned(Element.ALIGN_LEFT, "NO", 102, 750, 0); directcontent.showTextAligned(Element.ALIGN_LEFT, "Name partner?", 36, 730, 0); directcontent.endText(); PdfFormField married = PdfFormField.createRadioButton(writer, true); married.setFieldName("married"); married.setValueAsName("yes"); Rectangle rectYes = new Rectangle(40, 766, 56, 744); RadioCheckField yes = new RadioCheckField(writer, rectYes, null, "yes"); yes.setChecked(true); married.addKid(yes.getRadioField()); Rectangle rectNo = new Rectangle(84, 766, 100, 744); RadioCheckField no = new RadioCheckField(writer, rectNo, null, "no"); no.setChecked(false); married.addKid(no.getRadioField()); writer.addAnnotation(married); Rectangle rect = new Rectangle(40, 710, 200, 726); TextField partner = new TextField(writer, rect, "partner"); partner.setBorderColor(Color.BLACK); partner.setBorderWidth(0.5f); writer.addAnnotation(partner.getTextField()); document.close(); }