DocumentBuilder version: 8.0.0 (according to the website I downloaded it from)
Installation method: download arm.64deb package from Download ONLYOFFICE Document Builder | ONLYOFFICE
OS: Ubuntu (running in docker on mac)
Not sure what I’m missing, I’ve downloaded an installed the prebuilt package from the above link, but trying to run some sample code (below) is giving me the ReferenceError: Api is not defined, not sure if i’ve missed some setup/installation procedure?
script.docbuilder
builder.CreateFile('docx');
let oDoc = Api.GetDocument(0);
let oPar = oDoc.GetElement(0);
oPar.AddText(Argument['key']);
oPar.AddLineBreak();
oPar.AddText(Argument['key2']);
builder.SaveFile('docx', 'simple.docx');
builder.CloseFile();
Running:
/opt/onlyoffice/documentbuilder/docbuilder '/project/script.docbuilder'
ReferenceError: Api is not defined
at <anonymous>:1:12
UPDATE
Ended up modifying a different sample script and had It run without failure:
where /project/ is a volume mount to my current working dir where i’m running the docker container from.
So I suppose the Api object is not available, still struggling to comprehend the docs on this one…
UPDATE 2
So looks like I may have missed the difference between builder and builderJS, it also seems like the Api is available after I’ve opened/created a file. Seems simple now, but this was a struggle to comprehend
Hello @Jamesplxs,
I’m glad you’ve managed to resolve the issue. Do I understand it right that when you use builder.OpenFile instead of builderJS.OpenFile, the script is not executed?
Using this small script I was getting the same error TypeError: Cannot read property 'GetDocument' of null
builder.OpenFile("/tmp/tmp.test.docx");
var oDocument = Api.GetDocument();
var oParagraph;
builder.SaveFile("docx", "/tmp/test.docx");
builder.CloseFile();
it turned out that the json passed as input to docbuilder --argument=.... was mallformed
I’m really sorry to bring bad news to you but this is an issue.
The error reported by the docbuilder when it receives an invalid json as argument is misleading
TypeError: Cannot read property 'GetDocument' of null
the developer will waste hours … maybe days to figure this one out.
Dear @dsl400
Your provided earlier docbuilder script doesn’t contain variables at all. Please pay attention to link in my previous reply that contains a sample with following lines:
var sCompany = Argument["company"];
var sProduct = Argument["product"];
var sCompatibility = Argument["compatibility"];
If you are going to use arguments line, please make sure that the script contains necessary variables.
Hello @dsl400
We agree that output information isn’t informative in the described scenario. We have started working on it. I will update this thread once we have something to share.