Jsf To Pdf Converter

  1. Jsf To Pdf Converter File
  2. Jsf To Pdf Converter I Love
  3. Jsf To Pdf Converter Docx
Ranch Hand
posted 5 years ago

The PDF online converter can convert from Microsoft Word to PDF as well as a lot of other formats. If the PDF contains only scans from text pages, you can convert it to a searchable PDF file using the OCR functionality. If you want more advanced features like rotate, merge or sort PDF pages, you can use this free PDF editor. How to Convert HTML files. Click inside the file drop area to upload an HTML file or drag & drop an HTML file. Note: You can upload ZIP archives that contain an HTML page along with resources.

Hi,
I need your help and guidance on how to export a full jsf page to PDF. In my jsf page, I have a button to export to PDF and some fields where I am retrieving the values from a database. The form is ready but I don't know how to program code or program a button to export the page to PDF. I tried to search for an easy and a standard way but unfortunately I didn't find any useful example or code. Could you please instruct and to guide me on how to this.
Thanks
Saloon Keeper
posted 5 years ago
  • 1
Strictly speaking, one would render a JSF View as PDF using an alternative renderer instead of the default HTML renderer.
However, it's more likely that like most people you don't really want to 'export the JSF page to PDF', you want to generate a downloadable document in PDF form for viewing, printing and/or saving on the client's machine. Which is entirely different.
And you probably don't want the PDF to literally resemble the screen display, you probably want to construct the PDF to look better as a printed document.
If you literally wanted the screen display in PDF form, Linux (and probably Mac) users can simply use their browser's 'Print as PDF' printer option. I think that this MIGHT be available in newer versions of Windows, as well, but if not, there are 3d-party printer drivers that can do the job.
However, if you want to generate a printer-friendly PDF document, don't do it in JSF. Write a standard (non-JSF) servlet and use one of the available PDF rendering libraries to render the servlet output stream as a PDF. Pass any data you need to exchange between JSF and the servlet in session- or application-scope objects.
JSF wasn't intended to be a do-everything framework, and PDF's are one of the things that it wasn't intended to do.

This page explains how you can easily convert a.jsp file to a PDF using free and easy to use tools from PDF24. The methods to create PDF files explained here are free and easy to use. A PDF creator and a PDF converter makes the conversion possible. The PDF24 Creator installs for you a virtual PDF printer so that you can print your.jsp file on that printer in order to convert your file to PDF. This page explains how you can easily convert a.js file to a PDF using free and easy to use tools from PDF24. The methods to create PDF files explained here are free and easy to use. A PDF creator and a PDF converter makes the conversion possible. The PDF24 Creator installs for you a virtual PDF printer so that you can print your.js file on that printer in order to convert your file to PDF.

Jsf To Pdf Converter

Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.

Ranch Hand
posted 5 years ago
Thanks for your valueable information.
What libraries do you recommend to read about? Are there any examples?
Saloon Keeper
posted 5 years ago
The iText library is very popular and you should have no problems finding example code.
I often use Apache FOP, which allows me to use an XML template for the document instead of coding the document elements in logic.

Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.

Ranch Hand
posted 5 years ago
Thanks
What do you recommend for beginners? Is it Itext or Apache Fob?
The PDFs will contain only text, 2 tables and few fields to be retrieved from the database?
Saloon Keeper
posted 5 years ago
Whichever you prefer. There's no 'best' solution. PDF's aren't very simple to begin with, anyway. FOP allows you to define the page prototype as an XML document and then invoke a translator to convert the document to PDF. The iText library is an API that you can use to build PDFs up manually element by element.

Some people, when well-known sources tell them that fire will burn them, don't put their hands in the fire.
Some people, being skeptical, will put their hands in the fire, get burned, and learn not to put their hands in the fire.
And some people, believing that they know better than well-known sources, will claim it's a lie, put their hands in the fire, and continue to scream it's a lie even as their hands burn down to charred stumps.

Ranch Hand
posted 15 years ago
what is the best way to have pdf if all my pages are in jsf?
i'm planning to let user to print in pdf format when they click the 'print' button..
any suggestions on how to start with it?

Jys<br /><a href='http://jy-s.com' target='_blank'>http://jy-s.com</a><br /> <br />Trying my very best to learn java, please forgive me if i'm asking some really stupid questions.

