I am using the docx4j in a java app which parses HTML/CSS and exports a docx.
What I need is to make something like:
but seems like I can only make a couple of tables with docx4j. Can it read entire html css files or only basic html with no css?
Also I've been trying to use everything from flexbox, to display table, to just float ( like 15 years ago ), for making the gird layout.
I am curious if it is a dead end or it's just me and I don't know how to use it
docx4j-ImportXHTML can read CSS.
It uses Flying Saucer to parse the XHTML: https://github.com/flyingsaucerproject/flyingsaucer
Flying Saucer uses CSS 2.1.
If you hit a limitation, the first thing to do is to see whether Flying Saucer has captured the relevant value. If it has, then docx4j-ImportXHTML needs to handle it correctly.
Alternatively, Google to check whether FS handles flexbox etc. I don't think ImportXHTML handles float right now. You could add that, of course.
Related
The functionality for the project that I am currently working is to get data from a WYSIWYG editor and convert all the input to a PDF document. The problem is sometimes there is necessary to add wider tables and this produces a truncated visualization of them.
To solve this problem, I added to the editor (specifically, CKEditor) a HR button but I renamed it to "Change page orientation", so users can click that before inserting a table. In Java, I used iText 7 to detect this element (<hr>) and change the page orientation. This works like a charm.
Example using iText with a simple table
Now, requirements changed and for license purposes we need to replace iText for another HTML to PDF converter, but we need to keep this functionality.
I found OpenHTMLToPdf and I liked it, but I didn't find the way to replicate this page orientation when a hr (or another specific element) is found.
How can I solve that? I can use whatever library as long as they are open source.
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?
I am developing an editor in Java in which I want to include bullets of different types. I am using HtmlEditorKit. I wanted to add a style sheet but it is not working, I wanted to know if following Pseudo element is supported in Java, if it is supported can you please guide me where I am going wrong?
styleSheet.addRule("ul{list-style-type:none;margin:0px 20px;}");
styleSheet.addRule("li:before{content: \"✤\";}");
The Java HTML rendering engine only supports a (very) limited amount of CSS.
Can i create an expandable list in pdf files. Expandable list will be of the form :
+Item1
+Item2
-Item3
-Subitem3.1
-Subitem3.2
+Item4
-Item5
-Subitem5.1
-Subitem5.2
-Subitem5.3
Also I need to create the pdf file from Java(I was thinking of using iText, is another library better/easier?). Is this possible. Or is a report in some other standard format(not pdf or html) an easier way out.
First this: I'm the creator of iText, so forgive me for not pointing you to other solutions ;-)
Now for your question: you're asking for dynamic functionality (a tree structure that opens/closes upon user interaction) inside a PDF document.
The most obvious answer is: this isn't possible. When creating PDF, think of paper. Can you print a tree structure on paper that opens/closes when the end user touches the paper? No, you can't, therefore you're asking something that isn't possible in PDF.
The less obvious answer is: it depends. What type of PDF are we talking about?
If you're talking about an interactive XFA form, then you may be able to achieve what you want. The XML Forms Architecture (XFA) is an XML specification that can be used to define interactive forms. When you use XFA, the PDF is nothing more than a container for XML. This XML is rendered dynamically inside Adobe Reader. How to create an XFA form? I only know about two products: Adobe LiveCycle Designer and Avoka Smart Forms Designer.
If you're talking about 'regular PDF', then one option is to embed a swf file. In this case, the tree structure will be rendered by Flash player (which could be a disadvantage, because this might not work with all PDF viewers). Another disadvantage: the tree structure will be confined to a fixed rectangle on a fixed page.
Finally: you can have create such a structure in the bookmarks panel. In PDF terminology, those bookmarks are called Outlines. Obviously, the tree structure won't be a part of the printable content. It will be visible in a separate panel in your PDF viewer.
I have a library which generates pdf document with images.
I want to be able to add text after each image. What is the syntax for that? How to insert text into pdf documents?
I have to use the library I have, not another one.
First of all, mkl is correct, have a look at the specification for all of the details. PDF is an exact language, if you make mistakes they will routinely be punished severely once you open the PDF in viewers.
Secondly, when you think about putting text on the page, don't forget that besides the text operators to draw the text on the page, you'll also have to specify the font to use to draw this text. Which will include making sure there is a font resource included in the PDF file if your library doesn't automatically handle all of that for you.
If you want to cut corners (I shiver while writing this) and perhaps don't read the specification as thoroughly, try this.
1) Create a PDF file that looks more or less like what you want.
2) Use a tool such as pdfToolbox from callas (http://www.callassoftware.com/callas/doku.php/en:download) or Browser from Enfocus (http://www.enfocus.com/en/products/browser). Both of these tools allow you to investigate the low-level structure of a PDF file, including looking at the actual page description code. This will show you how fonts are embedded (if you have to do it yourself that could be very handy) and how text is rendered on the page (and how you set the font, size, color etc... to use).