Aspose.Words doc转pdf 内容出现丢失,页码跳页,排版混乱问题

更多问题参考:Aspose Repository Browser /repo/com/aspose/aspose-words/icon-default.png?t=M5H6https://repository.aspose.com/repo/com/aspose/aspose-words/File Format APIs for Word Excel PDF Email PowerPoint Barcode Images OCR Note & 3D.NET Java Cloud SharePoint Android SSRS and JasperReports file format APIs for developers. Integrate in any enterprise level web desktop and mobile applicationhttps://www.aspose.com/

简介:
Aspose.Words 是一个商业.NET 类库,可以使得应用程序处理大量的文件任务。Aspose.Words 支持 Doc,Docx,RTF,HTML,OpenDocument,PDF,XPS,EPUB 和其他格式。使用 Aspose.Words 可以在不使用 Microsoft.Word 的情况下生成、修改、转换和打印文档。

排版错位(页码跳页)

在使用中发现 apose 对 word 文档转换 PDF 操作中会出现将单页分成两页的情况。仔细分析后发现是因为 word 文档在编辑的时候是采用的多页编辑。页面效果是单页,可是在 apose 将 word 文档转为 pdf 后就变成了两页。所以要新生成一个 word 文档并保留原 word 文档的样式,问题解决。

try {
    long old = System.currentTimeMillis();
    File file = new File(targetFile);
    FileOutputStream os = new FileOutputStream(file);
    Document doc = new Document(sourcerFile);
    Document document = new Document();//新建一个空白pdf文档
    document.removeAllChildren();
    document.appendDocument(doc, ImportFormatMode.USE_DESTINATION_STYLES);//保留样式
    document.save(os, SaveFormat.PDF);//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
    os.close();
    long now = System.currentTimeMillis();
    System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");  //转化用时
} catch (Exception e) {
    e.printStackTrace();
}

数据丢失:

在使用中发现 apose 对 word 文档转换 PDF 操作中会出现将页签数据丢失的情况。将问题反复重现后发现是因为 word 文档的样式无法保存。所以要新生成一个 word 文档并保留原 word 文档的样式,问题解决。

try {
    long old = System.currentTimeMillis();
    File file = new File(targetFile);
    FileOutputStream os = new FileOutputStream(file);
    Document doc = new Document(sourcerFile);
    Document document = new Document();//新建一个空白pdf文档
    document.removeAllChildren();
    document.appendDocument(doc, ImportFormatMode.USE_DESTINATION_STYLES);//保留样式
    document.save(os, SaveFormat.PDF);//全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF, EPUB, XPS, SWF 相互转换
    os.close();
    long now = System.currentTimeMillis();
    System.out.println("共耗时:" + ((now - old) / 1000.0) + "秒");  //转化用时
} catch (Exception e) {
    e.printStackTrace();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值