Ranch Hand
posted 15 years ago
Ranch Hand
posted 15 years ago
i've read the thread.. hmm, by using this method provided i can actually convert my stuff into pdf?

and this line.. response.getOutputStream().write(yourdata[]);
i will pass all the things i want to retrieve from database here? do u happened to have a complete example for me to refer?
thks in advance..

Jys<br /><a href='http://jy-s.com' target='_blank'>http://jy-s.com</a><br /> <br />Trying my very best to learn java, please forgive me if i'm asking some really stupid questions.

Rancher
posted 15 years ago
The code snippet assumes that the 'yourdata' array holds the contents of a PDF file. To create a PDF file from your database data, you will need to use some PDF library, such as mentioned here.
Ranch Hand
posted 15 years ago
so how will 'yourdata' look like? xml? html?
sorry, this is my first time generating pdf so i'm not really sure what do i need and how do i do that.

Jys<br /><a href='http://jy-s.com' target='_blank'>http://jy-s.com</a><br /> <br />Trying my very best to learn java, please forgive me if i'm asking some really stupid questions.

Rancher
posted 15 years ago
'yourdata' should contain a binary representation of the PDF file. That you can create by using a PDf libraray, as mentioned in my previous post. iText in particular has a thorough introduction.
Ranch Hand
posted 15 years ago
from the iText eg, i see that most of it are using servlet. just wondering, is it possible to have pdf without using servlet?

Jys<br /><a href='http://jy-s.com' target='_blank'>http://jy-s.com</a><br /> <br />Trying my very best to learn java, please forgive me if i'm asking some really stupid questions.

Rancher
posted 15 years ago
The servlets just serve as examples. iText can be used in any kind of Java program.
Ranch Hand
posted 15 years ago
So Jolie, any success? I mean, have you actually tried out any of the suggestions and code we've provided?
Ranch Hand
posted 15 years ago
i've actually read thru the itext.. and one of the example their using jsp with iText to generate...
hmm.. might used that, but still not sure how they do column and etc .. cos wat i can see is that they only using paragraph.. cos i'm generating reports, so they will be a lot of columns and tables involves...
in my jsp page, how can i called the backing bean? cos if i were to use jsp to generate pdf(s), i may need to refer to backing beans to do retrieval from the database.. and i think i won't have any jsf tags in that jsp page that generate pdf...

Jys<br /><a href='http://jy-s.com' target='_blank'>http://jy-s.com</a><br /> <br />Trying my very best to learn java, please forgive me if i'm asking some really stupid questions.

Ranch Hand
posted 15 years ago
Jolie, Jolie, Jolie...
Remember that method I showed you?

Ok, lets change that just a bit...

Now, supose you have a commandButton that calls a backing bean method called generatePDF(). Let's take a look at what that method might look like..

