/** * Draws a horizontal line. * @param canvas the canvas to draw on * @param leftX the left x coordinate * @param rightX the right x coordindate * @param y the y coordinate */ public void drawLine(PdfContentByte canvas, float leftX, float rightX, float y) { float w; if (getPercentage() < 0) w = -getPercentage(); else w = (rightX - leftX) * getPercentage() / 100.0f; float s; switch (getAlignment()) { case Element.ALIGN_LEFT: s = 0; break; case Element.ALIGN_RIGHT: s = rightX - leftX - w; break; default: s = (rightX - leftX - w) / 2; break; } canvas.setLineWidth(getLineWidth()); if (getLineColor() != null) canvas.setColorStroke(getLineColor()); canvas.moveTo(s + leftX, y + offset); canvas.lineTo(s + w + leftX, y + offset); canvas.stroke(); }
protected PdfPCell pdfBuildPrefGroupLabel(CourseOffering co, PreferenceGroup prefGroup, String indentSpaces, boolean isEditable, String prevLabel) { if (prefGroup instanceof Class_) { Color color = (isEditable?Color.BLACK:Color.GRAY); String label = prefGroup.toString(); Class_ aClass = (Class_) prefGroup; label = aClass.getClassLabel(co); if (prevLabel != null && label.equals(prevLabel)){ label = ""; } PdfPCell cell = createCell(); addText(cell, indentSpaces+label, co.isIsControl(), false, Element.ALIGN_LEFT, color, true); InstructionalMethod im = aClass.getSchedulingSubpart().getInstrOfferingConfig().getInstructionalMethod(); if (im != null) addText(cell, " (" + im.getReference() + ")", false, false, Element.ALIGN_LEFT, color, false); return cell; } else return super.pdfBuildPrefGroupLabel(co, prefGroup, indentSpaces, isEditable, null); }
@Override protected PdfPCell pdfBuildNote(PreferenceGroup prefGroup, boolean isEditable, UserContext user){ Color color = (isEditable?sEnableColor:sDisableColor); PdfPCell cell = createCell(); if (prefGroup instanceof Class_) { Class_ c = (Class_) prefGroup; String offeringNote = c.getSchedulingSubpart().getInstrOfferingConfig().getInstructionalOffering().getNotes(); String classNote = c.getNotes(); String note = (offeringNote == null || offeringNote.isEmpty() ? classNote : offeringNote + (classNote == null || classNote.isEmpty() ? "" : "\n" + classNote)); if (note != null && !note.isEmpty()) { if (note.length() <= 30 || user == null || CommonValues.NoteAsFullText.eq(user.getProperty(UserProperty.ManagerNoteDisplay))){ addText(cell, note, false, false, Element.ALIGN_LEFT, color, true); } else { if (classNote != null && !classNote.isEmpty()) note = classNote; addText(cell, (note.length() <= 30 ? note : note.substring(0, 30) + "..."), false, false, Element.ALIGN_LEFT, color, true); } } } return cell; }
@Override protected PdfPCell pdfBuildDatePatternCell(ClassAssignmentProxy classAssignment, PreferenceGroup prefGroup, boolean isEditable){ Assignment a = null; if (getDisplayTimetable() && isShowTimetable() && classAssignment!=null && prefGroup instanceof Class_) { try { a = classAssignment.getAssignment((Class_)prefGroup); } catch (Exception e) { Debug.error(e); } } DatePattern dp = (a != null ? a.getDatePattern() : prefGroup.effectiveDatePattern()); PdfPCell cell = createCell(); if (dp!=null) { Color color = (isEditable?sEnableColor:sDisableColor); addText(cell,dp.getName(), false, false, Element.ALIGN_CENTER, color, true); } return cell; }
@Override protected PdfPCell pdfBuildInstructor(PreferenceGroup prefGroup, boolean isEditable){ Color color = (isEditable?sEnableColor:sDisableColor); PdfPCell cell = createCell(); if (prefGroup instanceof Class_) { Class_ aClass = (Class_) prefGroup; if (aClass.isDisplayInstructor()) { TreeSet sortedInstructors = new TreeSet(new InstructorComparator()); sortedInstructors.addAll(aClass.getClassInstructors()); for (Iterator i=sortedInstructors.iterator(); i.hasNext();) { ClassInstructor ci = (ClassInstructor)i.next(); String label = ci.getInstructor().getName(getInstructorNameFormat()); addText(cell, label, false, false, Element.ALIGN_LEFT, color, true); } } } return cell; }
private PdfPCell pdfSubjectAndCourseInfo(InstructionalOffering io, CourseOffering co) { PdfPCell cell = createCell(); addText(cell, (co != null ? co.getSubjectAreaAbbv()+" "+co.getCourseNbr():""), true, false, Element.ALIGN_LEFT, (co.isIsControl().booleanValue()?sEnableColor:sDisableColor), true); InstructionalMethod im = (co != null && co.getInstructionalOffering().getInstrOfferingConfigs().size() == 1 ? co.getInstructionalOffering().getInstrOfferingConfigs().iterator().next().getInstructionalMethod() : null); if (im != null) { if (co.getCourseType() != null) { addText(cell, " (" + co.getCourseType().getReference() + ", " + im.getReference() + ")", false, false, Element.ALIGN_LEFT, (co.isIsControl().booleanValue()?sEnableColor:sDisableColor), false); } else { addText(cell, " (" + im.getReference() + ")", false, false, Element.ALIGN_LEFT, (co.isIsControl().booleanValue()?sEnableColor:sDisableColor), false); } } else if (co.getCourseType() != null) { addText(cell, " (" + co.getCourseType().getReference() + ")", false, false, Element.ALIGN_LEFT, (co.isIsControl().booleanValue()?sEnableColor:sDisableColor), false); } for (Iterator it = io.courseOfferingsMinusSortCourseOfferingForSubjectArea(co.getSubjectArea().getUniqueId()).iterator(); it.hasNext(); ) { CourseOffering tempCo = (org.unitime.timetable.model.CourseOffering) it.next(); addText(cell, indent+""+tempCo.getSubjectAreaAbbv()+" "+tempCo.getCourseNbr() + " " + (tempCo.getCourseType() != null ? " (" + tempCo.getCourseType().getReference() + ")" : ""), false, false, Element.ALIGN_LEFT, sDisableColor, true); } return cell; }
private PdfPCell pdfBuildTimePatternCell(PreferenceGroup prefGroup, boolean isEditable){ Color color = (isEditable?sEnableColor:sDisableColor); PdfPCell cell = createCell(); for (Iterator i=prefGroup.effectiveTimePatterns().iterator(); i.hasNext();) { TimePattern tp = (TimePattern)i.next(); addText(cell, tp.getName(), false, false, Element.ALIGN_CENTER, color, true); } if (prefGroup instanceof Class_ && prefGroup.effectiveTimePatterns().isEmpty()) { Class_ clazz = (Class_)prefGroup; DurationModel dm = clazz.getSchedulingSubpart().getInstrOfferingConfig().getDurationModel(); Integer ah = dm.getArrangedHours(clazz.getSchedulingSubpart().getMinutesPerWk(), clazz.effectiveDatePattern()); if (ah == null) { addText(cell, "Arr Hrs", false, false, Element.ALIGN_CENTER, color, true); } else { addText(cell, "Arr "+ah+" Hrs", false, false, Element.ALIGN_CENTER, color, true); } } return cell; }
private PdfPCell pdfBuildPrefGroupDemand(PreferenceGroup prefGroup, boolean isEditable){ if (prefGroup instanceof Class_) { Class_ c = (Class_) prefGroup; if (StudentClassEnrollment.sessionHasEnrollments(c.getSessionId())){ PdfPCell tc = createCell(); if (c.getEnrollment() != null){ addText(tc, c.getEnrollment().toString()); } else { addText(tc, "0"); } tc.setHorizontalAlignment(Element.ALIGN_RIGHT); return(tc); } } return createCell(); }
private PdfPCell pdfBuildSnapshotLimit(PreferenceGroup prefGroup, boolean isEditable){ Color color = (isEditable?sEnableColor:sDisableColor); PdfPCell cell = createCell(); if (prefGroup instanceof Class_){ Class_ aClass = (Class_) prefGroup; boolean unlimited = aClass.getSchedulingSubpart().getInstrOfferingConfig().isUnlimitedEnrollment().booleanValue(); if (!unlimited) { String limitString = null; if (aClass.getSnapshotLimit() == null) { limitString = ""; } else { limitString = aClass.getSnapshotLimit().toString(); } addText(cell, limitString, false, false, Element.ALIGN_RIGHT, color, true); } } return cell; }
protected PdfPCell pdfBuildInstructorAssignment(PreferenceGroup prefGroup, boolean isEditable){ Color color = (isEditable?sEnableColor:sDisableColor); PdfPCell cell = createCell(); if (prefGroup instanceof Class_) { Class_ c = (Class_) prefGroup; if (c.isInstructorAssignmentNeeded()) { addText(cell, (c.effectiveNbrInstructors() > 1 ? c.effectiveNbrInstructors() + " \u00d7 " : "") + Formats.getNumberFormat("0.##").format(c.effectiveTeachingLoad()) + " " + MSG.teachingLoadUnits(), false, false, Element.ALIGN_RIGHT, color, false); } else if (c.getSchedulingSubpart().isInstructorAssignmentNeeded()) { addText(cell, MSG.cellNoInstructorAssignment(), false, false, Element.ALIGN_RIGHT, color, false); } } else if (prefGroup instanceof SchedulingSubpart) { SchedulingSubpart ss = (SchedulingSubpart)prefGroup; if (ss.isInstructorAssignmentNeeded()) { addText(cell, (ss.getNbrInstructors() > 1 ? ss.getNbrInstructors() + " \u00d7 " : "") + Formats.getNumberFormat("0.##").format(ss.getTeachingLoad()) + " " + MSG.teachingLoadUnits(), false, false, Element.ALIGN_RIGHT, color, false); } } return cell; }
protected PdfPCell pdfBuildInstructor(PreferenceGroup prefGroup, boolean isEditable){ Color color = (isEditable?sEnableColor:sDisableColor); PdfPCell cell = createCell(); if (prefGroup instanceof Class_) { Class_ aClass = (Class_) prefGroup; TreeSet sortedInstructors = new TreeSet(new InstructorComparator()); sortedInstructors.addAll(aClass.getClassInstructors()); for (Iterator i=sortedInstructors.iterator(); i.hasNext();) { ClassInstructor ci = (ClassInstructor)i.next(); String label = ci.getInstructor().getName(getInstructorNameFormat()); if (ci.getResponsibility() != null && ci.getResponsibility().getAbbreviation() != null && !ci.getResponsibility().getAbbreviation().isEmpty()) label += " (" + ci.getResponsibility().getAbbreviation() + ")"; boolean italic = !aClass.isDisplayInstructor().booleanValue(); boolean bold = ci.isLead().booleanValue(); addText(cell, label, bold, italic, Element.ALIGN_LEFT, color, true); } } return cell; }
private PdfPCell pdfBuildSchedulePrintNote(PreferenceGroup prefGroup, boolean isEditable, UserContext user) { Color color = (isEditable?sEnableColor:sDisableColor); PdfPCell cell = createCell(); if (prefGroup instanceof Class_) { Class_ c = (Class_) prefGroup; if (c.getSchedulePrintNote()!=null) { if (c.getSchedulePrintNote().length() <= 20 || user == null || CommonValues.NoteAsFullText.eq(user.getProperty(UserProperty.SchedulePrintNoteDisplay))){ addText(cell, c.getSchedulePrintNote(), false, false, Element.ALIGN_LEFT, color, true); } else { addText(cell, c.getSchedulePrintNote().substring(0,20) + "...", false, false, Element.ALIGN_LEFT, color, true); } } } return cell; }
private PdfPCell pdfBuildSchedulePrintNote(InstructionalOffering io, boolean isEditable, UserContext user){ Color color = (isEditable?sEnableColor:sDisableColor); PdfPCell cell = createCell(); StringBuffer note = new StringBuffer(""); Set s = io.getCourseOfferings(); for (Iterator i=s.iterator(); i.hasNext(); ) { CourseOffering coI = (CourseOffering) i.next(); if (coI.getScheduleBookNote()!=null && coI.getScheduleBookNote().trim().length()>0) { if (note.length()>0) note.append("\n"); if (coI.getScheduleBookNote().length() <= 20 || Constants.showCrsOffrAsFullText(user)){ note.append(coI.getScheduleBookNote()); } else { note.append(coI.getScheduleBookNote().substring(0, 20) + "..."); } } } addText(cell, note.toString(), false, false, Element.ALIGN_LEFT, color, true); return(cell); }
protected PdfPCell pdfBuildNote(PreferenceGroup prefGroup, boolean isEditable, UserContext user){ Color color = (isEditable?sEnableColor:sDisableColor); PdfPCell cell = createCell(); if (prefGroup instanceof Class_) { Class_ c = (Class_) prefGroup; if (c.getNotes()!=null) { if (c.getNotes().length() <= 30 || user == null || CommonValues.NoteAsFullText.eq(user.getProperty(UserProperty.ManagerNoteDisplay))){ addText(cell, c.getNotes(), false, false, Element.ALIGN_LEFT, color, true); } else { addText(cell, c.getNotes().substring(0, 30) + "...", false, false, Element.ALIGN_LEFT, color, true); } } } return cell; }
private PdfPCell pdfBuildManager(PreferenceGroup prefGroup, boolean isEditable){ Color color = (isEditable?sEnableColor:sDisableColor); PdfPCell cell = createCell(); Department managingDept = null; if (prefGroup instanceof Class_) { managingDept = ((Class_)prefGroup).getManagingDept(); } else if (prefGroup instanceof SchedulingSubpart) { managingDept = ((SchedulingSubpart)prefGroup).getManagingDept(); } if (managingDept!=null) { addText(cell, managingDept.getShortLabel(), false, false, Element.ALIGN_LEFT, color, true); } return cell; }
private PdfPCell pdfBuildExamPeriod(ExamAssignmentProxy examAssignment, TreeSet exams, boolean isEditable) { StringBuffer sb = new StringBuffer(); for (Iterator i=exams.iterator();i.hasNext();) { Exam exam = (Exam)i.next(); if (examAssignment!=null && examAssignment.getExamTypeId().equals(exam.getExamType().getUniqueId())) { ExamAssignment ea = examAssignment.getAssignment(exam.getUniqueId()); if (ea==null && !isShowExamName()) continue; sb.append(ea==null?"":ea.getPeriodAbbreviation()); } else { if (exam.getAssignedPeriod()==null && !isShowExamName()) continue; sb.append(exam.getAssignedPeriod()==null?"":exam.getAssignedPeriod().getAbbreviation()); } if (i.hasNext()) sb.append("\n"); } Color color = (isEditable?sEnableColor:sDisableColor); PdfPCell cell = createCell(); addText(cell, sb.toString(), false, false, Element.ALIGN_LEFT, color, true); return cell; }
private PdfPCell pdfBuildExamRoom(ExamAssignmentProxy examAssignment, TreeSet exams, boolean isEditable) { StringBuffer sb = new StringBuffer(); for (Iterator i=exams.iterator();i.hasNext();) { Exam exam = (Exam)i.next(); if (examAssignment!=null && examAssignment.getExamTypeId().equals(exam.getExamType().getUniqueId())) { ExamAssignment ea = examAssignment.getAssignment(exam.getUniqueId()); if (ea==null && !isShowExamName()) continue; sb.append(ea==null?"":ea.getRoomsName(", ")); } else { if (exam.getAssignedPeriod()==null && !isShowExamName()) continue; for (Iterator j=new TreeSet(exam.getAssignedRooms()).iterator();j.hasNext();) { Location location = (Location)j.next(); sb.append(location.getLabel()); if (j.hasNext()) sb.append(", "); } } if (i.hasNext()) sb.append("\n"); } Color color = (isEditable?sEnableColor:sDisableColor); PdfPCell cell = createCell(); addText(cell, sb.toString(), false, false, Element.ALIGN_LEFT, color, true); return cell; }
private float addImage(PdfPCell cell, String name) { try { java.awt.Image awtImage = (java.awt.Image)iImages.get(name); if (awtImage==null) return 0; Image img = Image.getInstance(awtImage, Color.WHITE); Chunk ck = new Chunk(img, 0, 0); if (cell.getPhrase()==null) { cell.setPhrase(new Paragraph(ck)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); } else { cell.getPhrase().add(ck); } return awtImage.getWidth(null); } catch (Exception e) { return 0; } }
private float addText(PdfPCell cell, String text, boolean bold, boolean italic, boolean underline, Color color, Color bgColor) { Font font = PdfFont.getFont(bold, italic, underline, color); Chunk chunk = new Chunk(text, font); if (bgColor!=null) chunk.setBackground(bgColor); if (cell.getPhrase()==null) { cell.setPhrase(new Paragraph(chunk)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); } else { cell.getPhrase().add(chunk); } float width = 0; if (text.indexOf('\n')>=0) { for (StringTokenizer s = new StringTokenizer(text,"\n"); s.hasMoreTokens();) width = Math.max(width,font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize())); } else width = Math.max(width,font.getBaseFont().getWidthPoint(text, font.getSize())); return width; }
@Override protected void buildPdfDocument(Map<String, Object> model, Document document, PdfWriter writer, HttpServletRequest request, HttpServletResponse response) throws Exception { List<Book> books = (List<Book>) model.get("book"); PdfPTable table = new PdfPTable(3); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.getDefaultCell().setBackgroundColor(Color.lightGray); table.addCell("Book Name"); table.addCell("Author Name"); table.addCell("Price"); for (Book book : books) { table.addCell(book.getBookName()); table.addCell(book.getAuthor()); table.addCell("" + book.getPrice()); } document.add(table); }
/** Creates new BarcodeInter25 */ public BarcodeInter25() { try { x = 0.8f; n = 2; font = BaseFont.createFont("Helvetica", "winansi", false); size = 8; baseline = size; barHeight = size * 3; textAlignment = Element.ALIGN_CENTER; generateChecksum = false; checksumText = false; } catch (Exception e) { throw new ExceptionConverter(e); } }
/** Creates a new Barcode39. */ public Barcode39() { try { x = 0.8f; n = 2; font = BaseFont.createFont("Helvetica", "winansi", false); size = 8; baseline = size; barHeight = size * 3; textAlignment = Element.ALIGN_CENTER; generateChecksum = false; checksumText = false; startStopText = true; extended = false; } catch (Exception e) { throw new ExceptionConverter(e); } }
/** Creates a new BarcodeCodabar. */ public BarcodeCodabar() { try { x = 0.8f; n = 2; font = BaseFont.createFont("Helvetica", "winansi", false); size = 8; baseline = size; barHeight = size * 3; textAlignment = Element.ALIGN_CENTER; generateChecksum = false; checksumText = false; startStopText = false; codeType = CODABAR; } catch (Exception e) { throw new ExceptionConverter(e); } }
/** * Returns the left indentation of the line taking the alignment of the line into account. * * @return a value */ float indentLeft() { if (isRTL) { switch (alignment) { case Element.ALIGN_LEFT: return left + width; case Element.ALIGN_CENTER: return left + (width / 2f); default: return left; } } else if (this.getSeparatorCount() == 0) { switch (alignment) { case Element.ALIGN_RIGHT: return left + width; case Element.ALIGN_CENTER: return left + (width / 2f); } } return left; }
private void insertTable_TextRow( PdfWriter writer, PdfPTable mainTable, String text, Font font ) { boolean hasBorder = false; // Add Organization ID/Period textfield // Create A table to add for each group AT HERE PdfPTable table = new PdfPTable( 1 ); table.setHorizontalAlignment( Element.ALIGN_LEFT ); addCell_Text( table, PdfDataEntryFormUtil.getPdfPCell( hasBorder ), text, Element.ALIGN_LEFT, font ); // Add to the main table PdfPCell cell_withInnerTable = new PdfPCell( table ); cell_withInnerTable.setBorder( Rectangle.NO_BORDER ); mainTable.addCell( cell_withInnerTable ); }
public void setToDefaults() { styleName = ""; styleNr = 0; alignment = Element.ALIGN_LEFT; justificationPercentage = 0; firstLineIndent = 0; leftIndent = 0; rightIndent = 0; adustRightIndent = 0; mirrorIndent = 0; overrideWidowControl = -1; AutoSpaceBetweenDBCEnglish = 0; AutoSpaceBetweenDBCNumbers = 0; noCharacterWrapping = 0; noWordWrapping = 0; noOverflowPeriodComma = 0; }
/** * Adds an Element to the Document * * @param element The element to be added * @return <code>false</code> * @throws DocumentException */ public boolean add(Element element) throws DocumentException { if (pause) { return false; } RtfBasicElement[] rtfElements = rtfDoc.getMapper().mapElement(element); if(rtfElements.length != 0) { for(int i = 0; i < rtfElements.length; i++) { if(rtfElements[i] != null) { rtfDoc.add(rtfElements[i]); } } return true; } else { return false; } }
/** * Constructs a RtfHeaderFooter as a copy of an existing RtfHeaderFooter. * For internal use only. * * @param doc The RtfDocument this RtfHeaderFooter belongs to * @param headerFooter The RtfHeaderFooter to copy * @param displayAt The display location of this RtfHeaderFooter */ protected RtfHeaderFooter(RtfDocument doc, RtfHeaderFooter headerFooter, int displayAt) { super(new Phrase(""), false); this.document = doc; this.content = headerFooter.getContent(); this.displayAt = displayAt; for(int i = 0; i < this.content.length; i++) { if(this.content[i] instanceof Element) { try { this.content[i] = this.document.getMapper().mapElement((Element) this.content[i])[0]; } catch(DocumentException de) { de.printStackTrace(); } } if(this.content[i] instanceof RtfBasicElement) { ((RtfBasicElement) this.content[i]).setInHeader(true); } } }
/** * Sets the RtfDocument this RtfElement belongs to * * @param doc The RtfDocument to use */ public void setRtfDocument(RtfDocument doc) { this.document = doc; if(this.document != null) { for(int i = 0; i < this.content.length; i++) { try { if(this.content[i] instanceof Element) { this.content[i] = this.document.getMapper().mapElement((Element) this.content[i])[0]; ((RtfBasicElement) this.content[i]).setInHeader(true); } else if(this.content[i] instanceof RtfBasicElement){ ((RtfBasicElement) this.content[i]).setRtfDocument(this.document); ((RtfBasicElement) this.content[i]).setInHeader(true); } } catch(DocumentException de) { de.printStackTrace(); } } } }
/** * Translates the alignment value. * * @param alignment the alignment value * @return the translated value */ public static String getAlignment(int alignment) { switch(alignment) { case Element.ALIGN_LEFT: return HtmlTags.ALIGN_LEFT; case Element.ALIGN_CENTER: return HtmlTags.ALIGN_CENTER; case Element.ALIGN_RIGHT: return HtmlTags.ALIGN_RIGHT; case Element.ALIGN_JUSTIFIED: case Element.ALIGN_JUSTIFIED_ALL: return HtmlTags.ALIGN_JUSTIFIED; case Element.ALIGN_TOP: return HtmlTags.ALIGN_TOP; case Element.ALIGN_MIDDLE: return HtmlTags.ALIGN_MIDDLE; case Element.ALIGN_BOTTOM: return HtmlTags.ALIGN_BOTTOM; case Element.ALIGN_BASELINE: return HtmlTags.ALIGN_BASELINE; default: return ""; } }
private void addCell_WithTextField( PdfPTable table, Rectangle rect, PdfWriter writer, PdfPCell cell, String strfldName, int fieldCellType, String value ) throws IOException, DocumentException { TextField nameField = new TextField( writer, rect, strfldName ); nameField.setBorderWidth( 1 ); nameField.setBorderColor( Color.BLACK ); nameField.setBorderStyle( PdfBorderDictionary.STYLE_SOLID ); nameField.setBackgroundColor( COLOR_BACKGROUDTEXTBOX ); nameField.setText( value ); nameField.setAlignment( Element.ALIGN_RIGHT ); nameField.setFont( pdfFormFontSettings.getFont( PdfFormFontSettings.FONTTYPE_BODY ).getBaseFont() ); cell.setCellEvent( new PdfFieldCell( nameField.getTextField(), rect.getWidth(), rect.getHeight(), fieldCellType, writer ) ); table.addCell( cell ); }
/** * Generates a document with a header containing Page x of y and with a Watermark on every page. */ @Test public void main() throws Exception { // step 1: creating the document Document doc = new Document(PageSize.A4, 50, 50, 100, 72); // step 2: creating the writer PdfWriter writer = PdfWriter.getInstance(doc, PdfTestBase.getOutputStream( "pageNumbersWatermark.pdf")); // step 3: initialisations + opening the document writer.setPageEvent(new PageNumbersWatermarkTest()); doc.open(); // step 4: adding content String text = "some padding text "; for (int k = 0; k < 10; ++k) { text += text; } Paragraph p = new Paragraph(text); p.setAlignment(Element.ALIGN_JUSTIFIED); doc.add(p); // step 5: closing the document doc.close(); }
/** * @see com.lowagie.text.pdf.PdfPageEventHelper#onStartPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document) */ public void onStartPage(PdfWriter writer, Document document) { if (writer.getPageNumber() < 3) { PdfContentByte cb = writer.getDirectContentUnder(); cb.saveState(); cb.setColorFill(Color.pink); cb.beginText(); cb.setFontAndSize(helv, 48); cb.showTextAligned(Element.ALIGN_CENTER, "My Watermark Under " + writer.getPageNumber(), document.getPageSize().getWidth() / 2, document.getPageSize().getHeight() / 2, 45); cb.endText(); cb.restoreState(); } }
protected void writePageAnchor(int pageIndex) throws DocumentException { Map<Attribute,Object> attributes = new HashMap<Attribute,Object>(); fontUtil.getAttributesWithoutAwtFont(attributes, new JRBasePrintText(jasperPrint.getDefaultStyleProvider())); Font pdfFont = getFont(attributes, getLocale(), false); Chunk chunk = new Chunk(" ", pdfFont); chunk.setLocalDestination(JR_PAGE_ANCHOR_PREFIX + reportIndex + "_" + (pageIndex + 1)); tagHelper.startPageAnchor(); ColumnText colText = new ColumnText(pdfContentByte); colText.setSimpleColumn( new Phrase(chunk), 0, pageFormat.getPageHeight(), 1, 1, 0, Element.ALIGN_LEFT ); colText.go(); tagHelper.endPageAnchor(); }
/** * Space Word Ratio. */ @Test public void main() throws Exception { // step 1 Document document = new Document(PageSize.A4, 50, 350, 50, 50); // step 2 PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("spacewordratio.pdf")); // step 3 document.open(); // step 4 String text = "Flanders International Filmfestival Ghent - Internationaal Filmfestival van Vlaanderen Gent"; Paragraph p = new Paragraph(text); p.setAlignment(Element.ALIGN_JUSTIFIED); document.add(p); document.newPage(); writer.setSpaceCharRatio(PdfWriter.NO_SPACE_CHAR_RATIO); document.add(p); // step 5 document.close(); }
private static void anadirTextoTabla(PdfPTable tabla, String titulo, String desc) { PdfPCell cell = new PdfPCell(); disableBorders(cell); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.addElement(new Phrase(titulo,fuente10)); tabla.addCell(cell); cell = new PdfPCell(); disableBorders(cell); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.addElement(new Phrase(defaultString(desc),fuente10)); tabla.addCell(cell); }
@Test public void testSimplePdf() throws FileNotFoundException, DocumentException { BaseFont font = null; try { font = BaseFont.createFont("LiberationSerif-Regular.ttf", BaseFont.IDENTITY_H, false); } catch (IOException ioe) { // nop } Document document = null; try { document = PdfTestBase.createPdf("unicode.pdf"); // new page with a rectangle document.open(); Element unicodeParagraph = new Paragraph(INPUT, new Font(font, 12)); document.add(unicodeParagraph); } finally { // close document if (document != null) document.close(); } }
private PdfPTable createNeedHeader(String name) throws DocumentException { Font whiteFont = new Font(Font.HELVETICA,14,Font.BOLD,Color.WHITE); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100); table.setWidths(new float[]{0.10f,0.20f,0.70f}); PdfPCell emptyCell = new PdfPCell(); emptyCell.setBorder(0); table.addCell(emptyCell); PdfPCell headerCell = new PdfPCell(); headerCell.setColspan(2); headerCell.setPhrase(new Phrase(name,whiteFont)); headerCell.setHorizontalAlignment(Element.ALIGN_CENTER); headerCell.setBackgroundColor(Color.LIGHT_GRAY); table.addCell(headerCell); return table; }
private float addDynamicPositionedText(String name, String text, float dynamicHeight, EctConsultationFormRequestUtil reqForm) throws DocumentException { if (text != null && text.length() > 0){ Font boldFont = new Font(bf, FONTSIZE, Font.BOLD); Font font = new Font(bf, FONTSIZE, Font.NORMAL); float lineCount = (name.length() + text.length()) / 100; // if there is not enough room on the page for the text start on the next page if ( (height - 264 - dynamicHeight - lineCount*LINEHEIGHT) < LINEHEIGHT*3 ){ nextPage(reqForm); dynamicHeight = LINEHEIGHT - 152; } ct.setSimpleColumn(new Float(85), height - 264 - dynamicHeight - lineCount*LINEHEIGHT, new Float(526), height - 250 - dynamicHeight, LINEHEIGHT, Element.ALIGN_LEFT); ct.addText(new Phrase(name, boldFont)); ct.addText(new Phrase(text, font)); ct.go(); dynamicHeight += lineCount*LINEHEIGHT + LINEHEIGHT*2; } return dynamicHeight; }
public PdfPCell createCell() { PdfPCell cell = new PdfPCell(); cell.setBorderColor(sBorderColor); cell.setPadding(3); cell.setBorderWidth(0); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthTop(1); cell.setBorderWidthBottom(1); cell.setBorderWidthLeft(1); cell.setBorderWidthRight(1); return cell; }