Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active April 21, 2021 12:23
Show Gist options
  • Save aspose-com-gists/bae36f809fa8c521dc664e0269b29624 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/bae36f809fa8c521dc664e0269b29624 to your computer and use it in GitHub Desktop.
Word用Java转换为PDF
// 从磁盘加载Word文档
Document doc = new Document("word.docx");
//另存为PDF
doc.save("output.pdf");
// 从磁盘加载Word文档
Document doc = new Document("word.docx");
// 设定Jpeg品质
PdfSaveOptions options = new PdfSaveOptions();
options.setJpegQuality(100);
// 将Word转换为PDF
doc.save("output.pdf", options);
// 从磁盘加载Word文档
Document doc = new Document("word.docx");
PdfSaveOptions options = new PdfSaveOptions();
// 文字和图像压缩
options.setTextCompression(PdfTextCompression.FLATE);
options.setImageCompression(PdfImageCompression.AUTO);
// 将Word另存为PDF
doc.save("output.pdf", options);
// 从磁盘加载Word文档
Document doc = new Document("word.docx");
// 将PDFSaveOption符合性设置为PDF15
PdfSaveOptions options = new PdfSaveOptions();
options.setCompliance(PdfCompliance.PDF_15);
// 将Word转换为PDF
doc.save("output.pdf", options);
// 从磁盘加载Word文档
Document doc = new Document("word.docx");
PdfSaveOptions options = new PdfSaveOptions();
// 从索引1开始转换3页,其中0是第一页的索引
options.setPageIndex(1);
options.setPageCount(3);
// 将Word另存为PDF
doc.save("output.pdf", options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment