List of usage examples for com.lowagie.text Chunk Chunk
public Chunk(DrawInterface separator)
From source file:fr.opensagres.xdocreport.itext.extension.TableWithVerticalAlignment.java
License:Open Source License
public static void main(String[] args) { Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10); try {//from w ww .j a v a 2 s .com PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("TableWithVerticalAlignment.pdf")); document.open(); PdfPTable table = new PdfPTable(1); // PdfPCell cell1 = new PdfPCell(); // cell1.setVerticalAlignment( Element.ALIGN_BOTTOM ); // //cell1.setMinimumHeight( 100f ); // cell1.addElement( new Chunk( "cell1" ) ); // table.addCell( cell1 ); PdfPCell cell2 = new PdfPCell(); Paragraph p = new Paragraph(); p.add(new Chunk("cellp&")); cell2.addElement(p); cell2.setVerticalAlignment(Element.ALIGN_BOTTOM); cell2.setMinimumHeight(38f); table.addCell(cell2); document.add(table); } catch (Exception de) { de.printStackTrace(); } document.close(); }
From source file:fr.paris.lutece.plugins.directory.modules.pdfproducer.utils.PDFUtils.java
License:Open Source License
/** * Build the fields in a single paragraph. * @param listRecordFields the list of record fields * @param entry the entry/* w ww. j a v a2 s.co m*/ * @param locale the locale * @param phraseEntry the phrase entry * @param paragraphEntry the paragraph entry * @param bExtractNotFilledField if true, extract empty fields, false * @throws DocumentException exception if there is an error */ private static void builFieldsInSinglePhrase(List<RecordField> listRecordFields, IEntry entry, Locale locale, Phrase phraseEntry, Paragraph paragraphEntry, Boolean bExtractNotFilledField) throws DocumentException { RecordField recordField = listRecordFields.get(0); Chunk chunkEntryValue = null; Font fontEntryValue = new Font( DirectoryUtils.convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_NAME)), DirectoryUtils .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_SIZE_ENTRY_VALUE)), DirectoryUtils .convertStringToInt(AppPropertiesService.getProperty(PROPERTY_POLICE_STYLE_ENTRY_VALUE))); if (entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeDownloadUrl) { if (StringUtils.isNotBlank(recordField.getFileName())) { chunkEntryValue = new Chunk(recordField.getFileName()); } else { chunkEntryValue = new Chunk(StringUtils.EMPTY); } } else if (entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeGeolocation) { for (RecordField recordFieldGeo : listRecordFields) { if ((recordFieldGeo.getField() != null) && EntryTypeGeolocation.CONSTANT_ADDRESS.equals(recordFieldGeo.getField().getTitle())) { chunkEntryValue = new Chunk( entry.convertRecordFieldValueToString(recordFieldGeo, locale, false, false), fontEntryValue); } } } else if (entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeCheckBox || entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeSelect || entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeRadioButton) { chunkEntryValue = new Chunk(entry.convertRecordFieldTitleToString(recordField, locale, false), fontEntryValue); } else if (entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeFile || entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeImg) { String strFileName = StringUtils.EMPTY; if ((recordField.getFile() != null) && StringUtils.isNotBlank(recordField.getFile().getTitle())) { // The thumbnails and big thumbnails should not be displayed if (!((StringUtils.isNotBlank(recordField.getValue()) && recordField.getValue().startsWith(FIELD_THUMBNAIL)) || (StringUtils.isNotBlank(recordField.getValue()) && recordField.getValue().startsWith(FIELD_BIG_THUMBNAIL)))) { strFileName = recordField.getFile().getTitle(); } } chunkEntryValue = new Chunk(strFileName, fontEntryValue); } else if (entry instanceof fr.paris.lutece.plugins.directory.business.EntryTypeRichText) { String strValue = entry.convertRecordFieldValueToString(recordField, locale, false, false); strValue = StringUtils.defaultString(HtmlUtils.htmlUnescape(strValue)).replaceAll("<[^>]*>", ""); chunkEntryValue = new Chunk(strValue, fontEntryValue); } else { chunkEntryValue = new Chunk(entry.convertRecordFieldValueToString(recordField, locale, false, false), fontEntryValue); } if (chunkEntryValue != null) { if (bExtractNotFilledField || (!bExtractNotFilledField && StringUtils.isNotBlank(chunkEntryValue.getContent()))) { phraseEntry.add(chunkEntryValue); paragraphEntry.add(phraseEntry); } } }
From source file:jmemorize.core.io.PdfRtfBuilder.java
License:Open Source License
private static void writeCategoryHeader(Document doc, Category category) throws DocumentException { Chunk chunk = new Chunk(category.getPath()); chunk.setFont(new Font(Font.HELVETICA, 12, Font.BOLD)); Paragraph paragraph = new Paragraph(chunk); paragraph.setSpacingBefore(1f);/*from ww w . j ava 2s . c om*/ doc.add(paragraph); }
From source file:net.sf.jasperreports.engine.export.JRPdfExporter.java
License:LGPL
protected void writePageAnchor(int pageIndex) throws DocumentException { Map pdfFontAttrs = getDefaultPdfFontAttributes(); Chunk chunk;/*from w ww.jav a2 s. com*/ if (pdfFontAttrs == null) { chunk = new Chunk(" "); } else { Font pdfFont = getFont(pdfFontAttrs); chunk = new Chunk(" ", pdfFont); } chunk.setLocalDestination(JR_PAGE_ANCHOR_PREFIX + reportIndex + "_" + (pageIndex + 1)); ColumnText colText = new ColumnText(pdfContentByte); colText.setSimpleColumn(new Phrase(chunk), 0, jasperPrint.getPageHeight(), 1, 1, 0, Element.ALIGN_LEFT); colText.go(); }
From source file:nl.dykema.jxmlnote.report.pdf.PdfCell.java
License:Open Source License
public PdfCell(PdfReport rep, ReportElement p) { if (p instanceof PdfParagraph) { PdfParagraph pp = ((PdfParagraph) p); super.addElement(pp); super.setVerticalAlignment(ALIGN_MIDDLE); } else if (p instanceof PdfTable) { PdfTable tbl = ((PdfTable) p);/*from ww w .jav a 2 s. c o m*/ super.addElement(tbl); super.setVerticalAlignment(ALIGN_MIDDLE); } else { super.addElement( new com.lowagie.text.Paragraph(new Chunk("Mixing implementations:" + p.getClass().getName()))); } }
From source file:nl.dykema.jxmlnote.report.pdf.PdfTable.java
License:Open Source License
public Table add(Cell cel) { if (cel instanceof PdfCell) { super.addCell((PdfCell) cel); } else {/* w w w .j a v a 2s. c o m*/ PdfPCell c = new PdfPCell(); c.addElement(new Paragraph(new Chunk("Cannot mix different implementations"))); super.addCell(c); } return this; }
From source file:org.apache.ofbiz.content.survey.PdfSurveyServices.java
License:Apache License
/** *//* ww w. ja va 2 s. co m*/ public static Map<String, Object> buildPdfFromSurveyResponse(DispatchContext dctx, Map<String, ? extends Object> rcontext) { Map<String, Object> context = UtilMisc.makeMapWritable(rcontext); Delegator delegator = dctx.getDelegator(); Map<String, Object> results = ServiceUtil.returnSuccess(); String surveyResponseId = (String) context.get("surveyResponseId"); String contentId = (String) context.get("contentId"); String surveyId = null; Document document = new Document(); try { if (UtilValidate.isNotEmpty(surveyResponseId)) { GenericValue surveyResponse = EntityQuery.use(delegator).from("SurveyResponse") .where("surveyResponseId", surveyResponseId).queryOne(); if (surveyResponse != null) { surveyId = surveyResponse.getString("surveyId"); } } if (UtilValidate.isNotEmpty(surveyId) && UtilValidate.isEmpty(contentId)) { GenericValue survey = EntityQuery.use(delegator).from("Survey").where("surveyId", surveyId) .queryOne(); if (survey != null) { String acroFormContentId = survey.getString("acroFormContentId"); if (UtilValidate.isNotEmpty(acroFormContentId)) { context.put("contentId", acroFormContentId); } } } ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); List<GenericValue> responses = EntityQuery.use(delegator).from("SurveyResponseAnswer") .where("surveyResponseId", surveyResponseId).queryList(); for (GenericValue surveyResponseAnswer : responses) { String value = null; String surveyQuestionId = (String) surveyResponseAnswer.get("surveyQuestionId"); GenericValue surveyQuestion = EntityQuery.use(delegator).from("SurveyQuestion") .where("surveyQuestionId", surveyQuestionId).queryOne(); String questionType = surveyQuestion.getString("surveyQuestionTypeId"); // DEJ20060227 this isn't used, if needed in the future should get from SurveyQuestionAppl.externalFieldRef String fieldName = surveyQuestion.getString("description"); if ("OPTION".equals(questionType)) { value = surveyResponseAnswer.getString("surveyOptionSeqId"); } else if ("BOOLEAN".equals(questionType)) { value = surveyResponseAnswer.getString("booleanResponse"); } else if ("NUMBER_LONG".equals(questionType) || "NUMBER_CURRENCY".equals(questionType) || "NUMBER_FLOAT".equals(questionType)) { Double num = surveyResponseAnswer.getDouble("numericResponse"); if (num != null) { value = num.toString(); } } else if ("SEPERATOR_LINE".equals(questionType) || "SEPERATOR_TEXT".equals(questionType)) { // not really a question; ingore completely } else { value = surveyResponseAnswer.getString("textResponse"); } Chunk chunk = new Chunk(surveyQuestion.getString("question") + ": " + value); Paragraph p = new Paragraph(chunk); document.add(p); } ByteBuffer outByteBuffer = ByteBuffer.wrap(baos.toByteArray()); results.put("outByteBuffer", outByteBuffer); } catch (GenericEntityException e) { System.err.println(e.getMessage()); results = ServiceUtil.returnError(e.getMessage()); } catch (DocumentException e) { System.err.println(e.getMessage()); results = ServiceUtil.returnError(e.getMessage()); } return results; }
From source file:org.areasy.common.doclet.document.elements.LinkPhrase.java
License:Open Source License
/** * Initializes the link chunk with given values. * * @param destination The original destination as defined * in the javadoc./*from ww w.j a va 2s . com*/ * @param label The text label for the link * @param font The base font for the link (for example, could be * a bold italic font in case of a "deprecated" tag). */ private void init(String destination, String label, Font font) { if (label == null) label = destination; String createLinksProp = DefaultConfiguration.getString(ARG_CREATE_LINKS, ARG_VAL_NO); if (createLinksProp.equalsIgnoreCase(ARG_VAL_NO)) destination = null; super.font = font; Chunk chunk = new Chunk(""); chunk.append(label); if (destination != null && Destinations.isValid(destination)) chunk.setLocalGoto(destination); add(chunk); }
From source file:org.areasy.common.doclet.document.Inherited.java
License:Open Source License
/** * Prints inherited methods and fields from superclasses * * @param supercls class source to get inherited fields and methods for. * @param show SHOW_METHODS or SHOW_FIELDS * @throws Exception/* www. j a va2s . co m*/ */ public static void print(ClassDoc supercls, int show) throws Exception { String type; FieldDoc[] fields = supercls.fields(); Arrays.sort(fields); if (supercls.isInterface()) type = "interface"; else type = "class"; // Create cell for additional spacing below PdfPCell spacingCell = new PdfPCell(); spacingCell.addElement(new Chunk(" ")); spacingCell.setFixedHeight((float) 4.0); spacingCell.setBorder(Rectangle.BOTTOM + Rectangle.LEFT + Rectangle.RIGHT); spacingCell.setBorderColor(Color.gray); if ((fields.length > 0) && (show == SHOW_FIELDS)) { Document.instance().add(new Paragraph((float) 6.0, " ")); PdfPTable table = new PdfPTable(1); table.setWidthPercentage((float) 100); Paragraph newLine = new Paragraph(); newLine.add(new Chunk("Fields inherited from " + type + " ", Fonts.getFont(TEXT_FONT, BOLD, 10))); newLine.add(new LinkPhrase(supercls.qualifiedTypeName(), null, 10, false)); table.addCell(new CustomPdfPCell(newLine, COLOR_INHERITED_SUMMARY)); Paragraph paraList = new Paragraph(); for (int i = 0; i < fields.length; i++) { paraList.add(new LinkPhrase(fields[i].qualifiedName(), fields[i].name(), 10, false)); if (i != (fields.length - 1)) paraList.add(new Chunk(", ", Fonts.getFont(TEXT_FONT, BOLD, 12))); } PdfPCell contentCell = new CellBorderPadding(paraList); float leading = (float) contentCell.getLeading() + (float) 1.1; contentCell.setLeading(leading, leading); table.addCell(contentCell); table.addCell(spacingCell); Document.instance().add(table); } MethodDoc[] meth = supercls.methods(); Arrays.sort(meth); if ((meth.length > 0) && (show == SHOW_METHODS)) { Document.instance().add(new Paragraph((float) 6.0, " ")); PdfPTable table = new CustomPdfPTable(); Paragraph newLine = new Paragraph(); newLine.add(new Chunk("Methods inherited from " + type + " ", Fonts.getFont(TEXT_FONT, BOLD, 10))); newLine.add(new LinkPhrase(supercls.qualifiedTypeName(), null, 10, false)); table.addCell(new CustomPdfPCell(newLine, COLOR_INHERITED_SUMMARY)); Paragraph paraList = new Paragraph(); for (int i = 0; i < meth.length; i++) { String methodLabel = meth[i].name(); // Do not list static initializers like "<clinit>" if (!methodLabel.startsWith("<")) { paraList.add(new LinkPhrase(supercls.qualifiedTypeName() + "." + meth[i].name(), meth[i].name(), 10, false)); if (i != (meth.length - 1)) paraList.add(new Chunk(", ", Fonts.getFont(CODE_FONT, 10))); } } PdfPCell contentCell = new CellBorderPadding(paraList); float leading = (float) contentCell.getLeading() + (float) 1.1; contentCell.setLeading(leading, leading); table.addCell(contentCell); table.addCell(spacingCell); Document.instance().add(table); } // Print inherited interfaces / class methods and fields recursively ClassDoc supersupercls = null; if (supercls.isClass()) supersupercls = supercls.superclass(); if (supersupercls != null) { String className = supersupercls.qualifiedName(); if (ifClassMustBePrinted(className)) Inherited.print(supersupercls, show); } ClassDoc[] interfaces = supercls.interfaces(); for (int i = 0; i < interfaces.length; i++) { supersupercls = interfaces[i]; String className = supersupercls.qualifiedName(); if (ifClassMustBePrinted(className)) Inherited.print(supersupercls, show); } }
From source file:org.areasy.common.doclet.document.tags.TagA.java
License:Open Source License
public Element[] openTagElements() { String addr = getAttribute("href"); String name = getAttribute("name"); if (addr != null && addr.equalsIgnoreCase("newpage")) { Chunk anchor = new Chunk(""); anchor.setNewPage();//from w w w . j ava 2 s. c om return new Element[] { anchor }; } else if (name != null && name.equalsIgnoreCase("bookmark")) { String label = getAttribute("label"); String destinationName = null; if (HtmlParserWrapper.getRootBookmarkEntry() != null) { String target = getAttribute("target"); destinationName = HtmlParserWrapper.getRootBookmarkEntry().addBookmarkEntry(target, label); } else { destinationName = Destinations.createAnchorDestination(State.getCurrentFile(), label); Bookmarks.addRootBookmark(label, destinationName); } Chunk anchor = PDFUtility.createAnchor(destinationName); return new Element[] { anchor }; } else if (name != null && name.length() > 0) { String dest = Destinations.createAnchorDestination(State.getCurrentFile(), name); setLink(false); Phrase anchor = new Phrase(PDFUtility.createAnchor(dest, getFont())); return new Element[] { anchor }; } return null; }