Click here to Skip to main content
15,077,377 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I am making a Java project that takes a docx file as an input and generates its image and then save it as a PDF file.
i.e. .docx -> .JPG -> .PDF

While coding the first part i.e .docx -> .jpg , here is my code but I am specifying the path of my document, but I want to ask how to make it possible so that the user can specify the document path.
here is my code

import com.aspose.words.Document;
import com.aspose.words.ImageSaveOptions;
import com.aspose.words.SaveFormat;

public class Program {

    public static void main(String args[]) throws Exception {

        new Program().generateImages("E:\\pro2\\Document.docx"); // here i am specifying the path of the document file within code itself

    public void generateImages(final String sourcePath) {
        try {
            Document doc = new Document(sourcePath);
            ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);

            for (int i = 0; i < doc.getPageCount(); i++) {
                String imageFilePath = sourcePath + "_outputimg_" + i + ".jpg";
      , options);
        } catch (Exception e) {

Please tell me how to make GUI where user can select location of the .docx file.
Updated 24-Jul-15 23:09pm

1 solution

Member 11834242 25-Jul-15 5:16am
can u suggest me the changes i need to make in my code.

in my code i have specified the locatio by "new Program().generateImages("E:\\pro2\\Document.docx");"
but while making an application, i am not allowed to define the path earlier , so what changes are required?
Richard MacCutchan 25-Jul-15 5:48am
I gave you the suggestions above. Go and read the documentation for the FileDialog class and use that to allow the user to select the file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900