Word转pdf 图片丢失

SNT25070004_1(4).zip (2.4 MB)

word转pdf 这里第四页的第二张图片不见了


@kin58

Cause

The issue of missing images when converting a Word document to PDF can occur due to various reasons, such as unsupported image formats, incorrect image paths, or issues with the document’s structure.

Solution

To troubleshoot and resolve the issue of missing images in the PDF output, consider the following steps:

  1. Check Image Format: Ensure that the images used in the Word document are in a supported format (e.g., JPEG, PNG, BMP). Some formats may not be properly handled during conversion.

  2. Verify Image Paths: If the images are linked rather than embedded, ensure that the paths to the images are correct and accessible during the conversion process.

  3. Use PdfSaveOptions: When saving the document as a PDF, utilize the PdfSaveOptions class to specify any necessary settings that may affect image rendering. For example, you can set the EmbedFullFonts option to ensure that all fonts are included, which can sometimes affect how images are displayed.

  4. Update Aspose.Words: Ensure you are using the latest version of Aspose.Words, as updates often include bug fixes and improvements related to document conversion.

Code

Here’s a sample code snippet demonstrating how to convert a Word document to PDF while ensuring images are handled correctly:

Document doc = new Document("path/to/your/document.docx");
PdfSaveOptions options = new PdfSaveOptions();
options.setEmbedFullFonts(true); // Ensure all fonts are embedded
doc.save("path/to/output/document.pdf", options);

Next Steps

  1. Test the conversion with different image formats to see if the issue persists.
  2. If the problem continues, share the document with Aspose support for further assistance.
  3. Review the Aspose documentation for any specific settings related to image handling during PDF conversion.

If you follow these steps, you should be able to resolve the issue of missing images in your PDF output. Please let me know if you need further assistance!

代码是

LoadOptions optionss = new LoadOptions(); optionss.getLanguagePreferences().setDefaultEditingLanguage(EditingLanguage.CHINESE_PRC);
String wordPath=“D:\data\ces\SNT25070004_1(4).doc”;//原文件
String pdfPath=“D:\data\ces\SNT25070004_1(4).pdf”;//pdf
Document doc = new Document(wordPath,optionss);
FileOutputStream fileOS = new FileOutputStream(pdfPath);
doc.save(pdfPath);
fileOS.close();

String wordPath=“D:\data\ces\SNT25070004_1(4).doc”;//原文件
String pdfPath=“D:\data\ces\SNT25070004_1(4).pdf”;//pdf
Document doc = new Document(wordPath);
PdfSaveOptions options = new PdfSaveOptions();
options.setEmbedFullFonts(true); // Ensure all fonts are embedded

    FileOutputStream fileOS = new FileOutputStream(pdfPath);
    doc.save(pdfPath,options);
    fileOS.close();

这样问题依然存在

aspose.java 使用的25.5

@kin58 感谢您报告此问题。 我们已经在我们的内部问题跟踪系统中打开了以下新工单,并将根据 免费支持政策 中提到的条款提供它们的修复:

Issue ID(s): WORDSNET-28422

如果您需要优先支持以及直接联系我们的付费支持管理团队,您可以获得 付费支持服务

这是因为当前版本 还没有优化这块吗?

@kin58 文件的版本较旧,看起来是兼容性问题。 如果我在 MS Word 2019 中重新保存该文档,问题就不会再出现。

MS Word 2019 重新保存 是怎么操作呢

String wordPath = “D:\data\ces\SNT25070004_1(4).doc”;//原文件
String pdfPath = “D:\data\ces\SNT25070004_1(4).pdf”;//pdf
Document doc = new Document(wordPath);

    // 输出文件路径(.docx格式)
    String outputPath = "D:\\data\\ces\\SNT25070004_1(4).docx";//原文件转docx


    // 保存为DOCX格式
    doc.save(outputPath, SaveFormat.DOCX);

但是这文件初始就是doc的,使用这个代码另存为docx 还是没有那张照片的,这个思路可以优化掉吗

@kin58 下面是手动重新保存的文档和输出文件:

SNT.zip (2.6 MB)

能从代码层面上解决这个问题吗

@kin58 很遗憾,没有。 即使在 Doc 到 Doc 转换之后,文档中的图像也会丢失,但形状还在。

The issues you have found earlier (filed as WORDSNET-28422) have been fixed in this Aspose.Words for Java 25.8 update.