Java Code Examples for com.lowagie.text.Paragraph#setIndentationLeft()

The following examples show how to use com.lowagie.text.Paragraph#setIndentationLeft() . 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 File: ElementFactory.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Creates a Paragraph object based on a list of properties.
 * 
 * @param attributes
 * @return a Paragraph
 */
public static Paragraph getParagraph(Properties attributes) {
	Paragraph paragraph = new Paragraph(getPhrase(attributes));
	String value;
	value = attributes.getProperty(ElementTags.ALIGN);
	if (value != null) {
		paragraph.setAlignment(value);
	}
	value = attributes.getProperty(ElementTags.INDENTATIONLEFT);
	if (value != null) {
		paragraph.setIndentationLeft(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(ElementTags.INDENTATIONRIGHT);
	if (value != null) {
		paragraph.setIndentationRight(Float.parseFloat(value + "f"));
	}
	return paragraph;
}
 
Example 2
Source File: ElementFactory.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates a Paragraph object based on a list of properties.
 * @param attributes
 * @return a Paragraph
 */
public static Paragraph getParagraph(Properties attributes) {
	Paragraph paragraph = new Paragraph(getPhrase(attributes));
	String value;
	value = attributes.getProperty(ElementTags.ALIGN);
	if (value != null) {
		paragraph.setAlignment(value);
	}
	value = attributes.getProperty(ElementTags.INDENTATIONLEFT);
	if (value != null) {
		paragraph.setIndentationLeft(Float.parseFloat(value + "f"));
	}
	value = attributes.getProperty(ElementTags.INDENTATIONRIGHT);
	if (value != null) {
		paragraph.setIndentationRight(Float.parseFloat(value + "f"));
	}
	return paragraph;
}
 
Example 3
Source File: PdfMBeansReport.java    From javamelody with Apache License 2.0 6 votes vote down vote up
private void writeAttributes(MBeanNode mbean) throws DocumentException {
	final String description = mbean.getDescription();
	final List<MBeanAttribute> attributes = mbean.getAttributes();
	if (description != null || !attributes.isEmpty()) {
		currentTable = createAttributesTable();
		if (description != null) {
			currentTable.getDefaultCell().setColspan(3);
			addCell('(' + description + ')');
			currentTable.getDefaultCell().setColspan(1);
		}
		for (final MBeanAttribute attribute : attributes) {
			writeAttribute(attribute);
		}
		final Paragraph paragraph = new Paragraph();
		paragraph.setIndentationLeft(margin);
		paragraph.add(currentTable);
		addToDocument(paragraph);
		addText("\n");
	}
}
 
Example 4
Source File: PdfRequestAndGraphDetailReport.java    From javamelody with Apache License 2.0 5 votes vote down vote up
@Override
void toPdf() throws DocumentException, IOException {
	if (request != null) {
		if (request.getRumData() != null && request.getRumData().getHits() != 0) {
			writeRequestRumData();
		}

		writeHeader();

		writeRequests();

		addTableToDocument();

		if (JdbcWrapper.SINGLETON.getSqlCounter().isRequestIdFromThisCounter(request.getId())
				&& !request.getName().toLowerCase(Locale.ENGLISH).startsWith("alter ")) {
			// inutile d'essayer d'avoir le plan d'exécution des requêtes sql
			// telles que "alter session set ..." (cf issue 152)
			writeSqlRequestExplainPlan();
		}
	}

	if (isGraphDisplayed()) {
		writeGraph();
	}

	if (request != null && request.getStackTrace() != null) {
		final Paragraph paragraph = new Paragraph("\n", cellFont);
		paragraph.setIndentationLeft(20);
		paragraph.setIndentationRight(20);
		paragraph.add(new Phrase("Stack-trace\n", boldFont));
		paragraph.add(new Phrase(request.getStackTrace().replace("\t", "        "), cellFont));
		addToDocument(paragraph);
	}
}
 
Example 5
Source File: PdfRequestAndGraphDetailReport.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private void writeRequest(CounterRequest childRequest, float executionsByRequest,
		boolean allChildHitsDisplayed) throws IOException, DocumentException {
	final PdfPCell defaultCell = getDefaultCell();
	defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
	final Paragraph paragraph = new Paragraph(defaultCell.getLeading() + cellFont.getSize());
	if (executionsByRequest != -1) {
		paragraph.setIndentationLeft(5);
	}
	final Counter parentCounter = getCounterByRequestId(childRequest);
	if (parentCounter != null && parentCounter.getIconName() != null) {
		paragraph.add(new Chunk(getSmallImage(parentCounter.getIconName()), 0, -1));
	}
	paragraph.add(new Phrase(childRequest.getName(), cellFont));
	final PdfPCell requestCell = new PdfPCell();
	requestCell.addElement(paragraph);
	requestCell.setGrayFill(defaultCell.getGrayFill());
	requestCell.setPaddingTop(defaultCell.getPaddingTop());
	addCell(requestCell);

	defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	if (executionsByRequest != -1) {
		addCell(nbExecutionsFormat.format(executionsByRequest));
	} else {
		final boolean hasChildren = !request.getChildRequestsExecutionsByRequestId().isEmpty();
		if (hasChildren) {
			addCell("");
		}
	}
	writeRequestValues(childRequest, allChildHitsDisplayed);
}
 
Example 6
Source File: PdfCounterRequestContextReport.java    From javamelody with Apache License 2.0 5 votes vote down vote up
private void writeRequest(CounterRequestContext context, PdfPCell cell, int margin)
		throws DocumentException, IOException {
	final Paragraph paragraph = new Paragraph(
			getDefaultCell().getLeading() + cellFont.getSize());
	paragraph.setIndentationLeft(margin);
	if (context.getParentCounter().getIconName() != null) {
		paragraph.add(new Chunk(getImage(context.getParentCounter().getIconName()), 0, -1));
	}
	paragraph.add(new Phrase(context.getCompleteRequestName(), cellFont));
	cell.addElement(paragraph);
}
 
Example 7
Source File: StatisticsPdf.java    From JDeSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
private void writeEntry(Document document,String label , String value) throws Exception{
	Paragraph questionParagraph = new Paragraph();
	questionParagraph.setLeading(14, 0);
	questionParagraph.setIndentationLeft(18);
	questionParagraph.add(new Chunk(label.trim() + ": ",boldedFont)); 
    questionParagraph.add(new Chunk(value == null ? "": value.trim() ,normalFont));  
	document.add(questionParagraph);
}
 
Example 8
Source File: StatisticsPdf.java    From JDeSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
private void writeEntry(Document document,String label) throws Exception{
	Paragraph questionParagraph = new Paragraph();
	questionParagraph.setLeading(14, 0);
	questionParagraph.setIndentationLeft(18);
	questionParagraph.add(new Chunk(label.trim()  ,boldedFont)); 
    document.add(questionParagraph);
}
 
Example 9
Source File: StatisticsPdf.java    From JDeSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
private void writeEntry(Document document,String label , double value) throws Exception{
	Paragraph questionParagraph = new Paragraph();
	questionParagraph.setLeading(14, 0);
	questionParagraph.setIndentationLeft(18);
	questionParagraph.add(new Chunk(label.trim() + ": ",boldedFont)); 
    questionParagraph.add(new Chunk(BigDecimalValidator.getInstance().format(value , LocaleContextHolder.getLocale()) , normalFont));  
	document.add(questionParagraph);
}
 
Example 10
Source File: StatisticsPdf.java    From JDeSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
private void writeEntry(Document document,String label , Date value, String dateFormat) throws Exception{
	Paragraph questionParagraph = new Paragraph();
	questionParagraph.setLeading(14, 0);
	questionParagraph.setIndentationLeft(18);
	questionParagraph.add(new Chunk(label.trim() + ": ",boldedFont)); 
    questionParagraph.add(new Chunk(DateValidator.getInstance().format(value ,dateFormat) , normalFont));  
	document.add(questionParagraph);
}
 
Example 11
Source File: StatisticsPdf.java    From JDeSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
private void writeCurrencyEntry(Document document,String label , double value) throws Exception{
	Paragraph questionParagraph = new Paragraph();
	questionParagraph.setLeading(14, 0);
	questionParagraph.setIndentationLeft(18);
	questionParagraph.add(new Chunk(label.trim() + ": ",boldedFont)); 
    questionParagraph.add(new Chunk(CurrencyValidator.getInstance().format(value , LocaleContextHolder.getLocale()) , normalFont));  
	document.add(questionParagraph);
}
 
Example 12
Source File: PdfMBeansReport.java    From javamelody with Apache License 2.0 4 votes vote down vote up
private void addText(String text) throws DocumentException {
	final Paragraph paragraph = new Paragraph(text, normalFont);
	paragraph.setIndentationLeft(margin);
	addToDocument(paragraph);
}
 
Example 13
Source File: ContractsGrantsInvoiceReportServiceImpl.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Generates the pdf file for printing the envelopes.
 *
 * @param list
 * @param outputStream
 * @throws DocumentException
 * @throws IOException
 */
protected void generateCombinedPdfForEnvelopes(Collection<ContractsGrantsInvoiceDocument> list, OutputStream outputStream) throws DocumentException, IOException {
    Document document = new Document(new Rectangle(ArConstants.InvoiceEnvelopePdf.LENGTH, ArConstants.InvoiceEnvelopePdf.WIDTH));
    PdfWriter.getInstance(document, outputStream);
    boolean pageAdded = false;

    for (ContractsGrantsInvoiceDocument invoice : list) {
        // add a document
        for (InvoiceAddressDetail invoiceAddressDetail : invoice.getInvoiceAddressDetails()) {
            if (ArConstants.InvoiceTransmissionMethod.MAIL.equals(invoiceAddressDetail.getInvoiceTransmissionMethodCode())) {
                CustomerAddress address = invoiceAddressDetail.getCustomerAddress();

                Integer numberOfEnvelopesToPrint = address.getCustomerEnvelopesToPrintQuantity();
                if (ObjectUtils.isNull(numberOfEnvelopesToPrint)) {
                    numberOfEnvelopesToPrint = 1;
                }
                for (int i = 0; i < numberOfEnvelopesToPrint; i++) {
                    // if a page has not already been added then open the document.
                    if (!pageAdded) {
                        document.open();
                    }
                    pageAdded = true;
                    document.newPage();
                    // adding the sent From address
                    Organization org = invoice.getInvoiceGeneralDetail().getAward().getPrimaryAwardOrganization().getOrganization();
                    Paragraph sentBy = generateAddressParagraph(org.getOrganizationName(), org.getOrganizationLine1Address(), org.getOrganizationLine2Address(), org.getOrganizationCityName(), org.getOrganizationStateCode(), org.getOrganizationZipCode(), ArConstants.PdfReportFonts.ENVELOPE_SMALL_FONT);
                    sentBy.setIndentationLeft(ArConstants.InvoiceEnvelopePdf.INDENTATION_LEFT);
                    sentBy.setAlignment(Element.ALIGN_LEFT);

                    // adding the send To address
                    String string;
                    Paragraph sendTo = generateAddressParagraph(address.getCustomerAddressName(), address.getCustomerLine1StreetAddress(), address.getCustomerLine2StreetAddress(), address.getCustomerCityName(), address.getCustomerStateCode(), address.getCustomerZipCode(), ArConstants.PdfReportFonts.ENVELOPE_TITLE_FONT);
                    sendTo.setAlignment(Element.ALIGN_CENTER);
                    sendTo.add(new Paragraph(KFSConstants.BLANK_SPACE));

                    document.add(sentBy);
                    document.add(sendTo);
                }
            }
        }
    }
    if (pageAdded) {
        document.close();
    }
}
 
Example 14
Source File: MarkupParser.java    From MesquiteCore with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Retrieves a Paragraph based on some style attributes.
 * @param font
 * @param styleattributes a Properties object containing keys and values
 * @return an iText Paragraph object
 */
public Element retrieveParagraph(Font font, Properties styleattributes) {
	Paragraph p = new Paragraph((Phrase)retrievePhrase(font, styleattributes));
	if (styleattributes == null) return p;
	String margin = styleattributes.getProperty(MarkupTags.CSS_KEY_MARGIN);
	float f;
	if (margin != null) {
		f = parseLength(margin);
		p.setIndentationLeft(f);
		p.setIndentationRight(f);
		p.setSpacingBefore(f);
		p.setSpacingAfter(f);
	}
	margin = styleattributes.getProperty(MarkupTags.CSS_KEY_MARGINLEFT);
	if (margin != null) {
		f = parseLength(margin);
		p.setIndentationLeft(f);
	}
	margin = styleattributes.getProperty(MarkupTags.CSS_KEY_MARGINRIGHT);
	if (margin != null) {
		f = parseLength(margin);
		p.setIndentationRight(f);
	}
	margin = styleattributes.getProperty(MarkupTags.CSS_KEY_MARGINTOP);
	if (margin != null) {
		f = parseLength(margin);
		p.setSpacingBefore(f);
	}
	margin = styleattributes.getProperty(MarkupTags.CSS_KEY_MARGINBOTTOM);
	if (margin != null) {
		f = parseLength(margin);
		p.setSpacingAfter(f);
	}
	String align = styleattributes.getProperty(MarkupTags.CSS_KEY_TEXTALIGN);
	if (MarkupTags.CSS_VALUE_TEXTALIGNLEFT.equals(align)) {
		p.setAlignment(Element.ALIGN_LEFT);
	}
	else if (MarkupTags.CSS_VALUE_TEXTALIGNRIGHT.equals(align)) {
		p.setAlignment(Element.ALIGN_RIGHT);
	}
	else if (MarkupTags.CSS_VALUE_TEXTALIGNCENTER.equals(align)) {
		p.setAlignment(Element.ALIGN_CENTER);
	}
	else if (MarkupTags.CSS_VALUE_TEXTALIGNJUSTIFY.equals(align)) {
		p.setAlignment(Element.ALIGN_JUSTIFIED);
	}
	return p;
}