Click to See Complete Forum and Search --> : HTML to PDF on the fly?


cakeday
12-04-2003, 03:01 PM
Hi all,

I have a webpage, which displays the records queried from the oracle database on the web using HTML table(s).

I want to give the users a button,which upon clicked should exports whatever is on the webpage to a PDF FORMAT.

I cannot hardcode and have a .PDF file sitting on the server, because in my webpage the parameters are passed dynamically, so i need to create the PDF file on the fly.

So can anyone tell me, how to do this. Any sample codes or links will be very useful. Thank you in advance.

i accomplished exporting HTML TO EXCEL ON THE FLY USING THE FOLLOWING SYNTAX,

Before i write my table, put this above it.
<%
Response.ContentType = "application/vnd.ms-excel"
%>
<table>
<tr>
<td>field1</td><td>field2</td><td>field3</td>
<td>field1</td><td>field2</td><td>field3</td>
</tr>
</table>

I am trying to accomplish exporting HTML to PDF on the fly using the same concept and the following syntax,
<%
Response.ContentType = "application/pdf"
%>

But for some reason, this does not seem to work. Is there anything else that i might need to accomplish the same?
Do i need any adobe plug-ins on my server?

Any help on this will be highly appreciated.

Thank you.

ray326
12-04-2003, 03:49 PM
Sorry but that only works because your version of Excel knows what to do with HTML table tags. I.e., you're not really sending an Excel document. To REALLY create a specific type of document you have to do it on the server using libraries designed to do that document generation process. There ARE such things. Search Google for ASP PDF LIBRARY and you'll turn up quite a few.

In your situation you might be better off pointing your users to software that lets them "print" to a PDF file. Adobe sells such software and I've used a freeware program called PDFCreator that works very well.

Khalid Ali
12-04-2003, 08:54 PM
The only way I can think of is using some application other then your browser.
Here is what I did few years back for some one.

Submit the page data to a java application using a java servlet,then servlet would create a pdf file with that data and then serv it.

I am pretty sure you will need to something like this

mrizwan
11-12-2006, 03:38 PM
I know this is very late reply .. but might help any users searching this forum for same problem.
To create your own pdf stuff ... you should have some pdf conversion component installed on the server. Otherwise http://www.PdfonFly.com and few similar sites provide you such facility to create pdf files on the fly from html pages.

Hope this help.

htlll
01-09-2009, 09:08 AM
You can use OpenOffice.org, running as a server and command it remotely for document convertion.

Besides HTML to PDF, there are also possible other convertions:
doc --> pdf, html, txt, rtf
xls --> pdf, html, csv
ppt --> pdf, swf
Code example

import java.io.*;
import officetools.OfficeFile; // this is my tools package
...
FileInputStream fis = new FileInputStream(new File("c:/test.html"));
FileOutputStream fos = new FileOutputStream(new File("c:/test.pdf"));

// suppose OpenOffice.org runs on localhost, port 8100
OfficeFile f = new OfficeFile(fis,"localhost","8100", true);
f.convert(fos,"pdf");


From: HTML to PDF with PHP, Java or ASP
dancrintea.ro/html-to-pdf/