CDocBuilder
Base class used by ONLYOFFICE Document Builder for the document file (text document, spreadsheet, PDF) to be generated.
Methods
Name |
Description |
CloseFile |
Close the file to stop working with it. You can use a single ONLYOFFICE Document Builder instance to work with all your files, but you need to close the previous file before you can start working with the next one in this case. |
CreateFile |
Create a new file. The type of the file which will be created needs to be set. |
Dispose |
Unloading the ONLYOFFICE Document Builder from the application memory when it is no longer needed. |
ExecuteCommand |
Execute the command which will be used to create the document file (text document, spreadsheet, PDF, etc.).
See the Text document API and Spreadsheet API sections for more information which commands are available for various document types.
|
Initialize |
Initializing the ONLYOFFICE Document Builder as a library for the application to be able to work with it. |
OpenFile |
Open the document file which will be edited and saved afterwards. |
Run |
Run ONLYOFFICE Document Builder executable. If you do not want to write a C++ application, you can simply use the docbuilder.exe executable file and run it with the .docbuilder file as an argument, where all the code for the document file creation will be written. For C++ the path to the executable file from the sPath parameter must be used, the CDocBuilder object created and the Run method is called. |
RunTextA |
Run the all the commands for the document creation using a single command. Compared to CDocBuilder.ExecuteCommand where only one command at a time is allowed, CDocBuilder.RunTextA makes it possible to enter all the commands for the document creation at once. |
RunTextW |
Run the all the commands for the document creation using a single command. Compared to CDocBuilder.ExecuteCommand where only one command at a time is allowed, CDocBuilder.RunTextW makes it possible to enter all the commands for the document creation at once. |
SaveFile |
Save the file after all the changes are made. The type of the file which will be saved needs to be set. |
SetProperty |
The argument which can be trasferred to the program outside the CDocBuilder.ExecuteCommand method. |
SetPropertyW |
The argument which can be trasferred to the program outside the CDocBuilder.ExecuteCommand method. |
SetTmpFolder |
The path to the folder where the program will temporarily save files needed for the program correct work. After the successful document file creation all the files will be deleted from the folder. If no temporary folder is set, the system one will be used. |
Example
#include "docbuilder.h"
#define OFFICESTUDIO_FILE_DOCUMENT 0x0040
#define OFFICESTUDIO_FILE_DOCUMENT_DOCX OFFICESTUDIO_FILE_DOCUMENT + 0x0001
#define OFFICESTUDIO_FILE_DOCUMENT_ODT OFFICESTUDIO_FILE_DOCUMENT + 0x0003
#define OFFICESTUDIO_FILE_DOCUMENT_RTF OFFICESTUDIO_FILE_DOCUMENT + 0x0004
#define OFFICESTUDIO_FILE_DOCUMENT_TXT OFFICESTUDIO_FILE_DOCUMENT + 0x0005
#define OFFICESTUDIO_FILE_PRESENTATION 0x0080
#define OFFICESTUDIO_FILE_PRESENTATION_PPTX OFFICESTUDIO_FILE_PRESENTATION + 0x0001
#define OFFICESTUDIO_FILE_SPREADSHEET 0x0100
#define OFFICESTUDIO_FILE_SPREADSHEET_XLSX OFFICESTUDIO_FILE_SPREADSHEET + 0x0001
#define OFFICESTUDIO_FILE_SPREADSHEET_ODS OFFICESTUDIO_FILE_SPREADSHEET + 0x0003
#define OFFICESTUDIO_FILE_SPREADSHEET_CSV OFFICESTUDIO_FILE_SPREADSHEET + 0x0004
#define OFFICESTUDIO_FILE_CROSSPLATFORM 0x0200
#define OFFICESTUDIO_FILE_CROSSPLATFORM_PDF OFFICESTUDIO_FILE_CROSSPLATFORM + 0x0001
int wmain(int argc, wchar_t *argv[])
{
if (argc <= 0)
return 0;
NSDoctRenderer::CDocBuilder::Initialize();
NSDoctRenderer::CDocBuilder oBuilder;
#ifdef _DOC_BUILDER_EXECUTABLE_
std::wstring sBuildFile(argv[argc - 1]);
oBuilder.Run(argv[argc - 1]);
#else
oBuilder.SetTmpFolder(L"DocBuilderTemp");
oBuilder.CreateFile(OFFICESTUDIO_FILE_DOCUMENT_DOCX);
oBuilder.ExecuteCommand(L"var oDocument = Api.GetDocument();");
oBuilder.ExecuteCommand(L"var oParagraph;");
oBuilder.ExecuteCommand(L"oParagraph = oDocument.GetElement(0);");
oBuilder.ExecuteCommand(L"oParagraph.SetJc(\"center\");");
oBuilder.ExecuteCommand(L"oParagraph.AddText(\"Center\");");
oBuilder.SaveFile(OFFICESTUDIO_FILE_CROSSPLATFORM_PDF, L"document.pdf");
oBuilder.CloseFile();
#endif
NSDoctRenderer::CDocBuilder::Dispose();
return 0;
}
builder.SetTmpFolder("DocBuilderTemp");
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph;
oParagraph = oDocument.GetElement(0);
oParagraph.SetJc("center");
oParagraph.AddText("Center");
builder.SaveFile("pdf", "images.pdf");
builder.CloseFile();