And that's it. It can all be done in the backing bean. That is what we have been trying to convey.
Greenhorn
posted 15 years ago
use this.
it will work
am doing this works great with itext.
public void executePDF() {
try {
FacesContext faces = FacesContext.getCurrentInstance();
HttpServletResponse response =
(HttpServletResponse) faces.getExternalContext().getResponse();
// setting some response headers
response.setHeader('Expires', '0');
response.setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
//response.setHeader('Content-disposition','inline; filename=kiran.pdf');
response.setHeader('Pragma', 'public');
response.setContentType( 'application/pdf' );
//response.setHeader('Content-Disposition', 'attachment;filename='ContactList.pdf');
response.addHeader('Content-disposition', 'attachment;filename='DataListBean.pdf');
//step 1: creation of a document-object
Document document = new Document(PageSize.A3.rotate(), 10, 10, 10, 10);
//step 2: we create a writer that listens to the document
// and directs a PDF-stream to a temporary buffer
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
PdfWriter writer = PdfWriter.getInstance( document, baos);
//step 3: we open the document
document.open();
Table datatable = getTable();
int rowCount = data.getRowCount();
// step 4: we add a paragraph to the document
for (int i=0;i<rowCount;i++) {
datatable.setDefaultHorizontalAlignment(Element.ALIGN_LEFT);
List list = (List)data.getRowData();
Iterator iter = list.iterator();
while(iter.hasNext()) {
Object obj = (Object) iter.next();
datatable.addCell(obj.toString());
if (i<=2) {
System.out.println(obj.toString());
}
}
if (!writer.fitsPage(datatable)) {
datatable.deleteLastRow();
i--;
document.add(datatable);
document.newPage();
datatable = getTable();
}
}
document.add(datatable);
//step 5: we close the document
document.close();
//step 6: we output the writer as bytes to the response output
// the contentlength is needed for MSIE!!!
response.setContentLength(baos.size());
// write ByteArrayOutputStream to the ServletOutputStream
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
baos.flush();
faces.responseComplete();
//DataOutput output = new DataOutputStream( response.getOutputStream() );
//byte[] bytes = buffer.toByteArray();
//response.setContentLength(bytes.length);
//for( int i = 0; i < bytes.length; i++ ) { output.writeByte( bytes[i] ); }
} catch(Exception e) {
e.printStackTrace();
}
}
private Table getTable()
throws BadElementException, DocumentException {
int colCount = columnHeaders.getRowCount();
Table datatable = new Table(colCount);
datatable.setPadding(4);
datatable.setSpacing(0);
datatable.setBorder(Rectangle.NO_BORDER);
int headerwidths[] = {14,3,3,9,8,5,14,9,5,3,1,4,4,10,3,3,2,10,10,2};
datatable.setWidths(headerwidths);
datatable.setWidth(140);
// the first cell spans 20 columns
Cell cell = new Cell(new Phrase('NEMO Order Tool Report',
FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD)));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setLeading(10);
cell.setColspan(20);
cell.setBorder(Rectangle.NO_BORDER);
cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
datatable.addCell(cell);
// These cells span n rows
datatable.setDefaultCellBorderWidth(1);
datatable.setDefaultHorizontalAlignment(1);
datatable.setDefaultRowspan(1);
List colList = (List)columnHeaders.getWrappedData();
for (int i=0; i < colList.size();i++) {
ColumnHeader header = (ColumnHeader) colList.get(i);
datatable.addCell(header.getLabel());
}
return datatable;
}
Greenhorn
posted 9 years ago

sridhar panini wrote:use this.
it will work
am doing this works great with itext.
public void executePDF() {
try {
FacesContext faces = FacesContext.getCurrentInstance();
HttpServletResponse response =
(HttpServletResponse) faces.getExternalContext().getResponse();
// setting some response headers
response.setHeader('Expires', '0');
response.setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
//response.setHeader('Content-disposition','inline; filename=kiran.pdf');
response.setHeader('Pragma', 'public');
response.setContentType( 'application/pdf' );
//response.setHeader('Content-Disposition', 'attachment;filename='ContactList.pdf');
response.addHeader('Content-disposition', 'attachment;filename='DataListBean.pdf');
//step 1: creation of a document-object
Document document = new Document(PageSize.A3.rotate(), 10, 10, 10, 10);
//step 2: we create a writer that listens to the document
// and directs a PDF-stream to a temporary buffer
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
PdfWriter writer = PdfWriter.getInstance( document, baos);
//step 3: we open the document
document.open();
Table datatable = getTable();
int rowCount = data.getRowCount();
// step 4: we add a paragraph to the document
for (int i=0;i<rowCount;i++) {
datatable.setDefaultHorizontalAlignment(Element.ALIGN_LEFT);
List list = (List)data.getRowData();
Iterator iter = list.iterator();
while(iter.hasNext()) {
Object obj = (Object) iter.next();
datatable.addCell(obj.toString());
if (i<=2) {
System.out.println(obj.toString());
}
}
if (!writer.fitsPage(datatable)) {
datatable.deleteLastRow();
i--;
document.add(datatable);
document.newPage();
datatable = getTable();
}
}
document.add(datatable);
//step 5: we close the document
document.close();
//step 6: we output the writer as bytes to the response output
// the contentlength is needed for MSIE!!!
response.setContentLength(baos.size());
// write ByteArrayOutputStream to the ServletOutputStream
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
baos.flush();
faces.responseComplete();
//DataOutput output = new DataOutputStream( response.getOutputStream() );
//byte[] bytes = buffer.toByteArray();
//response.setContentLength(bytes.length);
//for( int i = 0; i < bytes.length; i++ ) { output.writeByte( bytes[i] ); }
} catch(Exception e) {
e.printStackTrace();
}
}
private Table getTable()
throws BadElementException, DocumentException {
int colCount = columnHeaders.getRowCount();
Table datatable = new Table(colCount);
datatable.setPadding(4);
datatable.setSpacing(0);
datatable.setBorder(Rectangle.NO_BORDER);
int headerwidths[] = {14,3,3,9,8,5,14,9,5,3,1,4,4,10,3,3,2,10,10,2};
datatable.setWidths(headerwidths);
datatable.setWidth(140);
// the first cell spans 20 columns
Cell cell = new Cell(new Phrase('NEMO Order Tool Report',
FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD)));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setLeading(10);
cell.setColspan(20);
cell.setBorder(Rectangle.NO_BORDER);
cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
datatable.addCell(cell);
// These cells span n rows
datatable.setDefaultCellBorderWidth(1);
datatable.setDefaultHorizontalAlignment(1);
datatable.setDefaultRowspan(1);
List colList = (List)columnHeaders.getWrappedData();
for (int i=0; i < colList.size();i++) {
ColumnHeader header = (ColumnHeader) colList.get(i);
datatable.addCell(header.getLabel());
}
return datatable;
}


