Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocumentBuilder C++ API: Convert DOCX to PDF failed with V8 error #126

Open
anatoly-spb opened this issue Apr 3, 2024 · 3 comments
Open
Labels
question Issues that look for answers waiting feedback Issues that we waiting to be answered from author of issue

Comments

@anatoly-spb
Copy link

anatoly-spb commented Apr 3, 2024

Describe your problem:

I try to convert docx/xlsx file to pdf, but my program finished with:

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.
#

Steps to reproduce the problem:

compile and run C++ program based on your /opt/onlyoffice/documentbuilder/libdoctrenderer.so:

    using namespace NSDoctRenderer;
    CDocBuilder::Initialize(L"/opt/onlyoffice/documentbuilder");
    {
      CDocBuilder oBuilder;
      oBuilder.SetProperty("--work-directory", L"/opt/onlyoffice/documentbuilder");
      oBuilder.CreateFile(L"docx");
      oBuilder.SaveFile(L"pdf", L"my.pdf");
    }

the same error with xlsx:

 using namespace NSDoctRenderer;
 CDocBuilder::Initialize(L"/opt/onlyoffice/documentbuilder");
 {
   CDocBuilder oBuilder;
   oBuilder.SetProperty("--work-directory", L"/opt/onlyoffice/documentbuilder");
   oBuilder.CreateFile(L"xlsx");
   oBuilder.SaveFile(L"pdf", L"my.pdf");
 }

Here is the demo project https://github.com/anatoly-spb/onlyoffice-documentbuilder-cxx-api-demo

DocumentBuilder version:

8.0.0.99

Installation method:

rpm -ivh https://download.onlyoffice.com/install/desktop/docbuilder/linux/onlyoffice-documentbuilder.x86_64.rpm

Operating system:

CentOS 6
g++ (GCC) 11.4.1 20230605

@cccs-rs
Copy link

cccs-rs commented Jan 9, 2025

I ran into this issue as well with running DocumentBuilder in a Docker image using the Python API, no problems with testing on my buildhost.

@kam193 found that for some reason you have to try loading the CDocBuilder as root, and then it will work for other users:
https://github.com/CybercentreCanada/assemblyline-service-document-preview/blob/5e6dd549e9bb04fc4c04d68eb98c2e00a50001ae/Dockerfile#L63

Not sure if the authors/maintainers could explain why that is but I suspect maybe something has to be initialized but it requires certain privileges in order to do so?

@askonev
Copy link
Member

askonev commented Jan 30, 2025

@anatoly-spb At the moment, we are working on up-to-date documentation cdocbuilder/savefile/

If we consider the compilation script of a program for converting docx to pdf

format types

// main.cpp
#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;
}
// compile flags
g++ -I/opt/onlyoffice/documentbuilder/include \
 -L/opt/onlyoffice/documentbuilder \
 -Wl,--unresolved-symbols=ignore-in-shared-libs main.cpp \
  -ldoctrenderer

And for the resulting program to work correctly, you need to add a global variable with a path to document builder.

export LD_LIBRARY_PATH=/opt/onlyoffice/documentbuilder

@askonev
Copy link
Member

askonev commented Jan 30, 2025

@cccs-rs Can I ask you to issue a new issue because it does not relate to the problem described in this topic?

@Rita-Bubnova Rita-Bubnova added question Issues that look for answers waiting feedback Issues that we waiting to be answered from author of issue labels Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers waiting feedback Issues that we waiting to be answered from author of issue
Projects
None yet
Development

No branches or pull requests

4 participants