printing pdf from java

D

dingo

Can someone answer me how to print an pfd from java code ?
this is asked many times before and about 1000 times answerd before. its a
pitty i have 10times1000 differents answers.

i have found some application examples but none of them works.
this fellow seems to have the same problem, unfortunelly also no answer on
his question on the java forum
http://forum.java.sun.com/thread.jspa?forumID=31&threadID=583233

thx in advantage.
 
N

naiki

Can someone answer me how to print an pfd from java code ?
this is asked many times before and about 1000 times answerd before. its a
pitty i have 10times1000 differents answers.

i have found some application examples but none of them works.
this fellow seems to have the same problem, unfortunelly also no answer on
his question on the java forum
http://forum.java.sun.com/thread.jspa?forumID=31&threadID=583233

thx in advantage.

Try UJAC (http://ujac.sourceforge.net/)
I am successfully using it.
 
D

dar7yl

dingo said:
Can someone answer me how to print an pfd from java code ?
this is asked many times before and about 1000 times answerd before. its
a
pitty i have 10times1000 differents answers.

You can try Jasper Reports http://sourceforge.net/projects/jasperreports

The big problem with jasper is that it takes a computer scientist (as
opposed to a rocket scientist) to install and configure it. The docs are
severely lacking.

The quickest way to get jasper working is to load up JasperAssistant (
http://www.jasperassistant.com/ ), which also requires Eclipse, which
requires ...

If you want server-side reporting, you have to install Jakarta Tomcat (
http://jakarta.apache.org/tomcat/ ), and all it's dependancies.

I would strongly recommend that you stay away from CrystalReports. It used
to be a good product, but they went corporate, and now only fortune-500
executives know how to use it :)

regards,
Dar7yl
 
D

dingo

eclipse is no problem.
Note i'm talking about existing PDF's i just want to create a batch file
wich makes a hardcopy of 100 PDF
wich are created monthly by our unix server.
 
D

dar7yl

dingo said:
eclipse is no problem.
Note i'm talking about existing PDF's i just want to create a batch file
wich makes a hardcopy of 100 PDF
wich are created monthly by our unix server.

Here's how to return a pdf back to your browser, where you have the option
of saving or displaying it. Assuming that your file "report.pdf" is placed
in the local resource context for the servlet.

adapted from
http://www.javaalmanac.com/egs/javax.servlet/GetImage.html?l=rel
This example returns to the requestor, an file read from the server:
<code> // This method is called by the servlet container to process a GET
request.
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
// Get the absolute path of the image
ServletContext sc = getServletContext();
String filename = sc.getRealPath("report.pdf");

// Get the MIME type of the image
String mimeType = sc.getMimeType(filename);
if (mimeType == null) {
mimeType = "application/pdf"; // just force default
}

// Set content type
resp.setContentType(mimeType);

// Set content size
File file = new File(filename);
resp.setContentLength((int)file.length());

// Open the file and output streams
FileInputStream in = new FileInputStream(file);
OutputStream out = resp.getOutputStream();

// Copy the contents of the file to the output stream
byte[] buf = new byte[1024];
int count = 0;
while ((count = in.read(buf)) >= 0) {
out.write(buf, 0, count);
}
in.close();
out.close();
}</code>
 
D

dingo

The prints should come out of the printer (HP8500 postscript) without any
user interaction.
TM




dar7yl said:
dingo said:
eclipse is no problem.
Note i'm talking about existing PDF's i just want to create a batch file
wich makes a hardcopy of 100 PDF
wich are created monthly by our unix server.

Here's how to return a pdf back to your browser, where you have the option
of saving or displaying it. Assuming that your file "report.pdf" is placed
in the local resource context for the servlet.

adapted from
http://www.javaalmanac.com/egs/javax.servlet/GetImage.html?l=rel
This example returns to the requestor, an file read from the server:
<code> // This method is called by the servlet container to process a GET
request.
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
// Get the absolute path of the image
ServletContext sc = getServletContext();
String filename = sc.getRealPath("report.pdf");

// Get the MIME type of the image
String mimeType = sc.getMimeType(filename);
if (mimeType == null) {
mimeType = "application/pdf"; // just force default
}

// Set content type
resp.setContentType(mimeType);

// Set content size
File file = new File(filename);
resp.setContentLength((int)file.length());

// Open the file and output streams
FileInputStream in = new FileInputStream(file);
OutputStream out = resp.getOutputStream();

// Copy the contents of the file to the output stream
byte[] buf = new byte[1024];
int count = 0;
while ((count = in.read(buf)) >= 0) {
out.write(buf, 0, count);
}
in.close();
out.close();
}</code>
 
Joined
May 11, 2008
Messages
7
Reaction score
0
Pre java print pdf library

Recently Sun released an open source called PDF Renderer which can be used for pdf printing.
You can find the sample code in the below link:
venkatsadasivam.wordpress.com/2008/11/03/java-print-pdf/
 
Joined
Jan 13, 2009
Messages
1
Reaction score
0
another solution

There is another solution, based on OpenOffice.

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

Code example:
Code:
import officetools.OfficeFile;
...
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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,253
Latest member
BlytheFant

Latest Threads

Top