I just got a question about alignment in the library iText. Say if i was to do a quote program.
For example
On the Left side of the page I would want to put Quote # 01 and on the same line on the other side of the page I want to put the date.
Is this possible using the Paragraph class? If not can any body help me out with any other solutions?
To the best of my knowledge, you can't do this within a single paragraph. You'll have to get the current position (cb.getYLine()) and place a separate chunk with the date. See itext positioning text absolutely if you need pointers on placing the chunk.
Related
i am using docx4j library and using templating to genearte report from my application.
i have following requirement,
When a page break comes between a paragraph content, i need to add a custom title before the next page content starts as you see in figure.
I know if we need to repeat same title , we can achieve it by using table and repeating header row. But there title will be same. Here I need custom title.
Paragraph is getting populatated from backend and how do we figure out page breaks happens at code level ?
Thanks in advance
This has to do with the Word Object Model. Word really does not have the concept of pages in the underlying structure of a document. Word Doesn't Know What a Page Is by Daiya Mitchell, MVP
Because of that, this would be better posted in the Word Answers forum hosted by Microsoft.
There are ways to deal with this using headers (not table headers necessarily although they can be used) or using a shape anchored to the table to occlude the word "continued" in the original header.
When you say templating, are you talking about Word templates (term of art) or something else?
In Java how do we print to a pre-printed template? We have pre-printed form with field names and blank spaces. From Java, I need to print data into the blank spaces.
These pre-printed forms are always of the same template. All the fields and blank spaces are of fixed dimensions. I know the exact position of each blank space i.e., the location of it from the left of the page, top of the page, length of the blank space etc.
We already have an application in .Net where we achieved using RDL(report definition language - https://en.wikipedia.org/wiki/Report_Definition_Language). We are migrating to Java/mysql and was looking on how to achieve it?
Any help is greatly appreciated.
I am trying to write Persian text to a .txt file in Java. Because Persian (Farsi) is read from right to left, how can I write each line such that it is right aligned?
I am currently using Apache's FileUtils.writeLines(), but I am open to other alternatives in order to achieve the problem.
Thanks!
Text alignment is determined by UI that would show your text file. If you are using a plain text file, so it does not have facilities to tell it its text alignment.
If you insist on it, there are special Unicode characters that can tell UI it must be interpreted as right-to-left text. Please see here.
You can wrap each line into a String.format
String.format("%s", formatter.format(i))
or
Apache StringUtils has several methods: leftPad, rightPad, center and repeat.
Read following thread.
How can I pad a String in Java?
You just add spaces if you want to have lines with specific size, otherwise it depends on the tool you use for reading it.
I have an word template. There is an word photo that has to be replaced with an image. This has to be done with Docx4Java.
How do I do this?
If specifically looking to replace a text with an image(which is not possible using docx4j as answered above), you can use replace bookmark with image as an alternative.
Just open your templated word file, position the cursor at desired location and insert->bookmark and name your bookmark.
I followed the instructions here to replace this bookmark with an image
Disclosure: I manage the docx4j project
The VariableReplace code doesn't handle images.
The best way to do this would be to use data bound content controls, specifically a picture content control pointing via XPath at a base-64 encoded image in an XML document (see Getting Started for details).
However, if you want to replace a word with an image, you can do so, but you'll have to write a bit of glue code. It is pretty straightforward.
First, find the word. You can do this using XPath or TraversalUtil (again, see Getting Started for details).
Hopefully it is in a run (w:r/w:t) by itself. If not, you'll need to split the run up so you don't replace adjacent text.
Then, add the image. See the sample ImageAdd.
I suggest you have a look at the XML created when you add an image in Word (ie save and unzip your docx, then look at document.xml). Take care that the XML representing the image is at the correct level (eg child of w:p).
I have a requirement to insert Content into the middle of the page in a PDF.
The Content may be a Dynamic Table or an Image.
My Concept was to first split the PDF into 2 parts, then get the new Content that is to be added and append by replacing a place holder field.
the Splitting is called Tiling as per IText and here is an example for the same.
http://itextpdf.com/examples/iia.php?id=116
The Code above has 2 drawbacks:
1. It splits the page into 16 parts. but that is part of the example. Still i cant figure out a way to split the file into 2 parts only.
2. secondly the split page is converted to a complete page thus disturbing its proportions.
The Rearranging code is the another problem.
The remaining Content should be re-ordered in append mode. but till yet i have only found codes to add complete new pages rather than just the content.
I have found a code that appends the PDF content by replacing a placeholder:
float[] fieldPosition= pdfTemplate.getAcroFields().getFieldPositions("tableField");
PdfPTable table = buildTable();
PdfContentByte cb = stamper.getOverContent(1);
table.writeSelectedRows(0, -1, fieldPosition[1],fieldPosition[4],cb);
Please help me to solve this requirement.
PDF is a presentation format, not an edition format. In other words, it is not designed to allow content insertion, with the original content reflowing gracefully. As a consequence, no tool (at least, none that I know of, and surely not iText) will enable you to achieve what you were given as a requirement.
My advice :
refuse the assignment since it's not feasible, or
get your hands on the original document, insert the desired extra content, and then convert to PDF.