I found a very strange phenomenon.when I download this attachment file but not open it with office software. when i run in below code,it will convert to two page.but when i open it with office software it will convert to one page.
the original size is10.4kb ,but when i open it with office software it will be 14.9kb
so you should run this code by not open it.I will supply you with the all fonts ,you shoul setup these fonts.
package aspose.words;
import com.aspose.words.Document;
import com.aspose.words.Field;
import com.aspose.words.FieldHyperlink;
import com.aspose.words.FieldType;
import com.aspose.words.License;
public class MainTest {
private final static String MyDir = "C:\\Users\\Lixp\\DeskTop\\";
@SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception {
License license=new License();
license.setLicense(MyDir+"Aspose.Total.Java.lic");
Document wordDocument = new Document(MyDir + "oneppagetotwopage.docx");
wordDocument.acceptAllRevisions();
com.aspose.words.ImageSaveOptions imgSaveOptions = new com.aspose.words.ImageSaveOptions(
com.aspose.words.SaveFormat.JPEG);
imgSaveOptions.setPrettyFormat(true);
imgSaveOptions.setUseHighQualityRendering(false);
com.aspose.words.HtmlFixedSaveOptions htmlFixedSaveOptions = new com.aspose.words.HtmlFixedSaveOptions();
htmlFixedSaveOptions.setPrettyFormat(true);
htmlFixedSaveOptions.setExportEmbeddedCss(true);
htmlFixedSaveOptions.setExportEmbeddedFonts(true);
htmlFixedSaveOptions.setExportEmbeddedImages(true);
htmlFixedSaveOptions.setExportEmbeddedSvg(true);
htmlFixedSaveOptions.setWarningCallback(new com.aspose.words.IWarningCallback() {
@Override
public void warning(com.aspose.words.WarningInfo warningInfo) {
System.out.println(warningInfo.getDescription());
}
});
for (Field field : wordDocument.getRange().getFields()) {
if (field.getType() == FieldType.FIELD_HYPERLINK) {
FieldHyperlink hyperlink = (FieldHyperlink) field;
hyperlink.setTarget("_blank");
}
}
htmlFixedSaveOptions.setPageIndex(0);
htmlFixedSaveOptions.setPageCount(1);
wordDocument.save(MyDir + "Out.html", htmlFixedSaveOptions);
int pageCount = wordDocument.getPageCount();
for (int i = 0; i < pageCount; i++) {
if (i == 0) {
imgSaveOptions.setPageIndex(0);
imgSaveOptions.setPageCount(1);
wordDocument.save(MyDir + "Out0.html", imgSaveOptions);
}
htmlFixedSaveOptions.setPageIndex(i);
htmlFixedSaveOptions.setPageCount(1);
wordDocument.save(MyDir + "Out\\Out" + (i + 1) + "-svg.html", htmlFixedSaveOptions);
imgSaveOptions.setPageIndex(i);
imgSaveOptions.setPageCount(1);
}
}
}