> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/core/get-started/samples/officetemplatetest.md).

# Generate Document via Office Template - OfficeTemplate

Sample code for using Apryse Server SDK to generate a PDF from an Office document template and a JSON string.  Does not require any external dependencies or MS Office licenses.  Samples provided in Py

Sample code for using Apryse SDK to generate a PDF from an Office document template and a JSON string. Does not require any external dependencies or MS Office licenses. Samples provided in Python, C++, C#, Java, Node.js (JavaScript), PHP, Ruby, Go and VB. Learn more about our [Server SDK](/core/get-started/get-started.md) and [Office Template Generation](/core/create/generate-via-template.md).

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
//
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
//

using System;
using System.Drawing;
using System.Drawing.Drawing2D;

using pdftron;
using pdftron.Common;
using pdftron.Filters;
using pdftron.SDF;
using pdftron.PDF;

namespace OfficeTemplateTestCS
{
    /// <summary>
    ///---------------------------------------------------------------------------------------
    /// The following sample illustrates how to use the PDF::Convert utility class 
    /// to convert MS Office files to PDF and replace templated tags present in the document
    /// with content supplied via json
    ///
    /// For a detailed specification of the template format and supported features,
    /// see: https://docs.apryse.com/core/guides/generate-via-template/data-model/
    ///
    /// This conversion is performed entirely within the PDFNet and has *no* external or
    /// system dependencies dependencies
    ///
    /// Please contact us if you have any questions.    
    ///---------------------------------------------------------------------------------------
    /// </summary>



    class Class1
    {
        private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
        static Class1() { }

        static String input_path = "../../../../TestFiles/";
        static String output_path = "../../../../TestFiles/Output/";
        static String json = "{\"dest_given_name\": \"Janice N.\", \"dest_street_address\": \"187 Duizelstraat\", \"dest_surname\": \"Symonds\", \"dest_title\": \"Ms.\", \"land_location\": \"225 Parc St., Rochelle, QC \"," +
                "\"lease_problem\": \"According to the city records, the lease was initiated in September 2010 and never terminated\", \"logo\": {\"image_url\": \"" + input_path + "logo_red.png\", \"width\" : 64, \"height\" : 64}," +
                "\"sender_name\": \"Arnold Smith\"}";

        static String input_filename = "SYH_Letter.docx";
        static String output_filename = "SYH_Letter.pdf";

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            PDFNet.Initialize(PDFTronLicense.Key);

            try
            {
                // Create a TemplateDocument object from an input office file.
                using (TemplateDocument template_doc = pdftron.PDF.Convert.CreateOfficeTemplate(input_path + input_filename, null))
                {
                    // Fill the template with data from a JSON string, producing a PDF document.
                    PDFDoc pdfdoc = template_doc.FillTemplateJson(json);

                    // Save the PDF to a file.
                    pdfdoc.Save(output_path + output_filename, SDFDoc.SaveOptions.e_linearized);

                    // And we're done!
                    Console.WriteLine("Saved " + output_filename);
                }
            }
            catch (pdftron.Common.PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Unrecognized Exception: " + e.Message);
            }

            PDFNet.Terminate();
            Console.WriteLine("Done.");
        }
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
//------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//------------------------------------------------------------------------------

#include <iostream>
#include <PDF/PDFNet.h>
#include <PDF/Convert.h>
#include <PDF/OfficeToPDFOptions.h>
#include "../../LicenseKey/CPP/LicenseKey.h"

//------------------------------------------------------------------------------
// The following sample illustrates how to use the PDF::Convert utility class 
// to convert MS Office files to PDF and replace templated tags present in the document
// with content supplied via json
//
// For a detailed specification of the template format and supported features,
// see: https://docs.apryse.com/core/guides/generate-via-template/data-model/
//
// This conversion is performed entirely within the PDFNet and has *no* 
// external or system dependencies -- Conversion results will be
// the same whether on Windows, Linux or Android.
//
// Please contact us if you have any questions.	
//------------------------------------------------------------------------------

using namespace pdftron;
using namespace PDF;

UString input_path = "../../TestFiles/";
UString output_path = "../../TestFiles/Output/";


int main(int argc, char *argv[])
{
	// The first step in every application using PDFNet is to initialize the 
	// library. The library is usually initialized only once, but calling 
	// Initialize() multiple times is also fine.
	int ret = 0;

	PDFNet::Initialize(LicenseKey);
	PDFNet::SetResourcesPath("../../../Resources");

	UString input_filename = "SYH_Letter.docx";
	UString output_filename = "SYH_Letter.pdf";

	UString json(
		"{\"dest_given_name\": \"Janice N.\", \"dest_street_address\": \"187 Duizelstraat\", \"dest_surname\": \"Symonds\", \"dest_title\": \"Ms.\", \"land_location\": \"225 Parc St., Rochelle, QC \","
		"\"lease_problem\": \"According to the city records, the lease was initiated in September 2010 and never terminated\", \"logo\": {\"image_url\": \"" + input_path + "logo_red.png\", \"width\" : 64, \"height\" : 64},"
		"\"sender_name\": \"Arnold Smith\"}"
	);

	try
	{
		// Create a TemplateDocument object from an input office file.
		TemplateDocument template_doc = Convert::CreateOfficeTemplate(input_path + input_filename, NULL);

		// Fill the template with data from a JSON string, producing a PDF document.
		PDFDoc pdf = template_doc.FillTemplateJson(json);

		// Save the PDF to a file.
		pdf.Save(output_path + output_filename, SDF::SDFDoc::e_linearized, NULL);

		// And we're done!
		std::cout << "Saved " << output_filename << std::endl;
	}
	catch (Common::Exception& e)
	{
		std::cout << e << std::endl;
		ret = 1;
	}
	catch (...)
	{
		std::cout << "Unknown Exception" << std::endl;
		ret = 1;
	}

	PDFNet::Terminate();
	std::cout << "Done.\n";
	return ret;
}
```

{% endcode %}
{% endtab %}

{% tab title="Go" %}
{% code lineNumbers="true" %}

```go
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------

package main
import (
	"fmt"
	. "pdftron"
)

import  "pdftron/Samples/LicenseKey/GO"

//------------------------------------------------------------------------------
// The following sample illustrates how to use ConvertOfficeToPDF
// to convert MS Office files to PDF and replace templated tags present in the document
// with content supplied via json
//
// For a detailed specification of the template format and supported features,
// see: https://docs.apryse.com/core/guides/generate-via-template/data-model/
//
// This conversion is performed entirely within the PDFNet and has *no*
// external or system dependencies -- Conversion results will be
// the same whether on Windows, Linux or Android.
//
// Please contact us if you have any questions.
//------------------------------------------------------------------------------

// Relative path to the folder containing the test files.
var inputPath = "../../TestFiles/"
var outputPath = "../../TestFiles/Output/"

func main(){
    // The first step in every application using PDFNet is to initialize the
    // library. The library is usually initialized only once, but calling
    // Initialize() multiple times is also fine.
    PDFNetInitialize(PDFTronLicense.Key)
    PDFNetSetResourcesPath("../../Resources")

    var inputFileName = "SYH_Letter.docx"
    var outputFileName = "SYH_Letter.pdf"
    var json = `
    {
		"dest_given_name": "Janice N.",
        "dest_street_address": "187 Duizelstraat",
        "dest_surname": "Symonds",
        "dest_title": "Ms.",
        "land_location": "225 Parc St., Rochelle, QC ",
        "lease_problem": "According to the city records, the lease was initiated in September 2010 and never terminated",
        "logo": { "image_url": "` + inputPath + `logo_red.png", "width" : 64, "height":  64 },
        "sender_name": "Arnold Smith"
	}`;

    options :=  NewOfficeToPDFOptions()

    options.SetTemplateParamsJson(json)

    // Start with a PDFDoc (the conversion destination)
    pdfdoc := NewPDFDoc()

    // perform the conversion with template delimiters and content dictionary
    ConvertOfficeToPDF(pdfdoc, inputPath + inputFileName, options)

    // save the result
    pdfdoc.Save(outputPath + outputFileName, uint(SDFDocE_linearized))

    // And we're done!
    fmt.Println("Saved " + outputFileName )
}
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

import com.pdftron.common.PDFNetException;
import com.pdftron.pdf.Convert;
import com.pdftron.pdf.TemplateDocument;
import com.pdftron.pdf.PDFDoc;
import com.pdftron.pdf.PDFNet;
import com.pdftron.pdf.OfficeToPDFOptions;
import com.pdftron.sdf.SDFDoc;

//---------------------------------------------------------------------------------------
// The following sample illustrates how to use the PDF::Convert utility class 
// to convert MS Office files to PDF and replace templated tags present in the document
// with content supplied via json
//
// For a detailed specification of the template format and supported features,
// see: https://docs.apryse.com/core/guides/generate-via-template/data-model/
//
// This conversion is performed entirely within the PDFNet and has *no* external or
// system dependencies dependencies -- Conversion results will be the same whether
// on Windows, Linux or Android.
//
// Please contact us if you have any questions. 
//---------------------------------------------------------------------------------------
public class OfficeTemplateTest {

    static String input_path = "../../TestFiles/";
    static String output_path = "../../TestFiles/Output/";
    static String input_filename = "SYH_Letter.docx";
    static String output_filename = "SYH_Letter.pdf";

    public static void main(String[] args) {
        PDFNet.initialize(PDFTronLicense.Key());
        PDFNet.setResourcesPath("../../../Resources");

        try {
            String json = new StringBuilder()
                .append("{\"dest_given_name\": \"Janice N.\", \"dest_street_address\": \"187 Duizelstraat\", \"dest_surname\": \"Symonds\", \"dest_title\": \"Ms.\", \"land_location\": \"225 Parc St., Rochelle, QC \",")
                .append("\"lease_problem\": \"According to the city records, the lease was initiated in September 2010 and never terminated\", \"logo\": {\"image_url\": \"" + input_path + "logo_red.png\", \"width\" : 64, \"height\" : 64},")
                .append("\"sender_name\": \"Arnold Smith\"}").toString();

            // Create a TemplateDocument object from an input office file.
            TemplateDocument template_doc = Convert.createOfficeTemplate(input_path + input_filename, null);

            // Fill the template with data from a JSON string, producing a PDF document.
            try (PDFDoc pdfdoc = template_doc.fillTemplateJson(json)) {

                // Save the PDF to a file.
                pdfdoc.save(output_path + output_filename, SDFDoc.SaveMode.INCREMENTAL, null);
            }
        }
        catch (PDFNetException e) {
            e.printStackTrace();
            System.out.println(e);
        }

        // And we're done!
        System.out.println("Saved " + output_filename);
        System.out.println("Done.");

        PDFNet.terminate();
    }

}
```

{% endcode %}
{% endtab %}

{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// The following sample illustrates how to use the PDF::Convert utility class
// to convert MS Office files to PDF and replace templated tags present in the document
// with content supplied via json
//
// For a detailed specification of the template format and supported features,
// see: https://docs.apryse.com/core/guides/generate-via-template/data-model/
//
// This conversion is performed entirely within the PDFNet and has *no*
// external or system dependencies -- Conversion results will be
// the same whether on Windows, Linux or Android.
//
// Please contact us if you have any questions.
//------------------------------------------------------------------------------

const { PDFNet } = require('@pdftron/pdfnet-node');
const PDFTronLicense = require('../LicenseKey/LicenseKey');

((exports) => {
  'use strict';

  exports.runOfficeTemplateTest = () => {

    const inputPath = '../TestFiles/';
    const outputPath = inputPath + 'Output/';
    const inputFilename = 'SYH_Letter.docx'
    const outputFilename = 'SYH_Letter.pdf'

    const main = async () => {

      PDFNet.addResourceSearchPath('../Resources');

      try {
        const options = new PDFNet.Convert.OfficeToPDFOptions();

        const json = JSON.stringify({
          'dest_given_name': 'Janice N.',
          'dest_street_address': "187 Duizelstraat",
          'dest_surname': 'Symonds',
          'dest_title': 'Ms.',
          'land_location': '225 Parc St., Rochelle, QC ',
          'lease_problem': 'According to the city records, the lease was initiated in September 2010 and never terminated',
          'logo': { 'image_url': inputPath + 'logo_red.png', 'width' : 64, 'height':  64 },
          'sender_name': 'Arnold Smith'
        });

        // Create a TemplateDocument object from an input office file.
        const templateDoc = await PDFNet.Convert.createOfficeTemplateWithPath(inputPath + inputFilename, options);

        // Fill the template with data from a JSON string, producing a PDF document.
        const pdfdoc = await templateDoc.fillTemplateJson(json);

        // Save the PDF to a file.
        await pdfdoc.save(outputPath + outputFilename, PDFNet.SDFDoc.SaveOptions.e_linearized);

        // And we're done!
        console.log('Saved ' + outputFilename);

      } catch (err) {
        console.log(err);
      }

      console.log('Done.');
    };

    PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) {
      console.log('Error: ' + JSON.stringify(error));
    }).then(function () { return PDFNet.shutdown(); });

  };
  exports.runOfficeTemplateTest();
})(exports);
// eslint-disable-next-line spaced-comment
//# sourceURL=OfficeTemplateTest.js
```

{% endcode %}
{% endtab %}

{% tab title="PHP" %}
{% code lineNumbers="true" %}

```php
<?php
//------------------------------------------------------------------------------
// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//------------------------------------------------------------------------------
if(file_exists("../../../PDFNetC/Lib/PDFNetPHP.php"))
include("../../../PDFNetC/Lib/PDFNetPHP.php");
include("../../LicenseKey/PHP/LicenseKey.php");

// Relative path to the folder containing the test files.
$input_path = getcwd()."/../../TestFiles/";
$output_path = $input_path."Output/";

//------------------------------------------------------------------------------
// The following sample illustrates how to use the PDF::Convert utility class
// to convert MS Office files to PDF and replace templated tags present in the document
// with content supplied via json
//
// For a detailed specification of the template format and supported features,
// see: https://docs.apryse.com/core/guides/generate-via-template/data-model/
//
// This conversion is performed entirely within the PDFNet and has *no*
// external or system dependencies -- Conversion results will be
// the same whether on Windows, Linux or Android.
//
// Please contact us if you have any questions.
//------------------------------------------------------------------------------

function main()
{
	// The first step in every application using PDFNet is to initialize the
	// library. The library is usually initialized only once, but calling
	// Initialize() multiple times is also fine.
	global $LicenseKey;
	PDFNet::Initialize($LicenseKey);
	PDFNet::SetResourcesPath("../../../Resources");

	global $input_path, $output_path;
	$input_filename = 'SYH_Letter.docx';
	$output_filename = 'SYH_Letter.pdf';

	$json = '
	{
		"dest_given_name": "Janice N.",
        "dest_street_address": "187 Duizelstraat",
        "dest_surname": "Symonds",
        "dest_title": "Ms.",
        "land_location": "225 Parc St., Rochelle, QC ",
        "lease_problem": "According to the city records, the lease was initiated in September 2010 and never terminated",
        "logo": { "image_url": "' . $input_path . 'logo_red.png", "width" : 64, "height":  64 },
        "sender_name": "Arnold Smith"
	}';

	// Create a TemplateDocument object from an input office file.
	$template_doc = Convert::CreateOfficeTemplate($input_path . $input_filename, NULL);

	// Fill the template with data from a JSON string, producing a PDF document.
	$pdfdoc = $template_doc->FillTemplateJson($json);

	// Save the PDF to a file.
	$pdfdoc->Save($output_path.$output_filename, SDFDoc::e_linearized);

	// And we're done!
	echo nl2br("Saved ".$output_filename . "\n");
	echo nl2br("Done.\n");
}

main()

?>
```

{% endcode %}
{% endtab %}

{% tab title="Python" %}
{% code lineNumbers="true" %}

```python
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

import site
site.addsitedir("../../../PDFNetC/Lib")
import sys
from PDFNetPython import *

sys.path.append("../../LicenseKey/PYTHON")
from LicenseKey import *

# Relative path to the folder containing the test files.
input_path = "../../TestFiles/"
output_path = "../../TestFiles/Output/"

#------------------------------------------------------------------------------
# The following sample illustrates how to use the PDF.Convert utility class
# to convert MS Office files to PDF and replace templated tags present in the document
# with content supplied via json
#
# For a detailed specification of the template format and supported features,
# see: https://docs.apryse.com/core/guides/generate-via-template/data-model/
#
# This conversion is performed entirely within the PDFNet and has *no*
# external or system dependencies -- Conversion results will be
# the same whether on Windows, Linux or Android.
#
# Please contact us if you have any questions.
#------------------------------------------------------------------------------

def main():
    # The first step in every application using PDFNet is to initialize the
    # library. The library is usually initialized only once, but calling
    # Initialize() multiple times is also fine.
    PDFNet.Initialize(LicenseKey)
    PDFNet.SetResourcesPath("../../../Resources")

    input_filename = "SYH_Letter.docx"
    output_filename = "SYH_Letter.pdf"

    json = """
    {{
        "dest_given_name": "Janice N.",
        "dest_street_address": "187 Duizelstraat",
        "dest_surname": "Symonds",
        "dest_title": "Ms.",
        "land_location": "225 Parc St., Rochelle, QC ",
        "lease_problem": "According to the city records, the lease was initiated in September 2010 and never terminated",
        "logo": {{ "image_url": "{0}logo_red.png", "width" : 64, "height":  64 }},
        "sender_name": "Arnold Smith"
    }}
    """.format(input_path)

    # Create a TemplateDocument object from an input office file.
    template_doc = Convert.CreateOfficeTemplate(input_path + input_filename, None)

    # Fill the template with data from a JSON string, producing a PDF document.
    pdfdoc = template_doc.FillTemplateJson(json);

    # Save the PDF to a file.
    pdfdoc.Save(output_path + output_filename, SDFDoc.e_linearized)

    # And we're done!
    print("Saved " + output_filename )
    print("Done.")

if __name__ == '__main__':
    main()
```

{% endcode %}
{% endtab %}

{% tab title="Ruby" %}
{% code lineNumbers="true" %}

```ruby
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

require '../../../PDFNetC/Lib/PDFNetRuby'
include PDFNetRuby
require '../../LicenseKey/RUBY/LicenseKey'

$stdout.sync = true

#------------------------------------------------------------------------------
# The following sample illustrates how to use the PDF.Convert utility class
# to convert MS Office files to PDF and replace templated tags present in the document
# with content supplied via json
#
# For a detailed specification of the template format and supported features,
# see: https://docs.apryse.com/core/guides/generate-via-template/data-model/
#
# This conversion is performed entirely within the PDFNet and has *no*
# external or system dependencies -- Conversion results will be
# the same whether on Windows, Linux or Android.
#
# Please contact us if you have any questions.
#------------------------------------------------------------------------------

# Relative path to the folder containing the test files.
$inputPath = "../../TestFiles/"
$outputPath = "../../TestFiles/Output/"

def main()
    # The first step in every application using PDFNet is to initialize the
    # library. The library is usually initialized only once, but calling
    # Initialize() multiple times is also fine.
    PDFNet.Initialize(PDFTronLicense.Key)
    PDFNet.SetResourcesPath("../../../Resources")

    inputFilename = "SYH_Letter.docx"
    outputFilename = "SYH_Letter.pdf"

    json = '
    {
        "dest_given_name": "Janice N.",
        "dest_street_address": "187 Duizelstraat",
        "dest_surname": "Symonds",
        "dest_title": "Ms.",
        "land_location": "225 Parc St., Rochelle, QC ",
        "lease_problem": "According to the city records, the lease was initiated in September 2010 and never terminated",
        "logo": { "image_url": "%slogo_red.png", "width" : 64, "height":  64 },
        "sender_name": "Arnold Smith"
    }
    ' % $inputPath

    # Create a TemplateDocument object from an input office file.
    inputFile = $inputPath + inputFilename
    templateDoc = Convert.CreateOfficeTemplate(inputFile, nil)

    # Fill the template with data from a JSON string, producing a PDF document.
    pdfdoc = templateDoc.FillTemplateJson(json)

    # Save the PDF to a file.
    outputFile = $outputPath + outputFilename
    pdfdoc.Save(outputFile, SDFDoc::E_linearized)

    # And we're done!
    puts "Saved " + outputFilename
    puts "Done."
end

main()
```

{% endcode %}
{% endtab %}

{% tab title="VB" %}
{% code lineNumbers="true" %}

```vb
'
' Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
'

Imports pdftron
Imports pdftron.Common
Imports System.Text
Imports pdftron.SDF
Imports pdftron.PDF


' The following sample illustrates how to use the PDF::Convert utility class to convert 
' .docx files to PDF and replace templated tags present in the document with content supplied via json
'
' For a detailed specification of the template format and supported features,
' see: https://docs.apryse.com/core/guides/generate-via-template/data-model/
'
' This conversion is performed entirely within the PDFNet and has *no* external or
' system dependencies dependencies 
'
' Please contact us if you have any questions.	
Module OfficeToPDFTestVB
    Dim pdfNetLoader As PDFNetLoader
    Sub New()
        pdfNetLoader = pdftron.PDFNetLoader.Instance()
    End Sub

    ' Relative path to the folder containing test files.
    Dim input_path As String = "../../../../TestFiles/"
    Dim output_path As String = "../../../../TestFiles/Output/"
    Dim input_filename As String = "SYH_Letter.docx"
    Dim output_filename As String = "SYH_Letter.pdf"

    Sub Main()

        PDFNet.Initialize(PDFTronLicense.Key)

        Try
            ' Create a TemplateDocument object from an input office file.
            Using template_doc as TemplateDocument = pdftron.PDF.Convert.CreateOfficeTemplate(input_path + input_filename, Nothing)
                Dim builder As New StringBuilder()
                builder.Append("{""dest_given_name"": ""Janice N."", ""dest_street_address"": ""187 Duizelstraat"", ""dest_surname"": ""Symonds"", ""dest_title"": ""Ms."", ""land_location"": ""225 Parc St., Rochelle, QC "",")
                builder.Append("""lease_problem"":""According to the city records, the lease was initiated in September 2010 and never terminated"", ""logo"": {""image_url"": """ + input_path + "logo_red.png"", ""width"" : 64, ""height"" : 64},")
                builder.Append("""sender_name"": ""Arnold Smith""}")
                Dim json As String = builder.ToString()

                ' Fill the template with data from a JSON string, producing a PDF document.
                Dim pdfdoc As PDFDoc = template_doc.FillTemplateJson(json)

                ' Save the PDF to a file.
                pdfdoc.Save(output_path + output_filename, SDFDoc.SaveOptions.e_linearized)

                ' And we're done!
                Console.WriteLine("Saved " + output_filename)
                Console.WriteLine("Done.")
            End Using

        Catch ex As PDFNetException

            Console.WriteLine(ex.Message)

        Catch ex As Exception

            MsgBox(ex.Message)

        End Try

        PDFNet.Terminate()

    End Sub

End Module
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/core/get-started/samples/officetemplatetest.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
