please check! Use Aspose.PDF complete guide to Word in Java PDF file will be

PDF is one of the most popular formats to send a document to a third party. The reason for this popular platform compatibility across multiple PDF, regardless of any hardware / software requirements. However, in some cases, you may want to convert PDF documents into editable document format.

In this case, PDF to Word DOC or DOCX conversion options may be the priority. To make the conversion process automation, this article will show you how to programmatically convert PDF to Word in Java. If you have not upgraded Aspose.PDF latest version of the test, you can click here to download.

In this article, we will use the following Aspose.PDF PDF to DOC / DOCX conversion in Java:

使用Java将PDF转换为DOC
使用Java将PDF转换为DOCX
使用其他选项将PDF转换为Word(DOC / DOCX)

New year special offer! Use Aspose.PDF to Word complete guide in PDF files will be Java
① use Java convert PDF to DOC

After the Java Aspose.PDF cited in the application, by a few lines of code to convert any PDF documents into DOC format. The following steps are required to perform this conversion.

创建Document类的实例,并使用输入的PDF文件的路径对其进行初始化
使用输出DOC文件的名称和SaveFormat.Doc参数调用Document.save()方法

The following sample code shows how to convert the Java DOC in the PDF.

// Load source PDF file
Document doc = new Document(“input.pdf”);

// Save resultant DOC file
doc.save(“output.doc”, SaveFormat.Doc);

PDF input file

New year special offer! Use Aspose.PDF complete guide to Word in Java PDF file will be

The converted Excel documents

New year special offer! Use Aspose.PDF to Word complete guide in PDF files will be Java
② use Java convert PDF to DOCX

DOCX is a well-known format a Word document, as opposed to DOC format, based on the binary structure of DOCX files and XML files. SaveFormat.DocX ​​parameters if you want to convert PDF to DOCX format, you can use Document.save () method tells API to do so.

The following code example shows how to convert DOCX in Java in the PDF.

// Load source PDF file
Document doc = new Document(“input.pdf”);

// Save resultant DOCX file
doc.save(“output.docx”, SaveFormat.DocX);

③PDF other options to Word conversion

Aspose.PDF for Java also provides a number of other options, you can use these options in the PDF to Word conversion, such as the output format, image resolution, such as the distance between lines of text. DocSaveOptions class for this purpose, the following is a list of options you can use:

setFormat(int value) –设置输出格式(Doc,Docx等)。
setAddReturnToLineEnd(boolean value) –添加段落或换行符。
setImageResolutionX(int value) –设置图像的X分辨率。
setImageResolutionY(int value) –设置图像的Y分辨率。
setMaxDistanceBetweenTextLines(float value) –将文本行分组为段落。
setMode(int value) –设置识别模式。
setRecognizeBullets(boolean value) –打开项目符号的识别。
setRelativeHorizontalProximity(float value) –设置输入PDF文件中不同文本元素之间的间距。

The following code example demonstrates how to use Java to convert the PDF DocSaveOptions class DOCX.

// Load source PDF file
Document doc = new Document(“input.pdf”);

// Instantiate DocSaveOptions instance
DocSaveOptions saveOptions = new DocSaveOptions();

// Set output format
saveOptions.setFormat(DocSaveOptions.DocFormat.DocX);

// Set the recognition mode as Flow
saveOptions.setMode(DocSaveOptions.RecognitionMode.Flow);

// Set the horizontal proximity as 2.5
saveOptions.setRelativeHorizontalProximity(2.5f);

// Enable bullets recognition during conversion process
saveOptions.setRecognizeBullets(true);

// Save resultant DOCX file
doc.save(“resultant.docx”, saveOptions);

Published 133 original articles · won praise 12 · views 40000 +

Guess you like

Origin blog.csdn.net/mnrssj/article/details/104049694