Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Nov 27, 2024 8:11 am

When I want to use the SaveToFile function in an ubuntu-based docker container, the following problem occurs.

this is the part of dockerfile
Code: Select all
FROM ubuntu:22.04 AS base_image


this is the error
Code: Select all
Unhandled Exception: System.TypeInitializationException: TypeInitialization_Type_NoTypeAvailable
 ---> System.DllNotFoundException: DllNotFound_Linux, libSkiaSharp,
libfontconfig.so.1: cannot open shared object file: No such file or directory
liblibSkiaSharp.so: cannot open shared object file: No such file or directory
libSkiaSharp: cannot open shared object file: No such file or directory
liblibSkiaSharp: cannot open shared object file: No such file or directory

   at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x4e
   at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0x10f
   at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x35
   at SkiaSharp.SkiaApi.sk_colortype_get_default_8888() + 0x2d
   at SkiaSharp.SKImageInfo..cctor() + 0x2b
   at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0xb9
   Exception_EndOfInnerExceptionStack
   at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0x153
   at System.Runtime.CompilerServices.ClassConstructorRunner.CheckStaticClassConstructionReturnNonGCStaticBase(StaticClassConstructionContext*, IntPtr) + 0x9
   at sprhxg..ctor(Int32, Int32, Single, Single, SKColorType) + 0x5d
   at sprktg.spra() + 0x78
   at sprktg.sprd(Stream) + 0xdc
   at sprlsc.spra(Stream, sprkth) + 0x29f
   at sprksd.spra(ShapeBase, Boolean, sprlsf) + 0x3f9
   at sprksd.spra(ShapeBase, Paragraph) + 0x918
   at sprksd.spre(Paragraph) + 0x6bd
   at sprksd.spra(Section) + 0x6b6
   at sprksd.sprc(Document) + 0x61e
   at sprksd.sprb(Document, String) + 0x101
   at sprksd.sprc(Document, String) + 0x482
   at Spire.Doc.Document.sprn(String) + 0x56
   at Spire.Doc.AOT.NLDocument.Document_SaveToFileFF(IntPtr, IntPtr, Int32) + 0x65

Look forward to hearing from you!

arist.yang
 
Posts: 6
Joined: Wed Nov 27, 2024 7:39 am

Wed Nov 27, 2024 8:32 am

Hi,

Thank you for your message.
Please provide the programming language and the version of Spire.Doc that you are using so that we can reply to this question more accurately.
Thanks in advance.

Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 455
Joined: Mon Nov 07, 2022 8:10 am

Wed Nov 27, 2024 9:17 am

Thank you for your reply.
Used Python 3.10.12
Spire.Doc version is 12.7.1 or 11.8.1
wating for your re!

arist.yang
 
Posts: 6
Joined: Wed Nov 27, 2024 7:39 am

Wed Nov 27, 2024 9:24 am

after use this suggestionhttps://www.e-iceblue.com/forum/post54949.html?hilit=libSkiaSharp#p54949
the error change that
Code: Select all
document.SaveToFile(html_name, FileFormat.Html)
  File "/usr/local/lib/python3.10/dist-packages/plum/function.py", line 642, in __call__
    return self.f(self.instance, *args, **kw_args)
  File "/usr/local/lib/python3.10/dist-packages/plum/function.py", line 592, in __call__
    return _convert(method(*args, **kw_args), return_type)
  File "/usr/local/lib/python3.10/dist-packages/spire/doc/Document.py", line 2384, in SaveToFile
    CallCFunction(GetDllLibDoc().Document_SaveToFileFF,self.Ptr, fileNamePtr,enumfileFormat)
  File "/usr/local/lib/python3.10/dist-packages/spire/doc/common/__init__.py", line 113, in CallCFunction
    raise SpireException(info)
spire.doc.common.SpireException: TypeInitialization_Type_NoTypeAvailable:   at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0x153
   at System.Runtime.CompilerServices.ClassConstructorRunner.CheckStaticClassConstructionReturnNonGCStaticBase(StaticClassConstructionContext*, IntPtr) + 0x9
   at sprbsz..ctor(Int32, Int32, Single, Single, SKColorType) + 0x7a
   at spreyl.spra() + 0x78
   at spreyl.sprd(Stream) + 0x134
   at sprf6f.spra(Stream, spreym) + 0x282
   at sprexp.spra(ShapeBase, Boolean, sprf6i) + 0x6e9
   at sprexp.spra(ShapeBase, Paragraph) + 0x72e
   at sprexp.spre(Paragraph) + 0x668
   at sprexp.spra(Section) + 0x4e1
   at sprexp.sprc(Document) + 0x6e2
   at sprexp.sprb(Document, String) + 0x123
   at sprexp.sprc(Document, String) + 0x6f1
   at Spire.Doc.Document.sprq(String) + 0x56
   at Spire.Doc.AOT.NLDocument.Document_SaveToFileFF(IntPtr, IntPtr, Int32, IntPtr) + 0x71

