humbol
1
Do you want to: Report a bug
problem:
When using oDocument.ToJSON in a document that has the current document page counter, the generated json is bogus.
It is something like:
{type: 'instrText', hOh: 'PAGE'}
instead of:
{type: 'instrText', instr: 'PAGE'}
And therefore, using the generated JSON is creates an error.
You can reproduce the problem using
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
oParagraph.AddPagesCount();
let json = oDocument.ToJSON(false, false, false, false, false, false);
console.log(JSON.parse(json))
var api_json = Api.FromJSON(json)
To resolve the problem, i modified the function “WriterToJSON.prototype.SerParaRun” in file “sdkjs/word/fromToJSON.js”
where the line :
oInstrText.instr = "PAGE";
should be :
oInstrText["instr"] = "PAGE";
The problem cames only after the code has been minificated
Best,
DocumentBuilder version: 7.4 , 7.5
OS: ubuntu / docker
Hello @humbol
Thank you for providing this information
We are currently investigating the situation.
hey @humbol
Please, check the behavior in the latest version of the document server.
Testing on version 7.5.1 did not reveal any issues with the page counter.
humbol
5
Hi Nikolas,
The problem arises only when you have compiled and packed dist.
I did a gif using the instance of page : ONLYOFFICE Api Documentation - Clear
Best,
1 Like
@humbol
Our team has created a bug report for the behavior you described when using the AddPagesCount method.
I’m providing a script using the GetStatistic method:
var oDocument = Api.GetDocument();
var oStatistics = oDocument.GetStatistics();
var oParagraph = Api.CreateParagraph();
oParagraph.AddText("Pages: " + oStatistics.PageCount);
oDocument.Push(oParagraph);
let json = oDocument.ToJSON(false, false, false, false, false, false);
console.log(JSON.parse(json))
var api_json = Api.FromJSON(json)