Hello sridhar panini,
Please, can you give me the libraries used for this code? Thank you
Ranch Hand
posted 9 years agoJsf
Hello,
I will suggest use Jasper reports, you will get the PDF within no time.
I have the made a sample long ago. If you want let me know.
BR,

Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup

Greenhorn
posted 9 years ago
Hello Prithvi Sehgal,
I tried to use JasperReport 3.7.5 but I got some problemes. This my code with JasperReport

When I run this code, I get an empty pdf. Please can you help me to use Jasperreport to make my Reports.
Thank You
Ranch Hand
posted 9 years ago
Hello Boris,
I didn't look at the code before. Try to pick .jasper directly from IReport and see.
It should work. From where you data is coming?
HTH,

Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup

Ranch Hand
posted 9 years ago
Hello Boris,
I can see that you are using the compiler inside the code. I wanted to know from where
your data is coming?
Checkout my snippet of code.

BR,

Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup

Greenhorn
posted 9 years agoI try your code, but I get always an empty pdf

Jsf To Pdf Converter File


I wanted to know from where your data is coming?


With ireport, I defined a Database JBDC Connexion. And, in my jrxml file, I used a query whose the database connexion parameters are defined in the Database JBDC Connexion. I hope that I answered correctly to your question. English isn't my mother tongue, so excuse me for my bad english
Thank you
Ranch Hand

Jsf To Pdf Converter I Love

posted 9 years ago
Hello Boris,
Thats true. So basically is your query parameter based, like a criteria query. For example, find all all employees
whose salary is greater then your specified parameter. If you see that, you are passing a empty hashmap to your
jrxml. You are not passing any parameters. You need to put your parameters in the hashmap and send that hashmap.
Be sure that your your parameter in Hashmap is of the same name as in the JRXML.
HTH,

Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup

Greenhorn
posted 9 years ago
I don't pass parameter because my query don't have parameter. You can see my jrxml file
Pdf
Ranch Hand
posted 9 years ago
Hello Boris,
Where are you calling the getConnection() method to get the connection. In your code, i don't see anywhere that you are calling
the getConnection method.
Put in your printPdf() method as

I feel your connection reference is not properly initialized.
Have you checked your SQL in a editor like SQL editor, is it returning any results? Additionally, try to use the .jasper file directly and comment
the JRXML compile. To me your JRXML looks okay. Additionally, check is is your connection object null means is it able to correct to database
properly?
BR,

Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup

Jsf To Pdf Converter Docx

Greenhorn
posted 9 years ago
Hello,
Now the report is generated, but I can't open it because it is used by another process. After verification, this is the process 'java.exe' which use the genereted report.
I try to resolve it. Please, don't forget me If you have an idea to resolve the probleme.
I appreciate the attention you have given me
Ranch Hand
posted 9 years ago
Hello Boris,
Can you tell me what exception you are getting exactly? Additionally i would like to know did you try to use
.jasper file directly rather then using the built in compile utility.
BR,

Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup