Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9215295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:10:22+00:00 2026-06-18T02:10:22+00:00

I’m working on a Java applet that produces an XLS file as output. I

  • 0

I’m working on a Java applet that produces an XLS file as output. I need to convert it to PDF (or even better PDF/A) before I let the user view, download and print the document, since I need it unmodifyable.

I tried coding a solution, and it works. I downloaded and bundled JODConverter 2 in my applet so that the output XLS becomes JODConverter input file and it all works ok. The problem is the size of this component: almost 2mb. Since my applet is already 3mb I don’t want to bundle JODConverter in it too…

I read in the docs that it can work as a webservice too: I create a POST request, send it to the service and get the file, all without downloading a single kb of JODConverter. It sounds great, but I can’t get it working.

Below is the code I wrote:

public class Main
{
    public static void main(String[] args) throws Exception
    {
        doPost(new URL("http://localhost:8090/pdfconverter/service"), "C:\\Documents and Settings\\Administrator\\Desktop\\Gestione oneri\\calcolo oneri XP.xls");
    }


    private static void doPost(URL url, String binaryFile)
    {
        try
        {
            File binFile = new File(binaryFile);
            URLConnection conn = url.openConnection();
            conn.addRequestProperty("Content-Type", "multipart/form-datastrong text");
            conn.addRequestProperty("Accept", "application/pdf");
            conn.setDoOutput(true);
            DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
            FileInputStream input = new FileInputStream(binFile);
            byte[] buffer = new byte[1024];
            for(int length = 0; (length = input.read(buffer)) > 0;)
            {
                wr.write(buffer, 0, length);
            }
            wr.flush(); // Important! Output cannot be closed. Close of writer will close output as well.
            // Get the response and write it to a file.
            File file = new File("C:\\Documents and Settings\\Administrator\\Desktop\\Gestione oneri\\calcolo oneri XP2.pdf");
            FileOutputStream wrFile = new FileOutputStream(file);
            DataInputStream dataInput = new DataInputStream(conn.getInputStream());
            buffer = new byte[1024];
            for(int length = 0; (length = dataInput.read(buffer)) > 0;)
            {
                wrFile.write(buffer, 0, length);
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}

I downloaded a WAR which included JODConverter web service out of the box and put it into my tomcat\webapps\pdfconverter, created the script to start OpenOffice service

soffice -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\" -nofirststartwizard

but here’s my stacktrace:

java.io.IOException: Server returned HTTP response code: 500 for URL: http://localhost:8090/pdfconverter/service
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at main.Main.doPost(Main.java:128)
at main.Main.main(Main.java:25)

where Main.java:128 is the line

DataInputStream dataInput = new DataInputStream(conn.getInputStream());

Tomcat logs show this:
Access log:

127.0.0.1 - - [30/Jan/2013:11:45:24 +0100] "POST /pdfconverter/service HTTP/1.1" 500 4426

[EDIT after changing content-type from text/plain to multipart/form-data]
Standard log:

Grave: Servlet.service() for servlet [DocumentConverterServiceServlet] in context with path [/pdfconverter] threw exception
java.lang.IllegalArgumentException: unsupported input mime-type: multipart/form-data
at com.artofsolving.jodconverter.web.DocumentConverterServiceServlet.doPost(DocumentConverterServiceServlet.java:69)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

I believe there’s something wrong in the POST, because an exception has occurred during conversion process, but I can’t seem to find the problem: the code posted is the last version of a various numbers of trials and errors, so maybe before this I went with the right code for the POST and messed up something else…
Any suggestion is appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:10:23+00:00Added an answer on June 18, 2026 at 2:10 am

    At first you were sending .xls file with Mime-Type as text/plain and you got exception which said that it’s unable to parse your document because of some error (probably your JODConverter 2 was trying to convert .xls file as .txt file).

    This was first exception. Now you are getting exception that multipart/form-data is unsuported. This Mime-Type never represent a document and if you want to change one doc in another one as .pdf you have to provide valid Mime-Type definition.

    For .xls files this valid Mime-Type is application/vnd.ms-excel. You can found other types here: mime-types for xls.

    This change should allow you to send your request to JODConverter

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.