将 Excel 图像重新采样为 PDF 转换
Contents
[
Hide
]
在处理包含大量图像的大 Microsoft Excel 文件时,您可能需要压缩已添加的图像以减小输出 PDF 文件大小并提高整体转换性能。 Aspose.Cells 支持重新采样添加的图像以减少输出 PDF 文件大小并提高性能。
将 Excel 图像重新采样为 PDF 转换
请参阅以下示例代码,它描述了如何使用 Aspose.Cells API 执行任务。该示例将 Microsoft Excel 文件转换为 PDF 文件,同时压缩文件中的图像。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ResampleImagesforExceltoPDFConversion.class); | |
// Initialize a new Workbook | |
// Open an Excel file | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
// Instantiate the PdfSaveOptions | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
// Set Image Resample properties | |
pdfSaveOptions.setImageResample(300, 70); | |
// Save the PDF file | |
workbook.save(dataDir + "output.pdf", pdfSaveOptions); |
使用PdfSaveOptions.setImageResample 选项最小化输出 PDF 的大小,但它可能会稍微影响图像质量。
如果您的电子表格包含公式,最好调用[工作簿.calculateFormula()](https://reference.aspose.com/cells/java/com.aspose.cells/workbook#calculateFormula()就在将电子表格呈现为 PDF 格式之前。这样做将确保重新计算公式相关值,并在 PDF 中呈现正确的值。