Java Code Examples for com.lowagie.text.Element

The following examples show how to use com.lowagie.text.Element. These examples are extracted from open source projects. 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 Project: itext2   Author: albfernandez   File: SpaceWordRatioTest.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #2
Source Project: pentaho-reporting   Author: pentaho   File: PdfLogicalPageDrawable.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public ColumnText reconfigure( PdfContentByte cb, Phrase p ) {
  float filledWidth = ColumnText.getWidth( p, runDirection, 0 ) + 0.5f;
  ColumnText ct = new ColumnText( cb );
  ct.setRunDirection( runDirection );
  if ( alignment == Element.ALIGN_LEFT ) {
    ct.setSimpleColumn( llx, lly, llx + filledWidth, ury, leading, alignment );
  } else if ( alignment == Element.ALIGN_RIGHT ) {
    ct.setSimpleColumn( urx - filledWidth, lly, urx, ury, leading, alignment );
  } else if ( alignment == Element.ALIGN_CENTER ) {
    float delta = ( ( urx - llx ) - filledWidth ) / 2;
    ct.setSimpleColumn( urx + delta, lly, urx - delta, ury, leading, alignment );
  } else {
    ct.setSimpleColumn( llx, lly, urx, ury, leading, alignment );
  }
  return ct;
}
 
Example #3
Source Project: gcs   Author: richardwilkes   File: Barcode39.java    License: Mozilla Public License 2.0 6 votes vote down vote up
/** 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);
    }
}
 
Example #4
Source Project: kfs   Author: kuali   File: CustomerLoadServiceImpl.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
protected void writeCustomerSectionTitle(Document pdfDoc, String customerNameLine) {
    Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD + Font.UNDERLINE);

    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_LEFT);
    paragraph.add(new Chunk(customerNameLine, font));

    //  blank line
    paragraph.add(new Chunk("", font));

    try {
        pdfDoc.add(paragraph);
    }
    catch (DocumentException e) {
        LOG.error("iText DocumentException thrown when trying to write content.", e);
        throw new RuntimeException("iText DocumentException thrown when trying to write content.", e);
    }
}
 
Example #5
Source Project: gcs   Author: richardwilkes   File: LineSeparator.java    License: Mozilla Public License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #6
Source Project: MesquiteCore   Author: MesquiteProject   File: MarkupParser.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns an object based on a tag and its attributes.
 * @param attributes a Properties object with the tagname and the attributes of the tag.
 * @return an iText object
 */
public Element getObject(Properties attributes) {
	String key = getKey(attributes);
	Properties styleattributes = (Properties)stylecache.get(key);
	if (styleattributes != null && MarkupTags.CSS_VALUE_HIDDEN.equals(styleattributes.get(MarkupTags.CSS_KEY_VISIBILITY))) {
		return null;
	}
	String display = styleattributes.getProperty(MarkupTags.CSS_KEY_DISPLAY);
	Element element = null;
	if (MarkupTags.CSS_VALUE_INLINE.equals(display)) {
		element = retrievePhrase(getFont(attributes), styleattributes);
	}
	else if (MarkupTags.CSS_VALUE_BLOCK.equals(display)) {
		element = retrieveParagraph(getFont(attributes), styleattributes);
	}
	else if (MarkupTags.CSS_VALUE_LISTITEM.equals(display)) {
		element = retrieveListItem(getFont(attributes), styleattributes);
	}
	else if (MarkupTags.CSS_VALUE_TABLECELL.equals(display)) {
		element = retrieveTableCell(getFont(attributes), styleattributes);
	}
	else if (MarkupTags.CSS_VALUE_TABLE.equals(display)) {
		element = retrieveTable(styleattributes);
	}
	return element;
}
 
Example #7
Source Project: unitime   Author: UniTime   File: PdfInstructionalOfferingTableBuilder.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #8
Source Project: pentaho-reporting   Author: pentaho   File: RTFPrinter.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
private void computeCellStyle( final RenderBox content, final Cell cell ) {
  final ElementAlignment verticalAlign = content.getNodeLayoutProperties().getVerticalAlignment();
  if ( ElementAlignment.BOTTOM.equals( verticalAlign ) ) {
    cell.setVerticalAlignment( Element.ALIGN_BOTTOM );
  } else if ( ElementAlignment.MIDDLE.equals( verticalAlign ) ) {
    cell.setVerticalAlignment( Element.ALIGN_MIDDLE );
  } else {
    cell.setVerticalAlignment( Element.ALIGN_TOP );
  }

  final ElementAlignment textAlign =
      (ElementAlignment) content.getStyleSheet().getStyleProperty( ElementStyleKeys.ALIGNMENT );
  if ( ElementAlignment.RIGHT.equals( textAlign ) ) {
    cell.setHorizontalAlignment( Element.ALIGN_RIGHT );
  } else if ( ElementAlignment.JUSTIFY.equals( textAlign ) ) {
    cell.setHorizontalAlignment( Element.ALIGN_JUSTIFIED );
  } else if ( ElementAlignment.CENTER.equals( textAlign ) ) {
    cell.setHorizontalAlignment( Element.ALIGN_CENTER );
  } else {
    cell.setHorizontalAlignment( Element.ALIGN_LEFT );
  }
}
 
