List of usage examples for com.itextpdf.text Paragraph add
@Override public void add(final int index, final Element element)
Chunk
, an Anchor
or another Phrase
to this Phrase
. From source file:com.github.wolfposd.imsqti2pdf.PDFCreator.java
License:Open Source License
private void addQuestionText(Paragraph paragraph, Question question, int questionnumber) throws IOException { String fixedFonts = question.questiontext.replace("font-size: 12pt", "font-size: 10pt"); fixedFonts = fixedFonts.replace("face=\"courier new\"", "face=\"Courier\""); fixedFonts = fixedFonts.replace("src=\"media/", getPathToMedia()); ArrayList<Element> htmllist = (ArrayList<Element>) HTMLWorker.parseToList(new StringReader(fixedFonts), null);/*from ww w .j a v a 2s. c o m*/ ArrayList<Paragraph> codeParagraphs = new ArrayList<Paragraph>(); for (int i = 0; i < htmllist.size(); i++) { Element e = htmllist.get(i); if (e instanceof Paragraph) { Paragraph p = (Paragraph) e; if (i == 0) { p.setIndentationLeft(INDENTATION); p.getFont().setSize(OVERALLFONTSIZE); p.add(0, getQuestionNumberChunk(p.getFont(), questionnumber)); p.add(getPointsChunk(p.getFont(), question)); paragraph.add(p); } else { codeParagraphs.add(p); } } } if (codeParagraphs.size() > 0) { PdfPTable table = new PdfPTable(1); table.setWidthPercentage(90); table.setKeepTogether(true); Paragraph codeParagraph = new Paragraph(); for (Paragraph p : codeParagraphs) { p.setIndentationLeft(INDENTATION); p.getFont().setSize(OVERALLFONTSIZE); codeParagraph.add(p); fixFonts(p); } codeParagraph.add(Chunk.NEWLINE); PdfPCell cell = new PdfPCell(); cell.addElement(codeParagraph); cell.setBorderColor(BaseColor.BLACK); table.addCell(cell); paragraph.add(Chunk.NEWLINE); paragraph.add(table); } }