This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes Creating text in PDF with the FlyingSaucer library Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Creating text in PDF with the FlyingSaucer library " Watch "Creating text in PDF with the FlyingSaucer library " New topic
Author

Creating text in PDF with the FlyingSaucer library

Deepak Naithani
Greenhorn

Joined: Aug 30, 2012
Posts: 25
Converter1.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Title of document</title>
</head>

<body>

<h1>Hello World</h1>
<b>Name:</b>
<input type="text" name="usrname" ></input>

</body>

</html>


Converter.java
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import org.xhtmlrenderer.pdf.ITextRenderer;

import com.lowagie.text.DocumentException;

public class Convertor {

public static void main(String[] args) throws IOException,
DocumentException {
String inputFile = "C:/Documents and Settings/ADMIN/workspace/Html_to_PDF/WebContent/Converter1.xhtml";
String url = new File(inputFile).toURI().toURL().toString();
String outputFile = "C:/Documents and Settings/All Users/Desktop/Converted.pdf";
OutputStream os = new FileOutputStream(outputFile);

ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(url);
renderer.layout();
renderer.createPDF(os);

os.close();
}
}


I have use this example for creating PDF (example is available in internet) but textbox part doesn't appear. So, help me how to create the textbox in PDF for entering the data and also tell me how to save this PDF (I have use online passport application so i'm trying to built PDF as like passport application).
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41089
    
  44
Have you tried making the HTML form proper by adding appropriate "form" tags?


Ping & DNS - my free Android networking tools app
Deepak Naithani
Greenhorn

Joined: Aug 30, 2012
Posts: 25
While displaying in browser it displays in proper format (Name: <textbox>)

In pdf it is not showing in proper format.

then what shouls i do for it. Only the requirement is of textbox.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Deepak Naithani wrote:While displaying in browser it displays in proper format (Name: <textbox>)


Browsers will try to do something reasonable with malformed HTML. Presumably the product you're asking about doesn't do that, or maybe it doesn't do it in the way you expected.

I think you should follow Ulf's suggestion -- especially since your only requirement is to show a text box. Right now you're acting as if your requirement is to use exactly that HTML and nothing else, which it isn't.
Deepak Naithani
Greenhorn

Joined: Aug 30, 2012
Posts: 25
Ok if i'll use the form tag i will require server side scripting for it (eg. jsp) it will work on browser. I want all this functionality in PDF. Like "Name label and textbox for name, Number label and textbox for number, etc".

I want to make a PDF like online passport application which is providing a PDF to get downloaded and at user side we can fill the form in PDF.

Please understand what i am trying to do i want to add textbox to PDF form. Is there any way i could do it.


How can i migrate this things with each other ?


[Download untitled.bmp] Download

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Well, if you want that PDF-producing product to produce PDF from malformed HTML according to your specifications, you could certainly change it to do that. I am right in believing that it's open source, aren't I? If so, then you could fork it. But I think that might be a lot of work.
Deepak Naithani
Greenhorn

Joined: Aug 30, 2012
Posts: 25
Yes it requires a lot of work. I've found JasperReport, itext and core-renderer open source software for this so how to make a proper use of it to complete my work.

You got the point what i'm trying to do? Thanks for it.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41089
    
  44
While I don't understand why you have to work with broken HTML, have you at least tried if it works with correct HTML? Knowing whether this is a limitation of FlyingSaucer in general, or whether it's simply due to the broken HTML, would be important in order to make decisions about how to proceed.
Deepak Naithani
Greenhorn

Joined: Aug 30, 2012
Posts: 25
I was trying to do new type of thing so i was asking for help.
Thanks for the HELP.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating text in PDF with the FlyingSaucer library
 
Similar Threads
jsp:setProperty and requestDispatcher.forward problem
Disable HTML frame using Javascript
Problem in I18N in Spring
Web app exception: Name jdbc is not bound in this Context
Getting a 500 HTTP status returned from my web service with no errors in log