Example #9
Source Project: itext2   Author: albfernandez   File: BarcodeInter25.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/** 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);
    }
}
 
Example #10
Source Project: javamelody   Author: javamelody   File: PdfProcessInformationsReport.java    License: Apache License 2.0 6 votes vote down vote up
private void writeProcessInformations(ProcessInformations processInformations) {
	final PdfPCell defaultCell = getDefaultCell();
	defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
	addCell(processInformations.getUser());
	defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	addCell(integerFormat.format(processInformations.getPid()));
	if (!windows) {
		addCell(percentFormat.format(processInformations.getCpuPercentage()));
		addCell(percentFormat.format(processInformations.getMemPercentage()));
	}
	addCell(integerFormat.format(processInformations.getVsz()));
	if (!windows) {
		addCell(integerFormat.format(processInformations.getRss()));
		defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
		addCell(processInformations.getTty());
		addCell(processInformations.getStat());
		defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
		addCell(processInformations.getStart());
	}
	addCell(processInformations.getCpuTime());
	defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
	addCell(processInformations.getCommand());
}
 
Example #11
Source Project: itext2   Author: albfernandez   File: DuplicateRowOnPageSplitTest.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
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);        
}
 
Example #12
Source Project: itext2   Author: albfernandez   File: BarcodeCodabar.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/** 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);
    }
}
 
Example #13
Source Project: itext2   Author: albfernandez   File: HtmlEncoder.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
* 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 "";
       }
   }
 
Example #14
Source Project: itext2   Author: albfernandez   File: PageNumbersWatermarkTest.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
    * 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();
       
   }
 
Example #15
Source Project: javamelody   Author: javamelody   File: PdfCacheInformationsReport.java    License: Apache License 2.0 6 votes vote down vote up
@Override
void toPdf() throws DocumentException {
	writeHeader();

	for (final CacheInformations cacheInformations : cacheInformationsList) {
		nextRow();
		writeCacheInformations(cacheInformations);
	}
	addTableToDocument();
	if (!hitsRatioEnabled) {
		final Paragraph statisticsEnabledParagraph = new Paragraph(
				getString("caches_statistics_enable"), cellFont);
		statisticsEnabledParagraph.setAlignment(Element.ALIGN_RIGHT);
		addToDocument(statisticsEnabledParagraph);
	}
	addConfigurationReference();
}
 
Example #16
Source Project: javamelody   Author: javamelody   File: PdfJndiReport.java    License: Apache License 2.0 6 votes vote down vote up
private void writeJndiBinding(JndiBinding jndiBinding) throws BadElementException, IOException {
	final PdfPCell defaultCell = getDefaultCell();
	defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
	final String name = jndiBinding.getName();
	final String className = jndiBinding.getClassName();
	final String contextPath = jndiBinding.getContextPath();
	final String value = jndiBinding.getValue();
	if (contextPath != null) {
		final Image image = getFolderImage();
		final Phrase phrase = new Phrase("", cellFont);
		phrase.add(new Chunk(image, 0, 0));
		phrase.add(new Chunk(" " + name));
		addCell(phrase);
	} else {
		addCell(name);
	}
	addCell(className != null ? className : "");
	addCell(value != null ? value : "");
}
 
Example #17
Source Project: unitime   Author: UniTime   File: PdfInstructionalOfferingTableBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private PdfPCell pdfBuildRoomLimit(PreferenceGroup prefGroup, boolean isEditable, boolean classLimitDisplayed){
	Color color = (isEditable?sEnableColor:sDisableColor);
	PdfPCell cell = createCell();

	if (prefGroup instanceof Class_){
		Class_ aClass = (Class_) prefGroup;
		if (aClass.getNbrRooms()!=null && aClass.getNbrRooms().intValue()!=1) {
			if (aClass.getNbrRooms().intValue()==0)
				addText(cell, "N/A", false, true, Element.ALIGN_RIGHT, color, true);
			else {
				String text = aClass.getNbrRooms().toString();
				text += " at ";
				if (aClass.getRoomRatio() != null)
					text += sRoomRatioFormat.format(aClass.getRoomRatio().floatValue());
				else
					text += "0";
				addText(cell, text, false, false, Element.ALIGN_RIGHT, color, true);
			}
		} else {
			if (aClass.getRoomRatio() != null){
				if (classLimitDisplayed && aClass.getRoomRatio().equals(new Float(1.0))){
					addText(cell, "", false, false, Element.ALIGN_RIGHT, color, true);
				} else {
					addText(cell, sRoomRatioFormat.format(aClass.getRoomRatio().floatValue()), false, false, Element.ALIGN_RIGHT, color, true);
				}
			} else {
				if (aClass.getExpectedCapacity() == null){
					addText(cell, "", false, false, Element.ALIGN_RIGHT, color, true);
				} else {
					addText(cell, "0", false, false, Element.ALIGN_RIGHT, color, true);
				}
			}
		}
	}
	
    return cell;
}
 
Example #18
Source Project: gcs   Author: richardwilkes   File: BarcodeDatamatrix.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Gets an <CODE>Image</CODE> with the barcode. A successful call to the method
 * <CODE>generate()</CODE> before calling this method is required.
 * 
 * @return the barcode <CODE>Image</CODE>
 * @throws BadElementException on error
 */
public Image createImage() throws BadElementException {
	if (image == null) {
		return null;
	}
	byte g4[] = CCITTG4Encoder.compress(image, width + 2 * ws, height + 2 * ws);
	return Image.getInstance(width + 2 * ws, height + 2 * ws, false, Element.CCITTG4, 0, g4, null);
}
 
Example #19
Source Project: gcs   Author: richardwilkes   File: PdfDocument.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Ensures that a new line has been started.
 */
protected void ensureNewLine() {
	try {
		if (lastElementType == Element.PHRASE || lastElementType == Element.CHUNK) {
			newLine();
			flushLines();
		}
	} catch (DocumentException ex) {
		throw new ExceptionConverter(ex);
	}
}
 
Example #20
Source Project: gcs   Author: richardwilkes   File: PdfCell.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Processes all actions contained in the cell.
 * 
 * @param element an element in the cell
 * @param action an action that should be coupled to the cell
 * @param allActions
 */

protected void processActions(Element element, PdfAction action, ArrayList allActions) {
	if (element.type() == Element.ANCHOR) {
		String url = ((Anchor) element).getReference();
		if (url != null) {
			action = new PdfAction(url);
		}
	}
	Iterator i;
	switch (element.type()) {
		case Element.PHRASE:
		case Element.SECTION:
		case Element.ANCHOR:
		case Element.CHAPTER:
		case Element.LISTITEM:
		case Element.PARAGRAPH:
			for (i = ((ArrayList) element).iterator(); i.hasNext();) {
				processActions((Element) i.next(), action, allActions);
			}
			break;
		case Element.CHUNK:
			allActions.add(action);
			break;
		case Element.LIST:
			for (i = ((List) element).getItems().iterator(); i.hasNext();) {
				processActions((Element) i.next(), action, allActions);
			}
			break;
		default:
			int n = element.getChunks().size();
			while (n-- > 0) {
				allActions.add(action);
			}
			break;
	}
}
 
Example #21
private void insertTable_OrgAndPeriod( PdfPTable mainTable, PdfWriter writer, List<Period> periods )
    throws IOException, DocumentException
{
    boolean hasBorder = false;
    float width = 220.0f;

    // Input TextBox size
    Rectangle rectangle = new Rectangle( width, PdfDataEntryFormUtil.CONTENT_HEIGHT_DEFAULT );

    // Add Organization ID/Period textfield
    // Create A table to add for each group AT HERE
    PdfPTable table = new PdfPTable( 2 ); // Code 1
    table.setWidths( new int[]{ 1, 3 } );
    table.setHorizontalAlignment( Element.ALIGN_LEFT );


    addCell_Text( table, PdfDataEntryFormUtil.getPdfPCell( hasBorder ), "Organization unit identifier", Element.ALIGN_RIGHT );
    addCell_WithTextField( table, rectangle, writer, PdfDataEntryFormUtil.getPdfPCell( hasBorder ), PdfDataEntryFormUtil.LABELCODE_ORGID,
        PdfFieldCell.TYPE_TEXT_ORGUNIT );

    String[] periodsTitle = getPeriodTitles( periods, format );
    String[] periodsValue = getPeriodValues( periods );

    addCell_Text( table, PdfDataEntryFormUtil.getPdfPCell( hasBorder ), "Period", Element.ALIGN_RIGHT );
    addCell_WithDropDownListField( table, rectangle, writer, PdfDataEntryFormUtil.getPdfPCell( hasBorder ), PdfDataEntryFormUtil.LABELCODE_PERIODID, periodsTitle, periodsValue );

    // Add to the main table
    PdfPCell cell_withInnerTable = new PdfPCell( table );
    // cell_withInnerTable.setPadding(0);
    cell_withInnerTable.setBorder( Rectangle.NO_BORDER );

    cell_withInnerTable.setHorizontalAlignment( Element.ALIGN_LEFT );

    mainTable.addCell( cell_withInnerTable );
}
 
