Here you can find some code samples for Document Builder library in different programming languages:
For running C++ and C# code samples use python script configure/configure.py which is able to generate:
- Visual Studio project files
- Qt project file
- Makefile
To use configure.py you need to specify following options:
-
Which project files to generate:
--vs,--qtor--make. Several options are available at the same time, but some of them are not supported on all platforms. In case you provide none of these options, all available projects will be generated. -
Test samples with
--test TEST. Some available options:--test all– generate projects for both C++ and C#.--test cpp– generate projects only for C++ samples--test cs– generate projects only for C# samples.--test cpp/creating_basic_form– generate only project for the specified sample.
Several test options are available at the same time. To see all available
TESToptions callconfigure.py -l. -
Directory to the Document Builder with
--dir DIR. If Document Builder is not installed in default path you have to provide path to it.
Generated files will be located in the out directory inside of the corresponding test folders.
NOTE: Only available on Windows
-
Use
configure.pyto generate VS project files. For example:python configure.py --vs --test cpp/creating_basic_form --test cpp/creating_advanced_form
-
Open
.slnfile in Visual Studio. It will prompt you to retarget Windows SDK and VS toolset to your installed version – click "OK". -
The solution is ready to be built and run. Documents will be created in the project files directory.
-
Use
configure.pyto generate Qt project files. For example:python configure.py --qt --test cpp
-
Open
.profile in Qt Creator. -
The project is ready to be built and run. Documents will be created in the
builddirectory.
NOTE: Only available on Linux and Mac OS.
-
Use
configure.pyto generate Makefile. For example:python configure.py --make --test cpp/filling_spreadsheet
-
Go to the directory with generated Makefile:
cd ../out/cpp/filling_spreadsheet -
Call
make
makewill build and run the executable. Documents will be created in the same directory as Makefile is.
NOTE: Only available on Windows with Visual Studio and .NET SDK installed
-
Use
configure.pyto generate VS project files. For example:python configure.py --vs --test cs
-
Open
.slnfile in Visual Studio. Depending on your installed .NET SDK version you may need to set different target framework by setting it in Visual Studio project properties or editing it directly in the.csprojfile. -
The solution is ready to be built and run. Documents will be created in the project files directory.
-
Execute
configure.pywith--test python:python configure.py --test python
Provide directory to Document Builder with
--dirif necessary.It is needed for generating auxiliary module containing the path to Document Builder.
-
Go to test directory:
cd python/creating_basic_form -
Run the script
python main.py
Documents will be created in the test directory.
NOTE: JDK 8 or newer is required
-
Go to test directory:
cd java/creating_presentation -
Compile the
Program.javaproviding the path to docbuilder.jar, located in the Document Builder directory:javac -cp "C:\Program Files\ONLYOFFICE\DocumentBuilder\docbuilder.jar" Program.javaNote that some Java samples use
json_simplelibrary for parsing JSON files. The library is located at resources/utils/json/json_simple-1.1.jar. To compile these samples, you also need to add the path tojson_simplelibrary under-cpoption:javac -cp "C:\Program Files\ONLYOFFICE\DocumentBuilder\docbuilder.jar;..\..\resources\utils\json\json_simple-1.1.jar" Program.javaAlso note that on UNIX systems the path separator is
:instead of;. Thus, on Linux or Mac OS it should be:javac -cp "/opt/onlyoffice/documentbuilder/docbuilder.jar:../../resources/utils/json/json_simple-1.1.jar" Program.java -
.classfile should appear in the directory. Run the program withjavaand specify the same libraries under-cpoption as in the compilation step, but also add the current directory.:java -cp "C:\Program Files\ONLYOFFICE\DocumentBuilder\docbuilder.jar;." ProgramOr, if the sample uses the JSON library:
java -cp "C:\Program Files\ONLYOFFICE\DocumentBuilder\docbuilder.jar;..\..\resources\utils\json\json_simple-1.1.jar;." ProgramAgain, the same applies to UNIX systems, but with
;replaced with:. -
Documents will be created in the test directory.