在Ubuntu2404上使用documentbuilder c++的API将docx转pdf文件会出现v8报错,报错信息如下:
TypeError: Cannot read property 'length' of undefined
at Object.a.AscCommon.NU.decode.a.AscCommon.NU.decode (<anonymous>:11662:172)
at e (<anonymous>:11577:526)
at n.au (<anonymous>:11597:402)
at Object.au (<anonymous>:11602:10)
at e.vGd (<anonymous>:10401:495)
at e.vGd (<anonymous>:10704:213)
at <anonymous>:10345:382
at da (<anonymous>:9653:313)
at Object.a.AscCommon.aQh (<anonymous>:9835:127)
at e.yO (<anonymous>:10345:345)
#
# Fatal error in v8::ToLocalChecked
# Empty MaybeLocal.
#
使用的代码如下:
#include "common.h"
#include "docbuilder.h"
using namespace NSDoctRenderer;
const wchar_t* workDir = L"/opt/onlyoffice/documentbuilder";
const wchar_t* filePath = L"/opt/onlyoffice/documentbuilder/empty/new.docx";
const wchar_t* resultPath = L"result.pdf";
int main()
{
// initialize DocBuilder
CDocBuilder::Initialize(workDir);
CDocBuilder builder;
builder.OpenFile(filePath, L"");
// save as PDF and close
builder.SaveFile(OFFICESTUDIO_FILE_DOCUMENT_OFORM_PDF, resultPath);
builder.CloseFile();
CDocBuilder::Dispose();
return 0;
}
编译命令:
g++ -I/opt/onlyoffice/documentbuilder/include \
-L/opt/onlyoffice/documentbuilder \
-Wl,--unresolved-symbols=ignore-in-shared-libs main.cpp \
-ldoctrenderer
我参考documentbuilder使用文档,也安装了对应的依赖包,还是运行报错,是否documentbuilder不能直接使用,还需要部署document server才能使用呢,官方文档上并没有提到需要依赖本地部署的服务端,这个问题怎么解决呢