I am using ireport version 1.3.0. I have a description field in database. This field contains some html tags. How to render the html content in Jasper PDF report?
I tried with markup, I got an error markup attribute not found.
Notes fields in EA are not really HTML. They use HTML like tags to do store formatted text.
The easiest way to translate the internal format to something standard such as HTML, RTF or plain text, is to use the API method GetFormatFromField (string Format, string Text)
String
Notes: After accessing a field that contains formatting, use this
method to convert it to your preferred format; returns the field in
the format specified.
Parameters:
Format: String - The format to convert the field to; valid formats
are:
- HTML - Full HTML
- RTF - Rich Text Format
- TXT - Plain text
Text: String - The field to be converted
Related
How in a java project can a HTML form upon submission be converted to PDF and then attached to a email.
Springboot & Thymeleaf are the frameworks in use. The form looks like this:
http://jsfiddle.net/x1hphsvb/5563/
Controller so far:
#org.springframework.stereotype.Controller
#EnableAutoConfiguration
public class Controller {
#RequestMapping("/")
String home() {
return "static/index.html";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Controller.class, args);
}
}
I have looked at this tutorial and searched for a way to do it with PDF Box without success.
Should I take the data in the back end and insert it into a HTML template or insert the data into a PDF template.
The PDF form should also have the collapsability similar to the HTML.
Regarding the conversion of HTML to PDF
The example you refer to has my name in it (a reference to a package name starting with com.lowagie) which means it's about iText, not about pdfBox. PdfBox doesn't convert HTML to PDF, so that's not an option.
Versions of iText with my name in it, predate iText 5 and should no longer be used in a commercial context. See Can iText 2.1.7 / iTextSharp 4.1.6 or earlier be used commercially?
You also use the tag Flying Saucer. Flying Saucer is a third-party tool to convert HTML to PDF that was built on top of such an old version of iText.
Tips:
If you want to convert HTML to PDF, I suggest that you read Converting HTML to PDF using iText
If you want to use a templating format based on HTML, I suggest that you read How to create template and generate pdf using template and database data iText C#
Regarding PDF forms
You wrote: "The PDF form should also have the collapsability similar to the HTML."
Please check ISO 32000-2 (the PDF 2.0 standard) and you'll discover that PDF forms can't collapse the same way HTML forms collapse. You may have seen PDF documents with similar functionality, but those forms weren't ISO 32000-2 documents; they were XFA forms. XFA stands for the XML Forms Architecture, and that technology was deprecated. You'll hardly find any viewers other than Adobe Reader that support such forms.
When it comes to data entry, PDF has lost and HTML 5 has won. If you've read the answer to the question How to create template and generate pdf using template and database data iText C#, you've noticed that the DITO product chose to create HTML 5 templates for data entry and PDF templates for data presentation.
I'm trying to export a text area (for which I use ckeditor) into a Word document. I'm using JSP, and setting HTTP headers of a target page to receive the textarea value in request scope:
<%#page contentType="application/vnd.ms-word"%>
response.setHeader("Content-Disposition", "attachment;filename=responseLetter.doc")
...
<%=textAreaReqScopeValue%>
However, I lose formatting and style of my source ckeditor (example below) when the Word document has been generated:
<p>Dear Anonymous,</p><p>This is in response to your <strong><em><u>request regarding your continued ...
Is there any way to keep the formatting, either by generating the Word document or through CKEditor?
Using googoose.js or html-doc.js solved my problem. An open xml library should have been used to process html tags for the ms-word output.
We are using JSF PrimeFaces' text editor. When we receive String from text editor in backing bean, it also includes HTML tags. Following image might help in understanding this problem.
Following is what we wrote:
Following is what we received:
Next thing we want to do is, to write what was written in text editor, as it is, into PDF using iText. But we do not know how to convert this string (with HTML tags) into only data.
Following was the code:
You can go for XMLWorker in iText. Below code will give you the content in Orange color
document.open();
String finall= "<style>h1{color:orange;} </style><body><h1>This is a Demo</h1></body>";
InputStream is = new ByteArrayInputStream(finall.getBytes());
XMLWorkerHelper.getInstance().parseXHtml(pdfWriter,document, is);
document.close();
Whatever HTML content we are giving it will create it as PDF. The only thing to take care is it will work for XHTML means all the opening tags should have a end tag.
For example in HTML for break we will use <br> but here it should be <br/>Hope this will help you.
Use JSoup to achieve this. Jsoup
Then in your code
Jsoup.parse(textRecievedFromEditor).text();
This will return text without HTML Tags.
e.g.
For example, given HTML {#code <p>Hello <b>there</b> now!</p>},
{#code p.text()} returns {#code "Hello there now!"}
I am passing HTML text as parameter value in java. like
parameter.put("TEMP_TEXT","<p>test</P>");
I have bound this parameter in ireport as static text field like $P{TEMP_TEXT} then it will be converted in plain text.
output ought to be 'test'
Which setting need to be added on staticText in iReport for acquire same?
Add a Text Field to your report.
Text Field Expression : $P{TEMP_TEXT}
Markup : html
Lets see at this example:
I've got HTML tagged text:
<font size="100">Example text</font>
I have *.odt (OpenDocument Text) document where I want to place this HTML text with formatting depends on HTML tags (in this example font tag should be ommited and text Example text should have 100point size font in result *.odt file).
I prefer (but this is not strong requirement) to use OpenOffice UNO API for Java to achieve that. Is there any way to inject this HTML text into body of *.odt document with simple UNO API build-in HTML-odt converter or something like this (or I have to manually go through HTML tags in text and then use OO UNO API for placing text with specific formatting - e.g. font size)?
OK, this is what I've done to achieve this (using OpenOffice UNO Api with JAVA):
Load odt document where we want to place HTML text.
Goto place where you want to place HTML text.
Save HTML text in temp file in the system (maybe it is possible without saving with http URL but I wasn't testing it).
Insert HTML into odt following this instructions and passing URL to temp HTML file (remember about converting system path to OO path).
Maybe you can use JODConverter or you can use the xslt from xhtml2odt