Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to print a .pdf file from Java without using Adobe AcrobatReader (portable code) from an applet

Posted on 2006-05-24
15
Medium Priority
?
2,508 Views
Last Modified: 2013-12-03
Hi everybody,

I have an applet and i want to preview and print a .pdf file.
The applet must be platform independent, the file must be printed on one of the local printers, so the solution shouldn't be using acrobat reader.

10x

valipotor
0
Comment
Question by:valipotor
  • 5
  • 4
  • 3
  • +2
15 Comments
 
LVL 92

Expert Comment

by:objects
ID: 16750772
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16750991
0
 
LVL 12

Expert Comment

by:Giant2
ID: 16750998
Even PDF4Java:
http://sourceforge.net/projects/pdf4j

Bye, Giant.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Author Comment

by:valipotor
ID: 16751168
Hi Giant,

pdf4j - This project has not yet created any file release packages.

As for the first link, I was expecting a more precise info. The matter is of urgent nature, that's why i gave 500 points for this question.

Hi objects,
 I 'm now downloading pdfbox ... however, the lib has about 3MB. This can be a problem if used from an applet.

valipotor
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 16751240
Java libraries to read and write PDF files
http://schmidt.devlib.org/java/libraries-pdf.html
0
 
LVL 6

Author Comment

by:valipotor
ID: 16751358
Hi hoomanv,
I am trying to print an exisiting pdf file to a printer, not create a pdf file.
And because i am writing an applet, i also need the .jar file to be small, let's say under 500k.

10x
0
 
LVL 92

Assisted Solution

by:objects
objects earned 800 total points
ID: 16756070
I'm not aware of anything that meets those requirements sorry
0
 
LVL 8

Assisted Solution

by:colr__
colr__ earned 800 total points
ID: 16758767
If this is an applet, then you are going to either have to embed any Java PDF code you manage to find (which as Objects says, there isnt a package that meets your requirenemtns, to my knowledge).

Why do you ned to explicitly control how the pdf is sent to the printer, when Adobe reader perfoms all that for you (and nearly all clients have that s/w installed).

Your certainly not going to be able to do this in under 500k - youll need code to breakdown the pdf and send it to the printer in an acceptbale format, which is a lot of code to do something quite simlpe. Id recomend that you reconsider the adobe suite. Its reliable, popular, and you can almost rely on your clients as having it installed.

colr__
0
 
LVL 6

Author Comment

by:valipotor
ID: 16758943
Hi colr,

I need the posibility to control the print process. That is, after i have printed something, i have to mark the document as unmodifiable.
Using acrobat reader is no good, I must be able to determine if the user has printed the document or not.

And here are some other issues:

See the article at
http://princeoflightning.blogspot.com/2005/12/silent-print-pdf-print-pdf.html

One such product capable of doing that is the free Adobe Acrobat Reader. This well-known product does have it's limitations however. Command line options to print the PDF are undocumented / unsupported by Adobe. The Acrobat Reader process is known to start, print and continue running even after a silent print via command line; a bug that's not yet fixed by Adobe. Which means - you should expect to see a blank Acrobat Reader window after the "silent print". There are "beat around the bush" methods to attain certain amount of success using the commandline options - not for those who want "da perfect solution".
Inter Application Communication (IAC PDF reference file available at link) with the free Acrobat Reader cannot be done via OLE automation give the fact that Acrobat Reader is not a OLE server; you can get some luck only with Acrobat Standard or Pro. Only DDE messages can help a programmer write an application to achieve this. DDE will have restrictions that are not faced by an OLE Server. [If you don't know the difference then you musn't be doing this anyway].

Best regards,
valipotor
0
 
LVL 8

Expert Comment

by:colr__
ID: 16758968
Is it not enough to assume that if the print button is pressed that the print will have occured? I take it you want to know for sure that the document has been printed, in that the button has been pressed and the paper has actually been ejected from the printer?

Would it be possible to simplify the process and ask the user if the print was succesfull?

An interesting problem...

colr__
0
 
LVL 12

Accepted Solution

by:
Giant2 earned 400 total points
ID: 16759056
Agree with colr_,
you cannot ask the printer if the print job is finished and paper was printed correctly. It cannot answer for it.
0
 
LVL 6

Author Comment

by:valipotor
ID: 16759119
Giant2:
Nope, i don't want that. I want to be able to see if the button was pressed (and the confirmation dialog button, and so on ...), or if I use an external program such as Adobe then this is not possible.

That's why I wanted to try a silent print ... to be able to determine if the print has at least started.

colr_:
>>Would it be possible to simplify the process and ask the user if the print was succesfull?

This would mean to change the specs, this will be the last solution, if nothing else works.

valipotor
0
 
LVL 8

Assisted Solution

by:colr__
colr__ earned 800 total points
ID: 16759152
Im afraid that might be your only option. As soon as you press the print button, your java code will send the print command to the OS/print driver. At this point the print dialogue (or not, if using a silent print) would appear and you would lose control from your java program (the print dialoge (or silent) is launched in a completely seperate process).

Sorry, but there isnt any way of doing this w/o having some code that could directly interfae with the print process (this would typicallty invlove JNI, which is bad news as your code wouldnt be cross-platform compatible and would need some low-leeval coding, typically c/c++).

Sorry, but hope we helped!

colr__
0
 
LVL 6

Author Comment

by:valipotor
ID: 16851064
Hi guys,

I haven't found anything that could solve my problem, so i decided to change the specs. I am now downloading the file to the local computer, and then , using JDIC I will launch the default viewer for the .pdf file.
The user will have to specify that the file was printed.

0
 
LVL 8

Expert Comment

by:colr__
ID: 16851088
yeh, I think thats the best (only!) solution.

colr__
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month21 days, 3 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question