I have a table with cells set up like this:
Paragraph p = new Paragraph(content,font);
p.setLeading(30);
PdfPCell c = new PdfPCell(p);
My problem is that the paragraph leading is ignored. Can someone please tell me how to set the paragraph leading when inside a table cell? It works perfectly when not inside a cell.
Thanks.
Google for the difference between "text mode" and "composite mode".
You are using "text mode": the leading of the cell is taken into
account; the leading of the paragraph is ignored.
If you use "composite mode", it's the other way round.
Try:
PdfPCell c = new PdfPCell();
c.addElement(p);
Related
I need to insert new paragraphs in diferents positiins in docx.
My code insert new paragraph but not in determinate position
XWFParagraph.
para=docx.createParagraph();
XWPFRun run =para.createRun();
run.setText("example
paragraph");
I've been trying to add annotations to an existing PDF using the iText API and the older Lowagie version. However, I need alternatives to the API since it does not seem to be able to do what is asked in our requirement.
The requirement is to put an Annotation into an existing PDF with the following details:
Type: plain text
Postion: x=0mm && y=0mm
Font: Arial
Text Colour: White
Text Content: "some text"
Using iText, I can put in an annotation but I need to approximate in pixels where in my A4 size page I should put it. The closest approximation is using
PdfReader reader = new PdfReader(headerFilePath.concat(xmlFileName));
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(headerFilePath.concat(xmlFileNameNew)));
PdfAnnotation annotation = PdfAnnotation.createText(stamper.getWriter(), new Rectangle(0, 842, 5, 842), "some text", "some text", true, null);
annotation.setColor(Color.WHITE);
stamper.addAnnotation(annotation, 1);
reader.close();
stamper.close();
This snippet places it at the top left corner but I'm not sure if it's 0mm,0mm. Also it is black and I cannot specify the font.
Any help on the matter is greatly appreciated. Thanks!
You may try rich text annotions as described here:
annotation.put(PdfName.RC, new PdfString( "<font size=\"whatever\">" +
some text+
"</font>" ) );
myStamper.setGenerateAppearances( false );
However I doubt that this is what you need. If you add an appearance then you'll get an rectangular icon in the upper left corner. If you then hover with you mouse over it you are able to read the annotation in form of a pop up. And even if you get a white font color of the annotation text you can't hide the rectangular icon of the annotation itself...
You want to have a white font color which indicates that you want to "transport" some hidden (white color on white background) information. Maybe in this case you may use the following mechanism ( which is normally used for adding watermarks etc.):
String text;
int pageNumber
PdfContentByte overContent = stamper.getOverContent(pageNumber);
overContent.beginText();
overContent.setFontAndSize(yourFont, yourFontSize);
//overContent.setGrayFill(...);
overContent.showTextAligned(PdfContentByte.ALIGN_CENTER, yourText + " Center", 150, 760, 0);
overContent.endText();
Update: To set an annotation to invisble add to your code:
annotation.setColor(Color.WHITE);
//set visibility to 0 (invisble). All values between 0...1 are possible
//so 0.5 means 50% opacity
annotation.put(PdfName.CA, new PdfNumber(0));
I have coded java code and I wanted Arabic words to be displayed at PdfPTable which was asses to itext document to create PDF document
as attached picture "???" is Arabic code '
PdfPTable header = new PdfPTable(6);
PdfPTable tbame = new PdfPTable(1);
tbame.addCell(" >>>>>> " + install.getCustId().getFullName() + " <<<<<<");
tbame.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
tbame.setLockedWidth(false);
tbame.setExtendLastRow(false);
tbame.setWidthPercentage(100);
header.addCell("End");
header.addCell("Start");
Please read the documentation and you'll find out that the addCell(String content) method can not be used to add Arabic text for two reasons:
When you use this method, the default font Helvetica is used. You need to use a font that knows how to draw Arabic shapes. This is explained in the answer to this question: Itext Arabic Font coming as question marks
Arabic is written from right to left, which means that you need to change the run direction of the content of the cell as is explained in my answer to this question: RTL not working in pdf generation with itext 5.5 for Arabic text
A code snippet:
BaseFont bf = BaseFont.createFont("c:/WINDOWS/Fonts/arialuni.ttf",
BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font font = new Font(bf, 12);
Phrase phrase = new Phrase(
"\u0644\u0648\u0631\u0627\u0646\u0633 \u0627\u0644\u0639\u0631\u0628", font);
PdfPCell cell = new PdfPCell(phrase);
cell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
table.addCell(cell);
If you don't have access to the font arialuni.ttf, you'll have to find another font that contains Arabic glyphs.
I'm using the iText library with Java and I have an issue, let me explain:
I have a Word file converted into a PDF and i want to add a table at the end of the document, this works perfectly except when the Word file hasn’t active the feature "No Color" at the tab "Page Layout", the table adds it as "invisible".
I've already tried to change the property Font from the Chunk object that created the content, but it does not work, the table continues showing as "invisible".
How I can solve this
The following code is the one that I use to create the table:
Font font = new Font(1,fontSize, Font.BOLD);
font.setColor(0,0,0);
Chunk name = new Chunk(v_emp.getNombre(),font);
Chunk tipo = new Chunk(v_emp.getDireccion(),font);
Paragraph paragraph = new Paragraph();
paragraph.add(tipo);
paragraph.add(new Chunk("\n"));
paragraph.add(name);
PdfPCell cell1 = new PdfPCell(paragraph);
cell1.setPadding(2);
table.addCell(cell1);
Try selecting the table in PDF with your mouse and see if the table is there and still it is invisible.
If it is there, go to the file menu and do print as pdf.
I'm building a small conversation agent, where the text looks like follows:
I would like to set the System's text to always be red. The text is all placed in a JTextPane.
How can I accomplish this? I have tried doing the following:
agentTextPane.setForeground(Color.red); after the system's text is added, and then switching back to black, however that changes all the text in the JTextPane.
This is how the system's text is added:
//'output' is a stringBuilder
output.append("\nSystem: ").append(tempOutput).append("\n");
agentTextPane.setText(output.toString());
As shown here, you can define an attribute set representing a desired style. For example,
StyledDocument doc = (StyledDocument) jtp.getDocument();
SimpleAttributeSet system = new SimpleAttributeSet();
StyleConstants.setFontFamily(system, "Serif");
StyleConstants.setForeground(system, Color.red);
doc.insertString(doc.getLength(), "...", system);
The styles can be progressive, as shown here.
See Text Component Features for more examples.
You may want to use HTML tags to format your Strings in terms of colour. The following reference may be useful. setting JTextPane to content type HTML and using string builders
output.append("<font color=\"red\">");
output.append("\nSystem: ").append(tempOutput).append("\n");
output.append("</font>");