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 8269731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:19:37+00:00 2026-06-08T06:19:37+00:00

I converted .docx file to .pdf file, the text is converting fine, but the

  • 0

I converted .docx file to .pdf file, the text is converting fine, but the images in the .docx file is not appearing, instead it is represented as some special characters, below is my code:

import com.lowagie.text.Document;    
import com.lowagie.text.Paragraph;    
import com.lowagie.text.pdf.PdfWriter;    
import java.io.File;    
import java.io.FileOutputStream;    
public class PDFConversion {

    /**
     * 14. This method is used to convert the given file to a PDF format 15.
     * 
     * @param inputFile
     *            - Name and the path of the file 16.
     * @param outputFile
     *            - Name and the path where the PDF file to be saved 17.
     * @param isPictureFile
     *            18.
     */

    private void createPdf(String inputFile, String outputFile, boolean isPictureFile) {
        /**
         * 22. Create a new instance for Document class 23.
         */
        Document pdfDocument = new Document();
        String pdfFilePath = outputFile;

        try {
            FileOutputStream fileOutputStream = new FileOutputStream(pdfFilePath);
            PdfWriter writer = null;
            writer = PdfWriter.getInstance(pdfDocument, fileOutputStream);
            writer.open();
            pdfDocument.open();

            /**
             * 34. Proceed if the file given is a picture file 35.
             */
            if (isPictureFile) {
                pdfDocument.add(com.lowagie.text.Image.getInstance(inputFile));
            }

            /**
             * 41. Proceed if the file given is (.txt,.html,.doc etc) 42.
             */

            else {
                File file = new File(inputFile);
                pdfDocument.add(new Paragraph(org.apache.commons.io.FileUtils
                        .readFileToString(file)));      
            }
            pdfDocument.close();
            writer.close();
        } catch (Exception exception) {
            System.out.println("Document Exception!" + exception);
        }
    }

    public static void main(String args[]) {
        PDFConversion pdfConversion = new PDFConversion();
        pdfConversion.createPdf("C:/Users/LENOVO/Downloads/The_JFileChooser_Component.doc",
                "E:/The_JFileChooser_Component.pdf", false);
        // For other files
        // pdfConversion.createPdf("C:/shunmuga/sample.html",
        // "C:/shunmuga/sample.pdf", false);
    }
}
  • 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-08T06:19:39+00:00Added an answer on June 8, 2026 at 6:19 am

    I’m not sure what it could be, but for some alternatives have a look at:

    • Apose.Words Library for Java it has some really cool features one of them being docx to pdf conversion by a few simple lines (and it’s reliable):

      Document doc = new Document("d:/test/mydoc.docx");
      doc.Save("d:/test/Out.pdf", SaveFormat.Pdf);
      
    • Docx4j
      which can be used to convert docx and many others to PDF, it does this by first using HTML/XML based on IText then converts it to a PDF (All libararies are included within docx4j, just added the itext link for completeness):

      org.docx4j.convert.out.pdf.PdfConversion c
       = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(wordMLPackage);//using xml
      // = new org.docx4j.convert.out.pdf.viaHTML.Conversion(wordMLPackage);//using html
      // = new org.docx4j.convert.out.pdf.viaIText.Conversion(wordMLPackage);//using itext libs
      

    If that’s not enough it has sample source code for you to try.

    • xdocreport also comes with a lot of samples for conversion (haven’t downloaded them, but it should have the doc/docx to PDF converter source)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I converted .docx word file (xml content) to text with this code (in C#):
I converted a war file into a zip file to do some customizations. Renaming
How can I convert HTML with images to Word Document(Doc not Docx) in WPF?
I understand iTextSharp can be used for converting a document to pdf. But first
I have been working on a document conversion feature for converting a docx file
I want to read a docx File in c#. the docx file when converted
The following works and will convert /tmp/file.docx to /tmp/file.pdf . libreoffice3.5. --headless --convert-to pdf
I am looking for an online file conversion site which converts DOCX, DOC, PPT,
Is there a command line tool that is able to search docx file under
I'm wondering how you can convert Word .doc/.docx files to text files through Java.

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.