List of usage examples for com.lowagie.text.pdf PdfContentByte showTextAligned
public void showTextAligned(int alignment, String text, float x, float y, float rotation)
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. ja v a2 s. c o 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(); }
From source file:questions.separators.PositionedMarks.java
public void draw(PdfContentByte canvas, float llx, float lly, float urx, float ury, float y) { canvas.beginText();//from w w w. j a v a 2 s .c o m canvas.setFontAndSize(bf, 12); if (start) { canvas.showTextAligned(Element.ALIGN_CENTER, String.valueOf((char) 220), llx - 10, y, 0); } else { canvas.showTextAligned(Element.ALIGN_CENTER, String.valueOf((char) 220), urx + 10, y + 8, 180); } canvas.endText(); }
From source file:questions.separators.StarSeparators.java
public void draw(PdfContentByte canvas, float llx, float lly, float urx, float ury, float y) { float middle = (llx + urx) / 2; canvas.beginText();/* w w w. j av a 2s. c om*/ canvas.setFontAndSize(FONT, 10); canvas.showTextAligned(Element.ALIGN_CENTER, "*", middle, y, 0); canvas.showTextAligned(Element.ALIGN_CENTER, "* *", middle, y - 10, 0); canvas.endText(); }
From source file:questions.stamppages.PageXofYRightAligned.java
public static void main(String[] args) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {/*ww w .ja va2 s . co m*/ Document document = new Document(); PdfWriter.getInstance(document, baos); document.open(); BufferedReader reader = new BufferedReader(new FileReader(RESOURCE)); String line; Paragraph p; while ((line = reader.readLine()) != null) { p = new Paragraph(line); p.setAlignment(Element.ALIGN_JUSTIFIED); document.add(p); document.newPage(); } reader.close(); document.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } try { PdfReader reader = new PdfReader(baos.toByteArray()); int n = reader.getNumberOfPages(); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); PdfContentByte page; Rectangle rect; BaseFont bf = BaseFont.createFont(); for (int i = 1; i < n + 1; i++) { page = stamper.getOverContent(i); rect = reader.getPageSizeWithRotation(i); page.beginText(); page.setFontAndSize(bf, 12); page.showTextAligned(Element.ALIGN_RIGHT, "page " + i + " of " + n, rect.getRight(36), rect.getTop(32), 0); page.endText(); } stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:tufts.vue.PresentationNotes.java
License:Educational Community License
private static void drawSequenceNumber(PdfWriter writer, float x, float y, int seq) { PdfContentByte cb = writer.getDirectContent(); try {/*from w w w .j a v a2s . c om*/ cb.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, false), 16); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } cb.beginText(); cb.showTextAligned(Element.ALIGN_CENTER, new Integer(seq).toString() + ".", x, y, 0f); cb.endText(); cb.stroke(); //return tp2; }