Example #22
Source Project: unitime   Author: UniTime   File: PdfInstructionalOfferingTableBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private PdfPCell pdfBuildPreferenceCell(ClassAssignmentProxy classAssignment, PreferenceGroup prefGroup, Class[] prefTypes, boolean isEditable){
  	if (!isEditable) return createCell();
  	Color color = (isEditable?sEnableColor:sDisableColor);

  	PdfPCell cell = createCell();
  	boolean noRoomPrefs = false;
  	if (prefGroup instanceof Class_ && ((Class_)prefGroup).getNbrRooms().intValue()==0) {
  		 noRoomPrefs = true;
  	}
      if (prefGroup instanceof SchedulingSubpart && ((SchedulingSubpart)prefGroup).getInstrOfferingConfig().isUnlimitedEnrollment().booleanValue())
          noRoomPrefs = true;
  	for (int i=0;i<prefTypes.length;i++) {
  		Class prefType = prefTypes[i];
  		if (noRoomPrefs) {
  			if (//prefType.equals(RoomPref.class) || 
  				prefType.equals(RoomGroupPref.class) || 
  				prefType.equals(RoomFeaturePref.class) || 
  				prefType.equals(BuildingPref.class))
  				continue;
  		}
  		for (Iterator j=prefGroup.effectivePreferences(prefType).iterator();j.hasNext();) {
  			Preference pref = (Preference)j.next();
  			addText(cell, pref.getPrefLevel().getAbbreviation()+" "+pref.preferenceText(), false, false, Element.ALIGN_LEFT, (!isEditable ? color : pref.getPrefLevel().awtPrefcolor()), true);
  		}
  	}
  	if (noRoomPrefs && cell.getPhrase()==null)
  		addText(cell, "N/A", false, true, Element.ALIGN_LEFT, color, true);
return cell;
  }
 
Example #23
Source Project: javamelody   Author: javamelody   File: MRtfWriter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * We create a writer that listens to the document and directs a RTF-stream to out
 *
 * @param table
 *           MBasicTable
 * @param document
 *           Document
 * @param out
 *           OutputStream
 * @return DocWriter
 */
@Override
protected DocWriter createWriter(final MBasicTable table, final Document document,
		final OutputStream out) {
	final RtfWriter2 writer = RtfWriter2.getInstance(document, out);

	// title
	final String title = buildTitle(table);
	if (title != null) {
		final HeaderFooter header = new RtfHeaderFooter(new Paragraph(title));
		header.setAlignment(Element.ALIGN_LEFT);
		header.setBorder(Rectangle.NO_BORDER);
		document.setHeader(header);
		document.addTitle(title);
	}

	// advanced page numbers : x/y
	final Paragraph footerParagraph = new Paragraph();
	final Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL);
	footerParagraph.add(new RtfPageNumber(font));
	footerParagraph.add(new Phrase(" / ", font));
	footerParagraph.add(new RtfTotalPageNumber(font));
	footerParagraph.setAlignment(Element.ALIGN_CENTER);
	final HeaderFooter footer = new RtfHeaderFooter(footerParagraph);
	footer.setBorder(Rectangle.TOP);
	document.setFooter(footer);

	return writer;
}
 
Example #24
Source Project: gcs   Author: richardwilkes   File: PdfLine.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Resets the alignment of this line.
 * <P>
 * The alignment of the last line of for instance a <CODE>Paragraph</CODE> that has to be
 * justified, has to be reset to <VAR>ALIGN_LEFT</VAR>.
 */

public void resetAlignment() {
	if (alignment == Element.ALIGN_JUSTIFIED) {
		alignment = Element.ALIGN_LEFT;
	}
}
 
