Pure Java Print PDF Open Source API
November 3, 2008 69 Comments
PDF became widely used file format to exchange documents. There are a quite a few open source API available to create PDF document from Java application. Almost there is no good open source API available to view and print the PDF content from Java application. Fortunately sun released a open source API to fill this gap.
It is called “PDF Renderer” API. Since the name says renderer many of you might think that it may not be suitable for printing. But it is possible to print PDF document using this API. The code is fairly simple, you can download from the below link. You need JDK1.5 to run this code. You can enhance the code to set more printer configurations based on your need.
Resource: https://github.com/venkatsalem/print-pdf
Reference: https://pdf-renderer.dev.java.net/
Edited on June 21, 2010
Since PDF Renderer open source doesn’t meet all my requirement, Now I am using a commercial Java API called Aspose.Pdf.kit for Java to print the PDF document.
Hey this is a great resource venkat. I have been looking for something that will allow only restricted printing of a document from the web without making the pdf available to freely distribute.
Perfect for me. Thanks for documenting your findings!
Thanks for your post. Very useful. It saved us a lot of work.
Venkat,
Using the code to print a PDF file i’ve a problem in print service: During the job a message: java.nio.BufferUnderflowException occurs and the page was blank. I’m using Windows XP and a HP LaserJet 1010 printer. Do you know anything about this problem?
Thanks!
Wagner Pequeno
Sorry, I haven’t faced such issue. It could be specific to your printer settings.
Hi Venkat !
Thanks for distributing your experience.
Do you know how I can set the chars coding of PDF to “UTF-8” ? I have problems with some non-ascii characters.
Regards,
Balazs
Hi Venkat,
Thanks for the PrintPDF , we are looking to print PDF files from AS400 box, will be appericated if you have any sample code for AS400. Also, can we configure the printPDF to print other than default printer.
Thanks
Praveen
If you have JRE1.5 in your AS400 box the code will run.
Use the below method to set different printers.
/**
* Sets the printer service to be used for printing
*
* @param argPrintServiceName
* @throws PrinterException
*/
public void setPrintService(String argPrintServiceName) throws PrinterException {
PrintService[] printServices = PrinterJob.lookupPrintServices();
int i;
for (i = 0; i < printServices.length; i++) {
if (printServices[i].getName().equalsIgnoreCase(argPrintServiceName)) {
printerJob.setPrintService(printServices[i]);
break;
}
}
if (i == printServices.length) {
throw new PrinterException(“Invalid print service name: ” + argPrintServiceName);
}
}
Thanks for your post. It worked perfectly for me and saved me a lot of work.
Hi,
We used this API and seem to have worked for most of the stuff except it doesnt support multilingual PDF. Do you know a way to resolve it?
I don’t know. You can post your questions into java.net forum.
https://pdf-renderer.dev.java.net/servlets/ProjectMailingListList
Great find, I’m wondering how this can be adapted to print on a client side printer in a web application? I’m using JSF, and I’m at a loss as to how to proceed.
Do you mean from browser? You can do if you have applet code.
btw, the better solution is generate PDF in server side and display in the browser, user can click print button in the acrobat reader.
Thanks for the reply, I’m currently trying for a silent print function for my web application, so I’m avoiding streaming the pdf to the browser.
I’m reading the file from a location on a server thru the applet, but I’m getting an error: “This may not be a PDF File”
The only changes to the code I made were:
public PrintPdf(URL url)
{
try{
PrintPdf printPDFFile = new PrintPdf
(url.openStream(), “WEB PDF”);
printPDFFile.print();
}
catch(Exception e) {
e.printStackTrace();
}
}
instead of having the main in the class.
The file at the URL is a valid pdf. When line 74 in initialize is called,
PDFFile pdfFile = new PDFFile(bb);
the error occurs. I am unsure what’s causing the error as the error message is quite vague.
I know this might not be the place, but I’ve been doing a heap of looking on my own and came back here since the origin of this little snippet is you. I would really appreciate any ideas you might have. Thanks in advance.
Try converting URL content into ByteArrayInputStream and use it inside PrintPDF.
The below method might help you to convert:
public static InputStream getAsByteArray(URL url) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
InputStream inputStream = url.openStream();
int length = 0;
byte content[] = null;
do {
content = new byte[1024];
length = inputStream.read(content);
if (length > 0) {
outputStream.write(content, 0, length);
}
} while (length > 0);
return new ByteArrayInputStream(outputStream.toByteArray());
}
Hi there,
I have tried what you posted here and it works great. The print job size is a on the big side 1.1MB for a 3 page PDF document. Just wondering if you have any idea on how to reduce the job size?
cheers!
Also..I am getting some strange characters at the end of the lines characters which looks like this: l”
Any ideas how how to stop those characters from being printed?
cheers!
Hi Venkat,
Thanks for the printPDF. Am trying to print a pdf but am getting below exception.
Exception in thread “main” java.lang.SecurityException: class “com.sun.pdfview.PDFParseException”‘s signer information does not match signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(Unknown Source)
at java.lang.ClassLoader.preDefineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at com.oracle.printutilities.PrintPdf.initialize(PrintPdf.java:79)
at com.oracle.printutilities.PrintPdf.(PrintPdf.java:51)
at com.oracle.printutilities.PrintPdf.main(PrintPdf.java:35)
Hello Venkat,
Thanks for the code, but my PDF has some values in Fields that I can’t get to print, I mean, these fields are blank when I try to print.
Does PDF Renderer allow render fields values?
Thanks.
Lorenzo
Logongas, I have the same problem. I can’t print the euro symbol. It’s replaced by blank fields. Have you find a solution ?
Thanks
Hi dudu,
yes, using Foxit Reader.
Sorry.
Hi Venkat, im having some problems when i try to print pdf files, some of them print fine, but some i generate with Crystal Reports print only images, and strange characters where text should be, any ideas. Thanks in Advance.
Iqui.
Sorry, I don’t know.
Please post your question in PDF Renderer discussion forum.
https://pdf-renderer.dev.java.net/servlets/ProjectForumView
Hi Venkat, im having some problems when I try to print pdf files with pdf version 1.1 generated by Oracle Reports 6i. PDFRenderer does not recognize fonts used in pdf document. Adobe Reader runs well.
I have no idea about this problem. However I knew that this open source will not support on different version. You can try one of the prop root proprietary version.
Hi Venkat, I would like to download your example, PrintPdf.java, but it’s asking for username and password.
Dear Venkat,
Bar code not appear correctly. How to “install” these fonts ?
How to “install” other fonts ?
Hi Venkat,
Thnks a lot…
I am getting the following exception when i try to print the PDF doc
java.runtime exception : invalid character encountered.
Using PDF renderer is it possible to print PDF files which contain scanned images.. Please advice
Hi Venkat,
PDFRenderer works greatly but one very strange problem is there. It prints the pdf in very small size than the actual pdf size. My printed page is not same as in the original pdf.
Can you please give some hint ?
Thank you.
when i run printPdf.java on iseries ,i got null pinter exception at line
PrinterJob pjob = PrinterJob.getPrinterJob();
it seems that iseries cannot locate the default printer and create a job
does any one know the solution for this problem
thanks in advance
when i run printPdf.java on iseries ,i got null pinter exception at line
PrinterJob pjob = PrinterJob.getPrinterJob();
it seems that iseries cannot locate the default printer and create a job
does any one know the solution for this problem
thanks in advance
Hi Shymaa,
I have the same problem you having, basically calling
PrintService [] ps = PrinterJob.lookupPrintServices()
returns null, and hence the crash.
I wonder if Venkat or any other guru can shed some light on how to get working on the bloody AS/400 platform!
Daniel
Nothing seems to be working regarding printing PDF – even from Windows platform.
It depends on the PDF file size and contents, I get a series of Exceptions, like:
1- OutOfMemoryError if the document is more than 20 pages
2- NullPointerException if the documnet contains images
3- PDFParseException: Short stream in ASCIIHex decode
I tried it on a one page text only document, it printed the document without exception but with some distorted letters like all the “l”s , “i”s, “f”s and “r”s .
I don’t think it is there yet and lots need to be done. I posted a problem on their developer and issues mailing list, but it doesn’t look to be attended.
Will have to hunt again.. back to square one.
Daniel
i am facing a strange issue using PDF Renderer with respect to font setting, the all document which get’s printed using this, the text font style are geting changed to italic even thought its not, can any one help to solve this issue
Hi ,
i am wondering, if there is a way to print PDF files to one of available physical printers or an only printer while blocking the virtual printers to the list using java
I don’t know :-)
Great Post!
So does this work like printing to pdf? You select print and choose the pdf as your server or is this an automated feature?
Thanks,
Jason
Has anyone tried printing(or even rendering in a panel) a PDF file with a (image) signature? Mine keeps coming out with the color reversed:
-File has black signature against white background.
-Output is a white signature against a black box (the size of the signature image).
Any ideas? Thanks!
Hi All,
I could see many posts which says it WORKS (printing PDF through java) but its unfortunate am not able to connect to the site https://pdf-renderer.dev.java.net/ as it always shows TIMED OUT message.
Can anybody help me in getting the open source code from any other sites? Or it will be great if anybody can mail the jar file….
Any suggestions are much appreciated….waiting for reply
Thanks
Waiting for
Hi Venkat,
Could you please help me in getting the PDFRenderer source zip file?
i tried these 2 sites:
https://pdf-renderer.dev.java.net/
and
http://swinglabs.java.sun.com/downloads.jsp
but am not able to download the source files or even the binary files….
please help me in getting the src zip file as early as possible…since i need it very badly….
Thanks in Advance
Hi Venkat,
Thanks for sharing the jar file….but i do have a problem.
I copied the same PrintPdf.java that you have provided and i added the pdf.jar to my library and configured in PlugIn.xml file also.
am not able to clear the errors that is being shown in the the import statements that are present in the PrintPdf.java.
import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPage;
import com.sun.pdfview.PDFRenderer;
The files PDFFile.java, PDFPage.java and PDFRenderer.java are not visible.
Even the sub-packages that are present in the pdfview package like: action, colospace are visible but again the classess inside these sub-packages are also not visible, an not able to import those java files too.
am struck as to where is the problem…..please guide me in resolving these errors…..
looking forward for you reply at the earliest….
Thanks in Advance….
the pdf.jar contains java classes not .class files. Hope this info helps you.
Wow! thanks a lot venkat…..
That was really my bad…anyways thanks for the much needed help…
Great post!!!!!!!!!!
Thanks…
I can’t get it to print correctly. Whether my in my own program or in the example program, printing portrait stuff always shrinks the page and prints it in the top left corner (its like 45% the size.) Regardless of the PDF I print (datasheets or ones I created with PDFlatex or itext) results are the same. same results on linux and XP as well.
The code is exactly from the example program (the example program does the same thing as mentioned above.)
Any help would be appreciated.
Hii Venkat,
Thanks for sharing your work..I have taken your files and tried in Java 1.5 and PDF 6..
I m getting the following error:
com.sun.pdfview.PDFParseException: Expected ‘xref’ at start of table
at com.sun.pdfview.PDFFile.readTrailer(PDFFile.java:974)
at com.sun.pdfview.PDFFile.parseFile(PDFFile.java:1175)
at com.sun.pdfview.PDFFile.(PDFFile.java:126)
at com.sun.pdfview.PDFFile.(PDFFile.java:102)
Can u please help me in solving this issue?
Thanks in advance
Sorry guys, I have no clue about this error. Try posting the issue into https://pdf-renderer.dev.java.net/ if you don’t get response there my advice is look for commercial software.
I am planning to buy a commercial API for printing PDF because PDF spec and format will keep change expecting a open source to serve Adobe spec is not feasible.
Please download PDFRenderer.jar and use below code it will work for PDF Printing.
import java.awt.print.Book;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import javax.print.PrintException;
import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPrintPage;
public class PDFPrinter {
public static void main(String[] args){
try{
File f = new File(“C:\\CareLink\\WPS\\WID_naming_conventions.pdf”);
FileInputStream fis = new FileInputStream(f);
FileChannel fc = fis.getChannel();
ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
PDFFile pdfFile = new PDFFile(bb); // Create PDF Print Page
PDFPrintPage pages = new PDFPrintPage(pdfFile);
// Create Print Job
PrinterJob pjob = PrinterJob.getPrinterJob();
PageFormat pf = PrinterJob.getPrinterJob().defaultPage();
pjob.setJobName(f.getName());
Book book = new Book();
book.append(pages, pf, pdfFile.getNumPages());
pjob.setPageable(book);
// Send print job to default printer
pjob.print();
System.out.print(“done”);
}catch(PrinterException exe){
}catch(IOException e){
}
}
}
Problem is in the PDF rendering of PDF-renderer which is not complete, not the printing
I am trying to implement your solution as per your code.
when running your code, I get a “saveAs” dialog appearing for me to save a document of type .xps
I am presuming the image is created from reading the pdf file and before printing it wants me to rename this before printing is activated.
My Question is, where in your code can I automate this so that:
1) I do not have to physically name the new image file
2) It stores the new file directly in a certain directly which I can then delete after printing is finished.
I need this because my requirement is that I print a hundred of so pdfs at a time, so I need to automate this in my webserver.
Your assistance is greatly appreicated.
Thanks
I need to print PDF files on a local JES2 printer. DO you know if that is possible?
@mike smith: as coded, it uses the default printer, which in your case appears to be the “Microsoft XPS document writer” change your default printer and try it again.
I try to print a pdf file programatically and get Xref error also as did madhavi.. The website link I provided shows a patch.. but Its not working for me.. If someone uses the patch and gets it working please post how you got it to work..
https://pdf-renderer.dev.java.net/servlets/ProjectForumMessageView?forumID=2969&messageID=31058 OOOhhps here is the link.
While the code is very useful yet there is no way of knowing when the printer is offline, Paper ran out, printer not connected. How do we make them a part of this so that we can handle the exceptions. It seems that once we send the document it hands it over and doesn’t return the exception. The Printer Icon on system tray shows error to Cancel printing.
Any Ideas
It did not work when i tried it. Upon running my application, it asks me where to save the TIFF file. That’s weird. Please help me. Thanks!
HI….
as your code is too much useful to me but still I’m confused with a problem..
In this code u r using below line to select a default printer.
pjob = PrinterJob.getPrinterJob();
Instead I want to use any printer which is selected by me(using combo).
and to do that I’ve used setPrintService(PrintService[i]); method of PrinterJob class. But it gives me NullPointerException. So what could be the solution to this one???
pls reply its urgent…
Hi Venkat,
Great posting. Thank you very much.
I have integrated PDFRender API and your code, PrintPdf via the a servlet called PDFRendererServlet. I made a small change on the PrintPdf file to display the print dialog by the line pjob.printDialog() on the browser.
I am running tomcat (6.x) as the app server. I use eclipse ide installed on macbook pro. When I run the server and test locally it works fine (say, http://localhost:8080/pdfWeb/PDFRendererServlet).
While the server is running on the macbook, and test the print capability via a IE from the windows XP desktop computer (which is in network), I see the print dialog box on the macbook rather than on the windows XP desktop computer.
Appreciate if you could help me out what am I doing wrong or any other fix or code modifications needed.
Raghu
@Praveen: did you get it working on your AS400 ? I am trying to do sometinhg similar but unfortunately the call to PrinterJob.lookupPrintServices() is giving me an empty list. With IBM supplied classes I can get a list of 55 available printers. So why is the lookup empty?
Hi venkat,
I tried your code, but it is throwing exception, and the file is created with partial text.
I am posting the generated exception here.
com.sun.pdfview.PDFParseException: Encode required for function type 3!
at com.sun.pdfview.function.FunctionType3.parse(FunctionType3.java:139)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.pattern.ShaderType2.parse(ShaderType2.java:109)
at com.sun.pdfview.pattern.PDFShader.getShader(PDFShader.java:173)
at com.sun.pdfview.PDFParser.doShader(PDFParser.java:1151)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:640)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported function type 4.
at com.sun.pdfview.function.FunctionType4.parse(FunctionType4.java:828)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.colorspace.PDFColorSpace.getColorSpace(PDFColorSpace.java:175)
at com.sun.pdfview.PDFParser.parseColorSpace(PDFParser.java:1229)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:648)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported shader type: 3
at com.sun.pdfview.pattern.PDFShader.getShader(PDFShader.java:135)
at com.sun.pdfview.PDFParser.doShader(PDFParser.java:1151)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:640)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported shader type: 3
at com.sun.pdfview.pattern.PDFShader.getShader(PDFShader.java:135)
at com.sun.pdfview.PDFParser.doShader(PDFParser.java:1151)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:640)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported shader type: 3
at com.sun.pdfview.pattern.PDFShader.getShader(PDFShader.java:135)
at com.sun.pdfview.PDFParser.doShader(PDFParser.java:1151)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:640)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported function type 4.
at com.sun.pdfview.function.FunctionType4.parse(FunctionType4.java:828)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.colorspace.PDFColorSpace.getColorSpace(PDFColorSpace.java:175)
at com.sun.pdfview.PDFParser.parseColorSpace(PDFParser.java:1229)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:648)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported shader type: 3
at com.sun.pdfview.pattern.PDFShader.getShader(PDFShader.java:135)
at com.sun.pdfview.PDFParser.doShader(PDFParser.java:1151)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:640)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported shader type: 3
at com.sun.pdfview.pattern.PDFShader.getShader(PDFShader.java:135)
at com.sun.pdfview.PDFParser.doShader(PDFParser.java:1151)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:640)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported shader type: 3
at com.sun.pdfview.pattern.PDFShader.getShader(PDFShader.java:135)
at com.sun.pdfview.PDFParser.doShader(PDFParser.java:1151)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:640)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported function type 4.
at com.sun.pdfview.function.FunctionType4.parse(FunctionType4.java:828)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.colorspace.PDFColorSpace.getColorSpace(PDFColorSpace.java:175)
at com.sun.pdfview.PDFParser.parseColorSpace(PDFParser.java:1229)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:648)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
java.lang.IllegalArgumentException: Number of color/alpha components should be 4 but length of bits array is 1
at java.awt.image.ColorModel.(ColorModel.java:318)
at java.awt.image.ComponentColorModel.(ComponentColorModel.java:256)
at com.sun.pdfview.PDFImage$DecodeComponentColorModel.(PDFImage.java:564)
at com.sun.pdfview.PDFImage.getColorModel(PDFImage.java:529)
at com.sun.pdfview.PDFImage.parseData(PDFImage.java:270)
at com.sun.pdfview.PDFImage.getImage(PDFImage.java:225)
at com.sun.pdfview.PDFRenderer.drawImage(PDFRenderer.java:273)
at com.sun.pdfview.PDFImageCmd.execute(PDFPage.java:643)
at com.sun.pdfview.PDFRenderer.iterate(PDFRenderer.java:570)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at PDFPrintPage.print(NewClass.java:42)
at sun.print.RasterPrinterJob.printPage(RasterPrinterJob.java:1936)
at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1431)
at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1247)
at PrintPdf.print(PrintPdf.java:99)
at PrintPdf.main(PrintPdf.java:40)
java.lang.IllegalArgumentException: Number of color/alpha components should be 4 but length of bits array is 1
at java.awt.image.ColorModel.(ColorModel.java:318)
at java.awt.image.ComponentColorModel.(ComponentColorModel.java:256)
at com.sun.pdfview.PDFImage$DecodeComponentColorModel.(PDFImage.java:564)
at com.sun.pdfview.PDFImage.getColorModel(PDFImage.java:529)
at com.sun.pdfview.PDFImage.parseData(PDFImage.java:270)
at com.sun.pdfview.PDFImage.getImage(PDFImage.java:225)
at com.sun.pdfview.PDFRenderer.drawImage(PDFRenderer.java:273)
at com.sun.pdfview.PDFImageCmd.execute(PDFPage.java:643)
at com.sun.pdfview.PDFRenderer.iterate(PDFRenderer.java:570)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at PDFPrintPage.print(NewClass.java:42)
at sun.print.RasterPrinterJob.printPage(RasterPrinterJob.java:1964)
at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1431)
at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1247)
at PrintPdf.print(PrintPdf.java:99)
at PrintPdf.main(PrintPdf.java:40)
com.sun.pdfview.PDFParseException: Unsupported function type 4.
at com.sun.pdfview.function.FunctionType4.parse(FunctionType4.java:828)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.colorspace.PDFColorSpace.getColorSpace(PDFColorSpace.java:175)
at com.sun.pdfview.PDFParser.parseColorSpace(PDFParser.java:1229)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:648)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported function type 4.
at com.sun.pdfview.function.FunctionType4.parse(FunctionType4.java:828)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.colorspace.PDFColorSpace.getColorSpace(PDFColorSpace.java:175)
at com.sun.pdfview.PDFParser.parseColorSpace(PDFParser.java:1229)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:648)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported function type 4.
at com.sun.pdfview.function.FunctionType4.parse(FunctionType4.java:828)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.colorspace.PDFColorSpace.getColorSpace(PDFColorSpace.java:175)
at com.sun.pdfview.PDFParser.parseColorSpace(PDFParser.java:1229)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:648)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported function type 4.
at com.sun.pdfview.function.FunctionType4.parse(FunctionType4.java:828)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.colorspace.PDFColorSpace.getColorSpace(PDFColorSpace.java:175)
at com.sun.pdfview.PDFParser.parseColorSpace(PDFParser.java:1229)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:648)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported function type 4.
at com.sun.pdfview.function.FunctionType4.parse(FunctionType4.java:828)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.colorspace.PDFColorSpace.getColorSpace(PDFColorSpace.java:175)
at com.sun.pdfview.PDFParser.parseColorSpace(PDFParser.java:1229)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:648)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported function type 4.
at com.sun.pdfview.function.FunctionType4.parse(FunctionType4.java:828)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.colorspace.PDFColorSpace.getColorSpace(PDFColorSpace.java:175)
at com.sun.pdfview.PDFParser.parseColorSpace(PDFParser.java:1229)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:648)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Encode required for function type 3!
at com.sun.pdfview.function.FunctionType3.parse(FunctionType3.java:139)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.pattern.ShaderType2.parse(ShaderType2.java:109)
at com.sun.pdfview.pattern.PDFShader.getShader(PDFShader.java:173)
at com.sun.pdfview.PDFParser.doShader(PDFParser.java:1151)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:640)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Encode required for function type 3!
at com.sun.pdfview.function.FunctionType3.parse(FunctionType3.java:139)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.pattern.ShaderType2.parse(ShaderType2.java:109)
at com.sun.pdfview.pattern.PDFShader.getShader(PDFShader.java:173)
at com.sun.pdfview.PDFParser.doShader(PDFParser.java:1151)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:640)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported function type 4.
at com.sun.pdfview.function.FunctionType4.parse(FunctionType4.java:828)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.colorspace.PDFColorSpace.getColorSpace(PDFColorSpace.java:175)
at com.sun.pdfview.PDFParser.parseColorSpace(PDFParser.java:1229)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:648)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported function type 4.
at com.sun.pdfview.function.FunctionType4.parse(FunctionType4.java:828)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.colorspace.PDFColorSpace.getColorSpace(PDFColorSpace.java:175)
at com.sun.pdfview.PDFParser.parseColorSpace(PDFParser.java:1229)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:648)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported function type 4.
at com.sun.pdfview.function.FunctionType4.parse(FunctionType4.java:828)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.colorspace.PDFColorSpace.getColorSpace(PDFColorSpace.java:175)
at com.sun.pdfview.PDFParser.parseColorSpace(PDFParser.java:1229)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:648)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported function type 4.
at com.sun.pdfview.function.FunctionType4.parse(FunctionType4.java:828)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.colorspace.PDFColorSpace.getColorSpace(PDFColorSpace.java:175)
at com.sun.pdfview.PDFParser.parseColorSpace(PDFParser.java:1229)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:648)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported function type 4.
at com.sun.pdfview.function.FunctionType4.parse(FunctionType4.java:828)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.colorspace.PDFColorSpace.getColorSpace(PDFColorSpace.java:175)
at com.sun.pdfview.PDFParser.parseColorSpace(PDFParser.java:1229)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:648)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported function type 4.
at com.sun.pdfview.function.FunctionType4.parse(FunctionType4.java:828)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.colorspace.PDFColorSpace.getColorSpace(PDFColorSpace.java:175)
at com.sun.pdfview.PDFParser.parseColorSpace(PDFParser.java:1229)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:648)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported function type 4.
at com.sun.pdfview.function.FunctionType4.parse(FunctionType4.java:828)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.colorspace.PDFColorSpace.getColorSpace(PDFColorSpace.java:175)
at com.sun.pdfview.PDFParser.parseColorSpace(PDFParser.java:1229)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:648)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Unsupported function type 4.
at com.sun.pdfview.function.FunctionType4.parse(FunctionType4.java:828)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.colorspace.PDFColorSpace.getColorSpace(PDFColorSpace.java:175)
at com.sun.pdfview.PDFParser.parseColorSpace(PDFParser.java:1229)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:648)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
com.sun.pdfview.PDFParseException: Encode required for function type 3!
at com.sun.pdfview.function.FunctionType3.parse(FunctionType3.java:139)
at com.sun.pdfview.function.PDFFunction.getFunction(PDFFunction.java:168)
at com.sun.pdfview.pattern.ShaderType2.parse(ShaderType2.java:109)
at com.sun.pdfview.pattern.PDFShader.getShader(PDFShader.java:173)
at com.sun.pdfview.PDFParser.doShader(PDFParser.java:1151)
at com.sun.pdfview.PDFParser.iterate(PDFParser.java:640)
at com.sun.pdfview.BaseWatchable.run(BaseWatchable.java:101)
at java.lang.Thread.run(Thread.java:662)
Thanks,
Sanjeevi
I could not find the pdfrenderer.jar file on the java.net website..Can u pls sent it to me
Hi venkat,
I have put the jar file into lib folder and tried to compile the prindpdf.java file and it throws the error as follows:
PrintPdf.java:15: package com.sun.pdfview does not exist
import com.sun.pdfview.PDFFile;
^
PrintPdf.java:16: package com.sun.pdfview does not exist
import com.sun.pdfview.PDFPage;
^
PrintPdf.java:17: package com.sun.pdfview does not exist
import com.sun.pdfview.PDFRenderer;
^
PrintPdf.java:102: cannot find symbol
symbol : class PDFFile
location: class PDFPrintPage
private PDFFile file;
^
PrintPdf.java:104: cannot find symbol
symbol : class PDFFile
location: class PDFPrintPage
PDFPrintPage(PDFFile file) {
^
PrintPdf.java:74: cannot find symbol
symbol : class PDFFile
location: class PrintPdf
PDFFile pdfFile = new PDFFile(bb);
^
PrintPdf.java:74: cannot find symbol
symbol : class PDFFile
location: class PrintPdf
PDFFile pdfFile = new PDFFile(bb);
^
PrintPdf.java:112: cannot find symbol
symbol : class PDFPage
location: class PDFPrintPage
PDFPage page = file.getPage(pagenum);
^
PrintPdf.java:118: cannot find symbol
symbol : class PDFRenderer
location: class PDFPrintPage
PDFRenderer pgs = new PDFRenderer(page, g2, imageArea, n
ull, null);
^
PrintPdf.java:118: cannot find symbol
symbol : class PDFRenderer
location: class PDFPrintPage
PDFRenderer pgs = new PDFRenderer(page, g2, imageArea, n
ull, null);
^
10 errors
Please suggest me to resolve this.
Thanks in Advance.
Marvelous, TQVM
its fantastic thank you a lot
It is really very good post! It helps a lot…! Thanks dude!
Thank you a lot. It helped me to find a solution to my problem.
com.sun.pdfview.PDFParseException: Expected ‘xref’ at start of table
at com.sun.pdfview.PDFFile.readTrailer(PDFFile.java:974)
at com.sun.pdfview.PDFFile.parseFile(PDFFile.java:1175)
at com.sun.pdfview.PDFFile.(PDFFile.java:126)
at com.sun.pdfview.PDFFile.(PDFFile.java:102)
at com.ddj.common.PDFToImg.changePdfToImg(PDFToImg.java:58)
at com.ddj.common.PDFToImg.main(PDFToImg.java:31)
Can you help me to solve this problem?
This open source is no longer active. Use one of the commercial api like aspose pdf kit
Hi Venkat
i am trying to use that api it’s working perfectly on the local server once i try to deploy to a managed server and test i got nothing even on the server log
my requirement is to print a documet into client side using his default printer
thank you in advance