List of usage examples for com.lowagie.text.pdf PdfReader PdfReader
public PdfReader(PdfReader reader)
From source file:classroom.newspaper_a.Newspaper01.java
public static void main(String[] args) { try {/*from w w w . j a v a 2 s.c o m*/ PdfReader reader = new PdfReader(NEWSPAPER); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); PdfContentByte canvas = stamper.getOverContent(1); canvas.setRGBColorFill(0xC0, 0xC0, 0xC0); canvas.setRGBColorStroke(0xFF, 0x00, 0x00); canvas.rectangle(LLX1, LLY1, W1, H1); canvas.rectangle(LLX2, LLY2, W2, H2); canvas.fillStroke(); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:classroom.newspaper_a.Newspaper02.java
public static void main(String[] args) { try {/*w w w . j a v a2 s. c o m*/ PdfReader reader = new PdfReader(NEWSPAPER); Document document = new Document(reader.getPageSizeWithRotation(1)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); PdfContentByte content = writer.getDirectContent(); content.rectangle(document.left(), document.bottom(), document.right(), document.top()); content.rectangle(LLX1, LLY1, W1, H1); content.rectangle(LLX2, LLY2, W2, H2); content.eoClip(); content.newPath(); PdfImportedPage page = writer.getImportedPage(reader, 1); content.addTemplate(page, 0, 0); document.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:classroom.newspaper_a.Newspaper03.java
public static void main(String[] args) { try {/* w w w. j a va 2 s . c o m*/ PdfReader reader = new PdfReader(NEWSPAPER); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); PdfContentByte canvas = stamper.getOverContent(1); canvas.saveState(); canvas.setRGBColorFill(0xFF, 0xFF, 0xFF); canvas.rectangle(LLX1, LLY1, W1, H1); canvas.rectangle(LLX2, LLY2, W2, H2); canvas.fillStroke(); canvas.restoreState(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); putText(canvas, MESSAGE, bf, LLX1, LLY1, URX1, URY1); putText(canvas, MESSAGE, bf, LLX2, LLY2, URX2, URY2); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:classroom.newspaper_a.Newspaper04.java
public static void main(String[] args) { try {/*from w w w. j a v a 2 s. co m*/ PdfReader reader = new PdfReader(NEWSPAPER); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); PdfContentByte canvas = stamper.getOverContent(1); canvas.saveState(); canvas.setRGBColorFill(0xFF, 0xFF, 0xFF); canvas.rectangle(LLX1, LLY1, W1, H1); canvas.rectangle(LLX2, LLY2, W2, H2); canvas.fillStroke(); canvas.restoreState(); Phrase p = new Phrase(MESSAGE); putText(canvas, p, LLX1, LLY1, URX1, URY1); putText(canvas, p, LLX2, LLY2, URX2, URY2); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:classroom.newspaper_a.Newspaper05.java
public static void main(String[] args) { try {// w ww.j a va2 s . c om PdfReader reader = new PdfReader(NEWSPAPER); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); PdfContentByte canvas = stamper.getOverContent(1); canvas.saveState(); canvas.setRGBColorFill(0xFF, 0xFF, 0xFF); canvas.rectangle(LLX1, LLY1, W1, H1); canvas.rectangle(LLX2, LLY2, W2, H2); canvas.fillStroke(); canvas.restoreState(); Phrase p = new Phrase(MESSAGE); putText(canvas, p, LLX1, LLY1, W1, H1); putText(canvas, p, LLX2, LLY2, W2, H2); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:classroom.newspaper_a.Newspaper06.java
public static void main(String[] args) { try {/*from w ww.ja v a 2 s . co m*/ PdfReader reader = new PdfReader(NEWSPAPER); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); PdfContentByte canvas = stamper.getOverContent(1); canvas.saveState(); canvas.setRGBColorFill(0xFF, 0xFF, 0xFF); canvas.rectangle(LLX1, LLY1, W1, H1); canvas.rectangle(LLX2, LLY2, W2, H2); canvas.fill(); canvas.restoreState(); putImage(canvas, Image.getInstance(IMG1), LLX1, LLY1, W1, H1); putImage(canvas, Image.getInstance(IMG2), LLX2, LLY2, W2, H2); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:classroom.newspaper_a.Newspaper07.java
public static void main(String[] args) { try {/*w w w .jav a 2s .c om*/ PdfReader reader = new PdfReader(NEWSPAPER); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); PdfContentByte canvas = stamper.getOverContent(1); canvas.saveState(); canvas.setRGBColorFill(0xFF, 0xFF, 0xFF); canvas.rectangle(LLX1, LLY1, W1, H1); canvas.rectangle(LLX2, LLY2, W2, H2); canvas.fill(); canvas.restoreState(); putImage(canvas, Image.getInstance(IMG1), "http://www.manning.com/affiliate/idevaffiliate.php?id=223_0_3_14", LLX1, LLY1, W1, H1); putImage(canvas, Image.getInstance(IMG2), "http://www.1t3xt.com/docs/book.php", LLX2, LLY2, W2, H2); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:classroom.newspaper_b.Newspaper08.java
public static void main(String[] args) { try {//from w w w. j a v a 2s . c o m PdfReader reader = new PdfReader(NEWSPAPER); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); PdfAnnotation annotation1 = PdfAnnotation.createText(stamper.getWriter(), new Rectangle(LLX1, LLY1, URX1, URY1), "Advertisement 1", MESSAGE, false, "Insert"); PdfAppearance ap = stamper.getOverContent(1).createAppearance(W1, H1); ap.setRGBColorStroke(0xFF, 0x00, 0x00); ap.setLineWidth(3); ap.moveTo(0, 0); ap.lineTo(W1, H1); ap.moveTo(W1, 0); ap.lineTo(0, H1); ap.stroke(); annotation1.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, ap); stamper.addAnnotation(annotation1, 1); PdfAnnotation annotation2 = PdfAnnotation.createText(stamper.getWriter(), new Rectangle(LLX2, LLY2, URX2, URY2), "Advertisement 2", MESSAGE, true, "Insert"); annotation2.put(PdfName.C, new PdfArray(new float[] { 0, 0, 1 })); stamper.addAnnotation(annotation2, 1); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:classroom.newspaper_b.Newspaper09.java
public static void main(String[] args) { try {/* w w w . jav a 2 s . co m*/ PdfReader reader = new PdfReader(NEWSPAPER); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); PdfAnnotation annotation1 = PdfAnnotation.createSquareCircle(stamper.getWriter(), new Rectangle(LLX1, LLY1, URX1, URY1), MESSAGE, true); annotation1.put(PdfName.T, new PdfString("Advertisement 1")); annotation1.put(PdfName.C, new PdfArray(new float[] { 1, 0, 0 })); stamper.addAnnotation(annotation1, 1); PdfAnnotation annotation2 = PdfAnnotation.createText(stamper.getWriter(), new Rectangle(LLX2, LLY2, URX2, URY2), "Advertisement 2", MESSAGE, false, null); annotation2.put(PdfName.NM, new PdfString("ad2")); // the text must be read only, and the annotation set to NOVIEW annotation2.put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_READONLY | PdfAnnotation.FLAGS_NOVIEW)); // we create a popup annotation that will define where the rectangle will appear PdfAnnotation popup = PdfAnnotation.createPopup(stamper.getWriter(), new Rectangle(LLX2 + 50, LLY2 + 120, URX2 - 80, URY2 - 120), null, false); // we add a reference to the text annotation to the popup annotation popup.put(PdfName.PARENT, annotation2.getIndirectReference()); // we add a reference to the popup annotation to the text annotation annotation2.put(PdfName.POPUP, popup.getIndirectReference()); // we add both annotations to the writer stamper.addAnnotation(annotation2, 1); stamper.addAnnotation(popup, 1); // the text annotation can't be viewed (it's invisible) // we create a widget annotation named mywidget (it's a button field) PushbuttonField field = new PushbuttonField(stamper.getWriter(), new Rectangle(LLX2, LLY2, URX2, URY2), "button"); PdfAnnotation widget = field.getField(); PdfDictionary dict = new PdfDictionary(); // we write some javascript that makes the popup of the text annotation visible/invisible on mouse enter/exit String js1 = "var t = this.getAnnot(this.pageNum, 'ad2'); t.popupOpen = true; var w = this.getField('button'); w.setFocus();"; PdfAction enter = PdfAction.javaScript(js1, stamper.getWriter()); dict.put(PdfName.E, enter); String js2 = "var t = this.getAnnot(this.pageNum, 'ad2'); t.popupOpen = false;"; PdfAction exit = PdfAction.javaScript(js2, stamper.getWriter()); dict.put(PdfName.X, exit); // we add the javascript as additional action widget.put(PdfName.AA, dict); // we add the button field stamper.addAnnotation(widget, 1); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:classroom.newspaper_b.Newspaper10.java
public static void main(String[] args) { try {/*from ww w .ja v a 2 s . co m*/ PdfReader reader = new PdfReader(NEWSPAPER); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); PushbuttonField button; Rectangle rect; rect = new Rectangle(100, 980, 700, 1000); button = new PushbuttonField(stamper.getWriter(), rect, "click"); button.setBackgroundColor(Color.ORANGE); button.setText("Click here to close window"); button.setLayout(PushbuttonField.LAYOUT_LABEL_ONLY); button.setAlignment(Element.ALIGN_RIGHT); PdfFormField menubar = button.getField(); String js = "var f1 = getField('click'); f1.display = display.hidden;" + "var f2 = getField('advertisement'); f2.display = display.hidden;"; menubar.setAction(PdfAction.javaScript(js, stamper.getWriter())); stamper.addAnnotation(menubar, 1); rect = new Rectangle(100, 500, 700, 980); button = new PushbuttonField(stamper.getWriter(), rect, "advertisement"); button.setBackgroundColor(Color.WHITE); button.setBorderColor(Color.ORANGE); button.setImage(Image.getInstance(IMG)); button.setText("Buy the book iText in Action"); button.setLayout(PushbuttonField.LAYOUT_LABEL_TOP_ICON_BOTTOM); PdfFormField advertisement = button.getField(); advertisement.setAction(new PdfAction("http://www.1t3xt.com/docs/book.php")); stamper.addAnnotation(advertisement, 1); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }