• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Covert Excel Worksheet to PDF

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys,

I would like to know of an API (preferably OpenSource) which would convert my excel worksheets as it is to a pdf file. My Excel document has around 600 worksheets and the API has to generate a pdf for each one of those sheets. Any idea which API to use if any is available. I would not go for OpenOffice. Anything else?
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried the JExcel API, but it does not provide any option to convert the excel worksheet to a PDF??
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How would it look like if I decide to use OpenOffice?
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm...
My two cents:
Use Apache POI http://poi.apache.org/ To read from the excel files.
Use iText http://www.lowagie.com/iText/ to generate PDF files.

Not sure if you can achieve it with a much simpler approach!
HTH
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JODConverter library makes it easy to use OpenOffice in server mode to convert between document formats.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But I looked at the SourceForge website for JODConverter and the downloadables look like a web application.

http://sourceforge.net/projects/jodconverter/files/
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok i downloaded the zip file.

Referring to the example here on this link http://www.artofsolving.com/node/16 do I need to have OpenOffice installed? How can I ensure that the OpenOffice application that I have installed runs on port 8100? I did not quite understand this...
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have multiple worksheets in my excel and I would like to create a pdf for each one of them with the name of the worksheet being the name of the pdf. Is this achievable with the JODConverter?
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I installed OpenOffice and I would like to know how can I make it listen on port 8100 as the JODConverter requires that OpenOffice listens onn Port 8100?
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the README inside the ZIP file:

soffice -headless -accept="socket,port=8100;urp;"

 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The below is what I'm trying and not able to get the connection with OpenOffice. I have installed OpenOffice 3. Where did I go wrong? Getting null for the connection instance...

 
Rob Spoor
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You only initialize your static connection when you create an instance, which you never do.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fine, I corrected my mistake. I tried running it and it gave me the output pdf. But what I want to have is to have separate pdf's for each of the worksheets inside. Literally, I would like to iterate through the worksheets in the given excel file, use the name of the worksheet to print the pdf. In the end I would be having as many pdf's as the number of worksheets. How could I now acheive this?
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob, your help was really appreciated, but can you help me furthur?
 
Rob Spoor
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not really, sorry. I haven't worked with Open Office yet. Perhaps someone else has. If so you will surely get an answer.

Also, patience is a virtue.
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure how customizable your current solution is. Why not try the POI + iText combo ? Your final solution will be flexible. Is time a constrain ? How many times will this tool be invoked ? Will it need to be very flexible ?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the user guide: "HTML can be used as an output format but while all other formats always generate a single output file, HTML can produce multiple files.", so you may be out of luck. You might check out the source code to see how hard it would be to add this functionality.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deepak Bala wrote:I am not sure how customizable your current solution is. Why not try the POI + iText combo ? Your final solution will be flexible. Is time a constrain ? How many times will this tool be invoked ? Will it need to be very flexible ?



Well, this would be invoked just once a month or so. But it very much required that a single pdf be generated for each such worksheets inside the excel workbook. I think with POI, I can get the individual worksheets. Am I right here? But how do I manipulate the Sheet object using iText? Is there a straightforward solution already available? Any suggestions?
 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jothi Shankar Kumar wrote:

Deepak Bala wrote:I am not sure how customizable your current solution is. Why not try the POI + iText combo ? Your final solution will be flexible. Is time a constrain ? How many times will this tool be invoked ? Will it need to be very flexible ?



Well, this would be invoked just once a month or so. But it very much required that a single pdf be generated for each such worksheets inside the excel workbook. I think with POI, I can get the individual worksheets. Am I right here? But how do I manipulate the Sheet object using iText? Is there a straightforward solution already available? Any suggestions?



If you take this route you will indeed be able to do what you want to. However you will have to code using both POI and iText specific methods, which may take some learning to get by. I have used iText before but I cannot remember what the Sheet object is. Heck I cant even remember some of the basic classes used in the API. You will have to consult the iText book and online forums
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
iText has no provisions for working with POI objects. You'd have to code that yourself.

If this was my problem I'd start by looking into the OO Java API - the "accessing file formats" FAQ page links to an article that shows how to access spreadsheets through it. If that didn't work out I'd look into adapting JODConverter. The last approach would be to code it myself using POI and iText.
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think JasperReports do have a way for fetching data from excel sheets. Yes i am very much sure. iText is just a rendering tool used for designing the report.
 
Rob Spoor
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the PDF contains one page per worksheet, perhaps you can split the PDF file - one page in the original becomes a complete new PDF file.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:If the PDF contains one page per worksheet, perhaps you can split the PDF file - one page in the original becomes a complete new PDF file.



Nope...sometimes one sheet or one workbook in an excel document could span multiple pdf pages.
 
Rob Spoor
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can perhaps try to use Apache POI or JExcelAPI (I prefer the latter) to convert your Excel file into multiple HTML files; simply use <table> elements. Then convert those each to a single PDF file:
Of course this will not include the more advanced features like graphs and images but it's a start.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I'm already doing something of that sort what you had mentioned and as Ulf has mentioned in the above post.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And thanks Rob once again for the help!
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Once I succeed, I would post the entire source code here for corrections / reference...
 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jothi Shankar Kumar wrote:Once I succeed, I would post the entire source code here for corrections / reference...



Think twice if that would be a wise idea, in case the code is to be copyrighted or something like that.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since this thread is long enough I started a new thread which continues with the furthur discussions on this topic and it is here https://coderanch.com/t/465633/Java-General/java/Converting-Excel-Workbook-PDF#2080981

Moderators kindly lock this thread please!
 
Rob Spoor
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This thread is nowhere near "too long". As Campbell already suggested in your other thread one thread is enough. If the number of posts exceeds a certain number we simply will get a second page.

About your questions in that thread:
1) set the border attribute of the table to 1.
2) I have no idea to be honest.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob. I'm just considering some other options to get this done. Would keep posting my questions ans solutions here as and when I find them.
 
Rob Spoor
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since it's all the same issue, converting Excel into PDF, that's not a problem. Only create a new thread for a new topic, when it no longer has anything to do with this conversion issue.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the complete working code for the Excel to PDF conversion can be found at the following post (Scroll to the end for the final working code)

https://coderanch.com/t/465904/Other-Open-Source-Projects/Strange-error-with-Apache-POI#2084060
 
This. Exactly this. This is what my therapist has been talking about. And now with a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic