Free Support Forum - aspose.com

关于aspose.word的问题,linux和windows上部署aspose所呈现的效果是完全相同的吗?

我有一篇文档,在windows上生成时是99页,在linux上生成是100页,linux字体是全的,可能是在什么方面出现差异?能否先给个推测,文档暂且不方便提供。

test.zip (315.5 KB)
这六个文件都有上面的问题
linux是用linux生成的,win是用windows下的aspose生成的。都是20.4。(如果用最新版本有改进的话我再改),
不带direct但是带linux,win的是由我们自己的逻辑读入然后生成。
带direct的是由20210426辑要-loveandpeace.doc这个文件直接读入生成的(代码如下)。
com.aspose.words.Document doc = new com.aspose.words.Document(“src/test/docs/20210426辑要-loveandpeace.doc”);
LayoutCollector layoutCollector = new LayoutCollector(doc);
NodeCollection runs = doc.getChildNodes(NodeType.PARAGRAPH, true);

    for (int i = 0; i < runs.getCount(); i++) {
        try{
            Paragraph r = (Paragraph)runs.get(i);
            int numPage = layoutCollector.getStartPageIndex(r);

// System.out.println(i+" “+numPage+” “+r.getParagraphFormat().getOutlineLevel()+” "+r.getText());
} catch (Exception e) {

// System.out.println(e);
e.printStackTrace();
}
}
doc.save(“src/test/docs/20210426辑要-loveandpeace-direct-linux.doc”);
doc.updateFields();
doc.save(“src/test/docs/20210426辑要-loveandpeace-direct-linux-uptoc.doc”);

@xl1,

您是否尝试过最新的(21.4)版本的Aspose.Words for Java? 如果问题仍然存在,则请ZIP并上传您的源Word文档和Aspose.Words生成的输出文件,其中显示了不良行为,用于测试。 然后,我们将对此进行调查,并为您提供更多信息。

编辑:我们正在检查场景,我们将尽快与您联系。

宋体

我们现在的场景不便于升级怕出现更多bug……如果的确21.4能够解决这个问题我们会考虑升级。但希望贵方能帮忙测验是否是aspose自带的问题?

已测试21.4:出现同样的错误

@xl1,

我已经检查了与Windows 10上的MS Word 2019中文版共享的所有七个Word DOC文档,它说在所有这些DOC文件中实际上有99个页面可用。

您到底使用什么软件来查看这些DOC文件? 您是否也可以提供一个屏幕截图,以突出显示Aspose.Words生成的输出中的问题?

aspose. words.读入文件后,更新目录,linux上getpagecount输出是100页实际页码offitce打开99,目录4页,正文95页,目录最后一个的页码对应96页,你可以看一下带linux的word都是输出。windows的同样操作目录最后一行链接到95页。

‘’’
com.aspose.words.Document doc = new com.aspose.words.Document(“src/test/docs/20210426辑要-loveandpeace.doc”);
LayoutCollector layoutCollector = new LayoutCollector(doc);
NodeCollection runs = doc.getChildNodes(NodeType.PARAGRAPH, true);

    for (int i = 0; i < runs.getCount(); i++) {
        try{
            Paragraph r = (Paragraph)runs.get(i);
            int numPage = layoutCollector.getStartPageIndex(r);

//下面这句,windows上调用aspose.words,aspose和msword差不多;linux上,aspose和msword页码对不上
System.out.println(i+" “+numPage+” “+r.getParagraphFormat().getOutlineLevel()+” "+r.getText());
} catch (Exception e) {

// System.out.println(e);
e.printStackTrace();
}
}
doc.getPageCount();#linux输出99,win输出99
doc.save(“src/test/docs/20210426辑要-loveandpeace-direct-linux.doc”);
doc.updateFields();
doc.getPageCount();#linux输出100,win输出99
doc.save(“src/test/docs/20210426辑要-loveandpeace-direct-linux-uptoc.doc”);

‘’’

@xl1,

请从Windows 10计算机将以下字体文件的最新版本复制到Linux计算机内的单独文件夹中,并尝试运行Aspose.Words for Java最新21.4版本的以下代码:

  • 华文行楷
  • 仿宋_GB2312
  • 黑体
  • Calibri
  • 宋体
  • Times New Roman
  • Cambria
Document doc = new Document("source.doc");

FontSettings fontSettings = new FontSettings();
addFontFolder(fontSettings, myDir + "CustomFonts/");
doc.setFontSettings(fontSettings);

// your code goes here
LayoutCollector layoutCollector = new LayoutCollector(doc);
NodeCollection runs = doc.getChildNodes(NodeType.PARAGRAPH, true);
...
...

private static void addFontFolder(FontSettings fontSettings, String folder)
{
    FontSourceBase[] fontSourceBases = fontSettings.getFontsSources();
    FontSourceBase[] newFontSourceBases = new FontSourceBase[fontSourceBases.length + 1];
    System.arraycopy(fontSourceBases, 0, newFontSourceBases, 0, fontSourceBases.length);
    newFontSourceBases[newFontSourceBases.length - 1] = new FolderFontSource(folder, true);
    fontSettings.setFontsSources(newFontSourceBases);
}

如果问题仍然存在,您是否看到与字体丢失有关的警告消息? 请检查以下文章:

您还可以在Linux和Windows计算机上使用以下代码将源Word文档转换为PDF格式,并在此处共享输出的PDF文件以进行进一步测试吗?

Document doc = new Document("source.doc");
doc.Save("output 1 on [OS].pdf");
doc.updateFields();
doc.Save("output 2 on [OS].pdf");

我换了一台服务器(就叫linux2),之前那台服务器(linux1)暂且用不了。
在这台服务器linux2上,照您说的安装了上述字体,然后,运行了您所说的代码。
目前:win:getpagecount:99,msword:99,生成文件:20210426辑要-loveandpeace-direct-font-win(-uptoc)
linux2:getpagecount:189,msword:99,生成文件:20210426辑要-loveandpeace-direct-font-linux(-uptoc )
看上去linux上的行间距变得很大?他这是什么情况呢?
test.zip (2.1 MB)
没有报任何错误。

test.zip中linux的字体存在问题,调整了一下,现在字体使用callback不报错。但getpagecount页码是188
test2.zip (1.2 MB)

@xl1,

请首先在Windows计算机上运行以下代码,并生成带有嵌入式字体的DOCX文件。

Document doc = new Document("C:\\Temp\\source.doc");
doc.getFontInfos().setEmbedTrueTypeFonts(true);
doc.getFontInfos().setSaveSubsetFonts(false);
doc.getFontInfos().setEmbedSystemFonts(true);
doc.save("C:\\Temp\\word file with embedded fonts.docx");

现在,请将此带有嵌入式字体的DOCX Word文件复制到Linux计算机,并使用以下代码转换为PDF:

// 将默认编辑语言设置为PRC PRC以解决行距问题。
LoadOptions loadOptions = new LoadOptions();
loadOptions.getLanguagePreferences().setDefaultEditingLanguage(EditingLanguage.CHINESE_PRC);
Document doc = new Document("word file with embedded fonts.docx", loadOptions);
doc.save("awjava-21.4.pdf");

您现在在PDF中看到正确的输出了吗? 如果是,则Windows和Linux计算机之间的字体有所不同。

我注意到,您在上一篇文章中共享的所有PDF文件都是使用Java 20.4的旧Aspose.Words生成的。 您能否使用最新的21.4Aspose.Words for Java测试以上代码段?

试过21.4,20.4,分别运行embed部分代码得到的文档:

Document doc = new Document("C:\\Temp\\source.doc");
doc.getFontInfos().setEmbedTrueTypeFonts(true);
doc.getFontInfos().setSaveSubsetFonts(false);
doc.getFontInfos().setEmbedSystemFonts(true);
doc.save("C:\\Temp\\word file with embedded fonts.docx");

test_embed_win.zip (6.3 MB)
test_embed_linux.zip (8.1 MB)
test_embed_uptoc_linux.zip (8.1 MB)

@xl1,

我们正在处理您的查询,并将尽快与您联系。

@xl1,

在Windows 10计算机上测试方案时,我看不到任何问题。
然后,我将整个Fonts文件夹从Windows 10计算机复制到Ubuntu虚拟机。
在测试了场景之后,我意识到Aspose.Words for Java抛出了一些有关以下字体的警告。
您能否ZIP并附加以下字体文件,以重新测试Linux计算机上的方案?

  • 仿宋_GB2312
  • 黑体

CustomFonts.zip (7.0 MB)
这是字体

  • 仿宋_GB2312
  • 黑体

下面是其他字体
Calibria.zip (2.6 MB)

calibria1.zip (3.1 MB)

STXINGKA.zip (2.7 MB)

CustomFonts.zip (2.2 MB)

我这边用了您那个代码,使用mvn test,但是没有见到过报错字体缺失的错误?能否告知下我这个错误是在哪里出现的?长什么样子?

我知道了……warning在mvn test中不出现,换了println就有了。之前的输出缺少宋体……现在好了,我下午去试一下linux1,这是linux2的报错,感谢:
2 2
0 2 8.18一 一一一一一一一一 一一一:一一一一一一一一一一(苹果)
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.759 s - in NewsPaperWriterByAsposeTem2Test
[INFO] Running NewsPaperWriterByAsposeTest
Unsupported operation: Table column widths may need to be calculated. Rendered column widths could differ.
At Table 1, Cell 1, Row 1, Table 1, Section 1
Other warning!
Unsupported operation: Table column widths may need to be calculated. Rendered column widths could differ.
At Table 1, Section 1
Other warning!
src/test/docs/20210426辑要-loveandpeace-direct-font-linux 99
Unsupported operation: Font subset embedded for font ‘黑体’ due to exceeding the maximum allowed size of 4194304 bytes.
Other warning!
Unsupported operation: Font subset embedded for font ‘宋体’ due to exceeding the maximum allowed size of 4194304 bytes.
Other warning!
Unsupported operation: Table column widths may need to be calculated. Rendered column widths could differ.
At Table 1, Cell 1, Row 1, Table 1, Section 1
Other warning!
Unsupported operation: Table column widths may need to be calculated. Rendered column widths could differ.
At Table 1, Section 1
Other warning!
src/test/docs/20210426辑要-loveandpeace-direct-font-linux 99
Unsupported operation: Font subset embedded for font ‘黑体’ due to exceeding the maximum allowed size of 4194304 bytes.
Other warning!
Unsupported operation: Font subset embedded for font ‘宋体’ due to exceeding the maximum allowed size of 4194304 bytes.
Other warning!
src/test/docs/20210426辑要-loveandpeace-direct-linux.doc 99
src/test/docs/20210426辑要-loveandpeace-direct-linux.doc 99
Unsupported operation: Table column widths may need to be calculated. Rendered column widths could differ.
At Table 1, Cell 1, Row 1, Table 1, Section 1
Other warning!
Unsupported operation: Table column widths may need to be calculated. Rendered column widths could differ.
At Table 1, Section 1
Other warning!
src/test/docs/20210426辑要-loveandpeace-direct-with embedded fonts-linux 99
Unsupported operation: Font subset embedded for font ‘黑体’ due to exceeding the maximum allowed size of 4194304 bytes.
Other warning!
Unsupported operation: Font subset embedded for font ‘宋体’ due to exceeding the maximum allowed size of 4194304 bytes.
Other warning!
Unsupported operation: Table column widths may need to be calculated. Rendered column widths could differ.
At Table 1, Cell 1, Row 1, Table 1, Section 1
Other warning!
Unsupported operation: Table column widths may need to be calculated. Rendered column widths could differ.
At Table 1, Section 1
Other warning!
src/test/docs/20210426辑要-loveandpeace-direct-with embedded fonts-linux 99
Unsupported operation: Font subset embedded for font ‘黑体’ due to exceeding the maximum allowed size of 4194304 bytes.
Other warning!
Unsupported operation: Font subset embedded for font ‘宋体’ due to exceeding the maximum allowed size of 4194304 bytes.
Other warning!
src/test/docs/20210426辑要-loveandpeace-direct-loadOption-with embedded fonts-linux 99
src/test/docs/20210426辑要-loveandpeace-direct-loadOption-uptoc-with embedded fonts-linux 99
8.18一 一一一一一一一一 一一一:一一一一一一一一一一(苹果)
0 8.18一 一一一一一一一一 一一一:一一一一一一一一一一(苹果)
82 82
82
src/test/docs/asposeTem1Test0_1.6.5.doc
99 99
99
99 99
src/test/docs/20210426辑要-loveandpeace-linux.doc 99

请问这连中错误如何解决呢?以及这个相关报错的描述是在哪里呢?我看了warninginfocollection,但是里面并没有关于这些报错信息的描述?
Unsupported operation: Font subset embedded for font ‘宋体’ due to exceeding the maximum allowed size of 4194304 bytes.
Unsupported operation: Table column widths may need to be calculated. Rendered column widths could differ.

@xl1,

请将此Word DOC文档作为输入文档(source.zip (46.4 KB)),然后尝试运行以下代码:

public static class HandleDocumentWarnings implements IWarningCallback {
    public ArrayList listOfFonts = new ArrayList();

    public void warning(WarningInfo info) {

        if (info.getWarningType() == WarningType.FONT_SUBSTITUTION || info.getWarningType() == WarningType.FONT_EMBEDDING) {
            if (!listOfFonts.contains(info.getDescription()))
                listOfFonts.add(info.getDescription());
        }
    }

    public void printMissingFontDetails() throws Exception {
        DocumentBuilder builder = new DocumentBuilder();
        builder.getFont().setName("SimSun");

        for (int i = 0; i < listOfFonts.size(); i++)
            builder.writeln(listOfFonts.get(i).toString());

        builder.getDocument().save(myDir + "warnings.docx");
    }
}

Document doc = new Document(myDir + "source.doc");

FontSettings fontSettings = new FontSettings();
doc.setFontSettings(fontSettings);
fontSettings.setFontsFolder(myDir + "fake fonts folder that does not exist.", true);

HandleDocumentWarnings warningsHandler = new HandleDocumentWarnings();
doc.setWarningCallback(warningsHandler);

doc.save(myDir + "awjava-21.4.pdf");

warningsHandler.printMissingFontDetails();

您将获得一个包含121页的PDF文件(awjava-21.4 - 1.pdf (142.8 KB))和一个包含以下警告消息的文档:

  1. Font ‘华文行楷’ has not been found. Using ‘Fanwood’ font instead. Reason: first available font.
  2. Font ‘仿宋_GB2312’ has not been found. Using ‘Fanwood’ font instead. Reason: first available font.
  3. Font ‘黑体’ has not been found. Using ‘Fanwood’ font instead. Reason: first available font.
  4. Font ‘Calibri’ has not been found. Using ‘Fanwood’ font instead. Reason: first available font.
  5. Font ‘宋体’ has not been found. Using ‘Fanwood’ font instead. Reason: first available font.
  6. Font ‘Times New Roman’ has not been found. Using ‘Fanwood’ font instead. Reason: first available font.
  7. Font ‘Cambria’ has not been found. Using ‘Fanwood’ font instead. Reason: first available font.