Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating text in PDF with the FlyingSaucer library

 
Deepak Naithani
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried making the HTML form proper by adding appropriate "form" tags?
 
Deepak Naithani
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21581
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
Filename: untitled.bmp
Description: Like this output i want in PDF
File size: 86 Kbytes
[Download untitled.bmp] Download Attachment
 
Paul Clapham
Sheriff
Posts: 21581
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42969
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was trying to do new type of thing so i was asking for help.
Thanks for the HELP.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic