正确安装 DOCX -> PDF 转换后,Spire.Doc 无法运行

问题描述 投票:0回答:1

我只是想将

docx
导出到
pdf
,因此在我的协作中安装了
Spire.Doc

%pip install Spire.Doc
%pip install plum-dispatch

并运行代码

from spire.doc import *
from spire.doc.common import *

inputFile = "example-docs/document.docx"
outputFile = "document.pdf"

#Create word document
document = Document()
document.LoadFromFile(inputFile)

# Create a ToPdfParameterList object
parameters = ToPdfParameterList()

# Embed all used fonts in Word into PDF
parameters.IsEmbeddedAllFonts = True

#Save the file to a PDF file
document.SaveToFile("WordToPdfWithFontsEmbedded.pdf", parameters, FileFormat.PDF)
document.Close()

#Save the document to a PDF file.
# document.SaveToFile(outputFile, FileFormat.PDF)
# document.Close()

但我不断遇到问题;

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-2-707d9ebcb6c3> in <cell line: 15>()
     13 
     14 # Embed all used fonts in Word into PDF
---> 15 parameters.IsEmbeddedAllFonts = True
     16 
     17 #Save the file to a PDF file

1 frames
/usr/local/lib/python3.10/dist-packages/spire/doc/common/__init__.py in CallCFunction(func, *args, **kwargs)
    103     args = list(args) +[data]
    104 
--> 105     result = func(*args, **kwargs)
    106     modified_value = cast(data, POINTER(c_uint64)).contents.value
    107     if old_value != modified_value:

RuntimeError: ffi_prep_cif_var failed

问题是什么以及如何解决?

python pdf google-colaboratory docx spire.doc
1个回答
0
投票

Spire.Doc for Python 尚未提供对 Google Colab 的特定兼容性。但是,我注意到您在另一篇post中提到了 macOS。我想通知您,最新版本的 Spire.Doc for Python V12.4.0(今天发布)与 macOS 兼容。

要在Mac上安装Spire.Doc for Python,您可以参考这个文档。如果您在 macOS 上遇到任何问题,我建议您将其发布在 Spire forum 上寻求帮助。

© www.soinside.com 2019 - 2024. All rights reserved.