arist.yang
 
Posts: 6
Joined: Wed Nov 27, 2024 7:39 am

Wed Nov 27, 2024 9:31 am

this is full the test code
Code: Select all
from spire.doc import *
def read_htmllist_from_docx(docx_file_path, docx_file_md5):
    try:
        # time_now = time.time()
        print(f'开始读取docx')
        html_file_path = "/opt/yhf/html/"
        print(f'html_file_path = [{html_file_path}]')
        # 创建Document对象
        document = Document()
        print(f'创建Document对象')

        # 加载Word文档
        document.LoadFromFile(docx_file_path)
        (f'加载Word文档')

        # 嵌入CSS样式
        document.HtmlExportOptions.CssStyleSheetFileName = "sample.css"
        document.HtmlExportOptions.CssStyleSheetType = CssStyleSheetType.External
        print(f'嵌入CSS样式')

        # 设置是否嵌入图像
        document.HtmlExportOptions.ImageEmbedded = False
        document.HtmlExportOptions.ImagesPath = html_file_path + "Images/"
        print(f'设置是否嵌入图像')

        # 设置是否将表单字段导出为纯文本
        document.HtmlExportOptions.IsTextInputFormFieldAsText = True
        print(f'设置是否将表单字段导出为纯文本')

        # 将文档保存为 html 文件
        html_name = html_file_path + "test.html"
        print(html_name)
        document.SaveToFile(html_name, FileFormat.Html)
        print(f'将文档保存为 html 文件')
        document.Close()
    except Exception as err:
        print(err)
if __name__ =='__main__':
    docx_file_path ="/opt/local_file/2024-11-27/test.docx"
    read_htmllist_from_docx(docx_file_path,"qweqwe")

arist.yang
 
Posts: 6
Joined: Wed Nov 27, 2024 7:39 am

Wed Nov 27, 2024 10:06 am

Hello,

Thank you for supplementing the information.
Have you used PyInstaller? Did the error occur when you executed the program after packaging it with PyInstaller in a Docker container? I am looking forward to your reply. Thanks in advance.

Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 455
Joined: Mon Nov 07, 2022 8:10 am

Wed Nov 27, 2024 10:15 am

use pyinstaller after run docker, I used this command after the container was created, and this result is from my second run of it
Code: Select all
pyinstaller --add-binary /LinuxCases/Spire.Doc.Base.so:. --add-binary /LinuxCases/libSkiaSharp.so:. toPdf.py

pyinstaller's return
Code: Select all
 pyinstaller --add-binary /LinuxCases/Spire.Doc.Base.so:. --add-binary /LinuxCases/libSkiaSharp.so:. toPdf.py
On Linux, objdump is required. It is typically provided by the 'binutils' package installable via your Linux distribution's package manager.

arist.yang
 
Posts: 6
Joined: Wed Nov 27, 2024 7:39 am

Thu Nov 28, 2024 8:07 am

Hi,

Regarding the error you encountered, please first install binutils using the following command:
Code: Select all
apt install binutils

Then, use the following command to package your Python program:
Code: Select all
pyinstaller --add-binary Spire.Doc.Base.so:./spire/doc/lib --add-binary libSkiaSharp.so:./spire/doc/lib your_python_script.py

Please note the following points:
1. "Spire.Doc.Base.so" and "libSkiaSharp.so" need to be filled in with the actual paths that exist in your environment. If Spire.Doc is installed in a Linux environment, the path is usually located at /usr/local/lib/python3.xx/dist-packages/spire/doc/lib/.
2. Please do not remove or make any changes to ":./spire/doc/lib".
3. Replace "your_python_script.py" with the actual name of the Python file you need to package.

If you still cannot succeed in the test after following these steps, please provide the following information for us to further investigate. Thank you for your assistance in advance.
1. The new error message
2. Your Dockerfile file.
3. The specific steps you took within the Docker container.
4. Your Word test file.

Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 455
Joined: Mon Nov 07, 2022 8:10 am

Return to Spire.Doc