Get Started
Documentation

SaveFile

bool SaveFile(nType, sPath, sParams);

Save the file after all the changes are made. The type of the file which will be saved needs to be set.

Parameters:

Name Type Description
nType const int& The type of the file to be saved set as a hexadecimal integer for the C++ code; for the .docbuilder script file the following values are possible: docx, odt, rtf, txt, pptx, xlsx, ods, csv, pdf.
sPath const wchar_t* The path to the file to be saved together with its name and extension.
sParams const wchar_t* The parameters needed for the correct file saving (most commonly the encoding is used for the txt and csv file types or the delimiter for the csv files, for other file types this is just an empty string). The parameters are added in the form of XML tags, where m_nCsvTxtEncoding is used for the text encoding and m_nCsvDelimiter is used for the csv delimiter. You can find all the supported values for the encoding in this file. The supported values for the csv delimiters include:
  • 0 - no delimiter
  • 1 - tab
  • 2 - semicolon
  • 3 - colon
  • 4 - comma
  • 5 - space
When saving into an image file (png or jpg) for creating thumbnails, the additional parameters are used. See below to find them out.

Example

C++

#define OFFICESTUDIO_FILE_DOCUMENT          0x0040
#define OFFICESTUDIO_FILE_DOCUMENT_DOCX     OFFICESTUDIO_FILE_DOCUMENT + 0x0001
NSDoctRenderer::CDocBuilder::Initialize();
NSDoctRenderer::CDocBuilder oBuilder;
oBuilder.SaveFile(OFFICESTUDIO_FILE_DOCUMENT_DOCX, L"D:/TESTFILES/document.docx");
NSDoctRenderer::CDocBuilder::Dispose();

.docbuilder

builder.SaveFile("docx", "D:/TESTFILES/document.docx");

Saving into images

ONLYOFFICE Document Builder allows to save your document files into image files creating thumbnails of the first page or of all the pages in the document. This is done using the parameters of the SaveFile() method. The parameters are added in the form of XML tags, where the following tags can be used:

  • m_oThumbnail - the core tag showing that the inner nodes will be used to create a thumbnail out of the document file;
  • format - the image file format used to create the thumbnail (can be of the following values: 3 - for a JPG file, 4 - for a PNG file);
  • aspect - the image aspect when creating the thumbnail from the document file (can be of the following values: 1 - will keep the original aspect, 0 - will stretch the image to fit the width and the height set below;
  • first - whether only the first page or all the pages should be converted into the thumbnail (can be of the following values: true - only the first page will serve as a thumbnail, false - all the document pages will be used to create thumbnails, in this case the file will be saved as an archive of images, one for each page);
  • width - the image width in pixels;
  • height - the image height in pixels.

Example

C++

oBuilder.SaveFile(OFFICESTUDIO_FILE_IMAGE, L"D:/TESTFILES/thumbnail.png", "<m_oThumbnail><format>4</format><aspect>1</aspect><first>false</first><width>1000</width><height>1000</height></m_oThumbnail>");

.docbuilder

builder.SaveFile("image", "./thumbnail.png", "<m_oThumbnail><format>4</format><aspect>1</aspect><first>false</first><width>1000</width><height>1000</height></m_oThumbnail>");