mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-07-19 21:00:55 +08:00
Update test example
(it doesn't work yet)
This commit is contained in:
@ -1,18 +1,49 @@
|
||||
import docbuilder.CDocBuilder;
|
||||
import docbuilder.*;
|
||||
|
||||
public class Program {
|
||||
public static void main(String[] args) {
|
||||
test();
|
||||
String workDirectory = "C:/Program Files/ONLYOFFICE/DocumentBuilder";
|
||||
String resultPath = "result.docx";
|
||||
|
||||
// TODO: Update system PATH at runtime
|
||||
|
||||
test(workDirectory, resultPath);
|
||||
|
||||
// Need to explicitly call System.gc() because finalizers might not automatically get called
|
||||
// Note: Even System.gc() can not guarantee that finalizers will be actually called. Possible memory leaks!
|
||||
System.gc();
|
||||
}
|
||||
|
||||
public static void test() {
|
||||
CDocBuilder.initialize("C:\\Users\\mixa_\\main\\core\\build\\lib\\win_64\\debug");
|
||||
public static void test(String workDirectory, String resultPath) {
|
||||
CDocBuilder.initialize(workDirectory);
|
||||
CDocBuilder builder = new CDocBuilder();
|
||||
System.out.println(builder.getVersion());
|
||||
builder.createFile(FileTypes.Document.DOCX);
|
||||
|
||||
CDocBuilderContext context = builder.getContext();
|
||||
CDocBuilderContextScope scope = context.createScope();
|
||||
|
||||
CDocBuilderValue global = context.getGlobal();
|
||||
|
||||
CDocBuilderValue api = global.get("Api");
|
||||
CDocBuilderValue document = api.call("GetDocument");
|
||||
CDocBuilderValue paragraph1 = api.call("CreateParagraph");
|
||||
|
||||
// TODO: autowrapping?
|
||||
paragraph1.call("SetSpacingAfter", new CDocBuilderValue(1000), new CDocBuilderValue(false));
|
||||
paragraph1.call("AddText", new CDocBuilderValue("Hello from Java!"));
|
||||
|
||||
CDocBuilderValue paragraph2 = api.call("CreateParagraph");
|
||||
paragraph2.call("AddText", new CDocBuilderValue("Goodbye!"));
|
||||
|
||||
CDocBuilderValue content = context.createArray(2);
|
||||
content.set(0, paragraph1);
|
||||
content.set(1, paragraph1);
|
||||
|
||||
document.call("InsertContent", content);
|
||||
|
||||
builder.saveFile(FileTypes.Document.DOCX, resultPath);
|
||||
builder.closeFile();
|
||||
|
||||
CDocBuilder.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user