Example #25
Source Project: gcs   Author: richardwilkes   File: IncCell.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/** Creates a new instance of IncCell */
public IncCell(String tag, ChainedProperties props) {
    cell = new PdfPCell((Phrase)null);
    String value = props.getProperty("colspan");
    if (value != null)
        cell.setColspan(Integer.parseInt(value));
    value = props.getProperty("align");
    if (tag.equals("th"))
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    if (value != null) {
        if ("center".equalsIgnoreCase(value))
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        else if ("right".equalsIgnoreCase(value))
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        else if ("left".equalsIgnoreCase(value))
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        else if ("justify".equalsIgnoreCase(value))
            cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
    }
    value = props.getProperty("valign");
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    if (value != null) {
        if ("top".equalsIgnoreCase(value))
            cell.setVerticalAlignment(Element.ALIGN_TOP);
        else if ("bottom".equalsIgnoreCase(value))
            cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    }
    value = props.getProperty("border");
    float border = 0;
    if (value != null)
        border = Float.parseFloat(value);
    cell.setBorderWidth(border);
    value = props.getProperty("cellpadding");
    if (value != null)
        cell.setPadding(Float.parseFloat(value));
    cell.setUseDescender(true);
    value = props.getProperty("bgcolor");
    cell.setBackgroundColor(Markup.decodeColor(value));
}
 
Example #26
Source Project: javamelody   Author: javamelody   File: PdfHotspotsReport.java    License: Apache License 2.0 5 votes vote down vote up
private void writeHotspot(SampledMethod hotspot) {
	final PdfPCell defaultCell = getDefaultCell();
	defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
	addCell(hotspot.getClassName() + '.' + hotspot.getMethodName());
	defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	final double percent = 100d * hotspot.getCount() / totalCount;
	addCell(percentFormat.format(percent));
}
 
Example #27
Source Project: unitime   Author: UniTime   File: PdfInstructionalOfferingTableBuilder.java    License: Apache License 2.0 5 votes vote down vote up
private PdfPCell pdfBuildAssignedTime(ClassAssignmentProxy classAssignment, PreferenceGroup prefGroup, boolean isEditable){
	Color color = (isEditable?sEnableColor:sDisableColor);
	PdfPCell cell = createCell();

	if (classAssignment!=null && prefGroup instanceof Class_) {
		Class_ aClass = (Class_) prefGroup;
		Assignment a = null;
		AssignmentPreferenceInfo p = null;
		try {
			a = classAssignment.getAssignment(aClass);
			p = classAssignment.getAssignmentInfo((Class_)prefGroup);
		} catch (Exception e) {
			Debug.error(e);
		}
		if (a!=null) {
			StringBuffer sb = new StringBuffer();
			Integer firstDay = ApplicationProperty.TimePatternFirstDayOfWeek.intValue();
			for (int i = 0; i < CONSTANTS.shortDays().length; i++) {
				int idx = (firstDay == null ? i : (i + firstDay) % 7);
				if ((Constants.DAY_CODES[idx] & a.getTimeLocation().getDayCode()) != 0) sb.append(CONSTANTS.shortDays()[idx]);
			}
			sb.append(" ");
			sb.append(a.getTimeLocation().getStartTimeHeader(CONSTANTS.useAmPm()));
			sb.append("-");
			sb.append(a.getTimeLocation().getEndTimeHeader(CONSTANTS.useAmPm()));
			addText(cell, sb.toString(), false, false, Element.ALIGN_LEFT, (p == null || !isEditable ? color : PreferenceLevel.int2awtColor(p.getTimePreference(), color)), true);
		} 
	}
	
    return cell;
}
 
Example #28
Source Project: itext2   Author: albfernandez   File: PageNumbersWatermarkTest.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @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();
    }
}
 
Example #29
private PdfPTable getProgramStageMainTable()
{
    PdfPTable mainTable = new PdfPTable( 1 ); // Code 1

    mainTable.setTotalWidth( 800f );
    mainTable.setLockedWidth( true );
    mainTable.setHorizontalAlignment( Element.ALIGN_LEFT );

    return mainTable;
}
 
Example #30
Source Project: sakai   Author: sakaiproject   File: HTMLWorker.java    License: Educational Community License v2.0 5 votes vote down vote up
public void endDocument() {
	try {
		for (int k = 0; k < stack.size(); ++k)
			document.add((Element)stack.elementAt(k));
		if (currentParagraph != null)
			document.add(currentParagraph);
		currentParagraph = null;
	}
	catch (Exception e) {
		throw new ExceptionConverter(e);
	}
}