如何将文档文件作为java中用户界面的输入 [英] how to take a document file as an input from the user interface in java
本文介绍了如何将文档文件作为java中用户界面的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我正在制作一个Java项目,它将docx文件作为输入并生成其图像,然后将其另存为PDF文件。
即.docx - > .JPG - > .PDF
编码第一部分,即.docx - > .jpg,这是我的代码但是我指定了我的文档的路径,但是我想问一下如何让它成为可能,以便用户可以指定文档路径。
这里是我的代码< br $> b $ b
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);
options.setJpegQuality(100);
options.setResolution(100);
for (int i = 0; i < doc.getPageCount(); i++) {
String imageFilePath = sourcePath + "_outputimg_" + i + ".jpg";
options.setPageIndex(i);
doc.save(imageFilePath, options);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
请告诉我如何在用户可以选择位置的地方制作GUI .docx文件。
Please tell me how to make GUI where user can select location of the .docx file.
推荐答案
参见 https://docs.oracle.com/javase/tutorial/uiswing/components/panel.html [ ^ ]和http://docs.oracle.com/javase/7/docs/api/java/awt/FileDialog.html [ ^ ]。谷歌在不到30秒的时间内发现了这两种情况。
See https://docs.oracle.com/javase/tutorial/uiswing/components/panel.html[^] and http://docs.oracle.com/javase/7/docs/api/java/awt/FileDialog.html[^]. Both found by Google in less than 30 seconds.
这篇关于如何将文档文件作为java中用户界面的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文