> 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/advancedimagingtest.md).

# Convert DICOM to PDF - AdvancedImaging

Sample code demonstrates how to use the Apryse Advanced Imaging module for direct, high-quality conversion from DICOM, and other advanced image formats to PDF. Samples provided in Python, C++, C#, Jav

Sample code demonstrates how to use the Apryse Advanced Imaging module for direct, high-quality conversion from DICOM to PDF. Samples provided in Python, C++, C#, Java, Node.js (JavaScript), and VB. Learn more about our [Server SDK](/core/get-started/get-started.md) and [PDF Conversion Library](/core/page-manipulation/manipulation.md).

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

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

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;

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

namespace AdvancedImagingTestCS
{
    /// <summary>
    //---------------------------------------------------------------------------------------
    // The following sample illustrates how to convert AdvancedImaging documents (such as dcm,
    // png) to pdf 
    //---------------------------------------------------------------------------------------
    /// </summary>
    class Class1
    {
        private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
        static Class1() {}


        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            // The first step in every application using PDFNet is to initialize the 
            // library and set the path to common PDF resources. The library is usually 
            // initialized only once, but calling Initialize() multiple times is also fine.
            PDFNet.Initialize(PDFTronLicense.Key);
            PDFNet.AddResourceSearchPath("../../../../../Lib/");
            if (!AdvancedImagingModule.IsModuleAvailable())
            {
                Console.WriteLine();
                Console.WriteLine("Unable to run AdvancedImagingTest: Apryse SDK AdvancedImaging module not available.");
                Console.WriteLine("---------------------------------------------------------------");
                Console.WriteLine("The AdvancedImaging module is an optional add-on, available for download");
                Console.WriteLine("at http://www.pdftron.com/. If you have already downloaded this");
                Console.WriteLine("module, ensure that the SDK is able to find the required files");
                Console.WriteLine("using the PDFNet::AddResourceSearchPath() function.");
                Console.WriteLine();
            }

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

            string dicom_input_file = "xray.dcm";
            string heic_input_file = "jasper.heic";
            string psd_input_file = "tiger.psd";
            string output_ext = ".pdf";

            Console.WriteLine("Example of advanced imaging module:");
            try
            {
                using (PDFDoc pdfdoc = new PDFDoc())
                {
                    AdvancedImagingConvertOptions opts = new AdvancedImagingConvertOptions();
                    opts.SetDefaultDPI(72.0);

                    pdftron.PDF.Convert.FromDICOM(pdfdoc, input_path + dicom_input_file, opts);
                    pdfdoc.Save(output_path + dicom_input_file + output_ext, SDFDoc.SaveOptions.e_remove_unused);
                }

                using (PDFDoc pdfdoc = new PDFDoc())
                {
                    pdftron.PDF.Convert.ToPdf(pdfdoc, input_path + heic_input_file);
                    pdfdoc.Save(output_path + heic_input_file + output_ext, SDFDoc.SaveOptions.e_remove_unused);
                }

                using (PDFDoc pdfdoc = new PDFDoc())
                {
                    pdftron.PDF.Convert.ToPdf(pdfdoc, input_path + psd_input_file);
                    pdfdoc.Save(output_path + psd_input_file + output_ext, SDFDoc.SaveOptions.e_remove_unused);
                }

                Console.WriteLine("Done.");
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }
            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 convert AdvancedImaging documents to PDF format 
// 
// The AdvancedImaging module is an optional PDFNet Add-on that can be used to convert AdvancedImaging
// documents into PDF documents
//
// The Apryse SDK AdvancedImaging module can be downloaded from http://www.pdftron.com/
//---------------------------------------------------------------------------------------

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

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

	exports.runAdvancedImagingTest = () => {

		const main = async () => {

			try {
				await PDFNet.addResourceSearchPath('../../lib/');

				if (!await PDFNet.AdvancedImagingModule.isModuleAvailable()) {
					console.log('\nUnable to run AdvancedImagingTest: Apryse SDK AdvancedImaging module not available.');
					console.log('---------------------------------------------------------------');
					console.log('The AdvancedImaging module is an optional add-on, available for download');
					console.log('at http://www.pdftron.com/. If you have already downloaded this');
					console.log('module, ensure that the SDK is able to find the required files');
					console.log('using the PDFNet::AddResourceSearchPath() function.\n');

					return;
				}

				// Relative path to the folder containing test files.
				const inputPath = '../TestFiles/AdvancedImaging/';
				const outputPath = '../TestFiles/Output/';

				const dicom_input_file = 'xray.dcm';
				const heic_input_file = 'jasper.heic';
				const psd_input_file = 'tiger.psd';
				const output_ext = '.pdf';
				
				const doc = await PDFNet.PDFDoc.create();
				doc.initSecurityHandler();

				const opts = new PDFNet.Convert.AdvancedImagingConvertOptions();
				opts.setDefaultDPI(72);
				await PDFNet.Convert.fromDICOM(doc, inputPath + dicom_input_file, opts);
				await doc.save(outputPath + dicom_input_file + output_ext, PDFNet.SDFDoc.SaveOptions.e_linearized);

				const doc2 = await PDFNet.PDFDoc.create();
				doc2.initSecurityHandler();

				await PDFNet.Convert.toPdf(doc2, inputPath + heic_input_file);
				await doc2.save(outputPath + heic_input_file + output_ext, PDFNet.SDFDoc.SaveOptions.e_linearized);

				const doc3 = await PDFNet.PDFDoc.create();
				doc3.initSecurityHandler();

				await PDFNet.Convert.toPdf(doc3, inputPath + psd_input_file);
				await doc3.save(outputPath + psd_input_file + output_ext, PDFNet.SDFDoc.SaveOptions.e_linearized);
			} catch (err) {
				console.log(err);
			}
		};
		PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) {
			console.log('Error: ' + JSON.stringify(error));
		}).then(function () { return PDFNet.shutdown(); });
	};
	exports.runAdvancedImagingTest();
})(exports);
// eslint-disable-next-line spaced-comment
//# sourceURL=AdvancedImagingTest.js
```

{% 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.*;
import com.pdftron.sdf.Obj;
import com.pdftron.sdf.ObjSet;
import com.pdftron.sdf.SDFDoc;

//---------------------------------------------------------------------------------------
// The following sample illustrates how to convert AdvancedImaging documents to PDF format using
// the AdvancedImaging class.
// 
// 'pdftron.PDF.AdvancedImaging' is an optional PDFNet Add-On utility class that can be 
// used to convert AdvancedImaging documents into PDF documents by using an external module (AdvancedImaging).
//
// AdvancedImaging modules can be downloaded from http://www.pdftron.com/pdfnet/downloads.html.
//---------------------------------------------------------------------------------------
public class AdvancedImagingTest {

	public static void main(String[] args)
	{
		System.getProperty("sun.arch.data.model");

		PDFNet.initialize(PDFTronLicense.Key());
		try {
			PDFNet.addResourceSearchPath("../../../Lib/");
			if(!AdvancedImagingModule.isModuleAvailable())
			{
				System.out.println();
				System.out.println("Unable to run AdvancedImagingTest: Apryse SDK AdvancedImaging module not available.");
				System.out.println("---------------------------------------------------------------");
				System.out.println("The AdvancedImaging module is an optional add-on, available for download");
				System.out.println("at http://www.pdftron.com/. If you have already downloaded this");
				System.out.println("module, ensure that the SDK is able to find the required files");
				System.out.println("using the PDFNet::AddResourceSearchPath() function." );
				System.out.println();
			}
		} catch (PDFNetException e) {
			System.out.println("AdvancedImaging module not available, error:");
			e.printStackTrace();
			System.out.println(e);
		}

		// Relative path to the folder containing test files.
		String input_path = "../../TestFiles/AdvancedImaging/";
		String output_path = "../../TestFiles/Output/";
		// The input file names
		String dicom_input_file = "xray.dcm";
		String heic_input_file  = "jasper.heic";
		String psd_input_file = "tiger.psd";
		String outputFile;

		System.out.println("-------------------------------------------------");
		System.out.println("Converting DICOM document to PDF");
	
		try (PDFDoc doc = new PDFDoc()) {
			AdvancedImagingConvertOptions opts = new AdvancedImagingConvertOptions();
 			opts.setDefaultDPI(72.0);
			Convert.fromDICOM(doc, input_path + dicom_input_file, opts);
			outputFile = output_path + dicom_input_file + ".pdf";
			doc.save(outputFile, SDFDoc.SaveMode.LINEARIZED, null);
			System.out.println("Result saved in " + outputFile);
		} catch (PDFNetException e) {
			System.out.println("Unable to convert DICOM document, error:");
			e.printStackTrace();
			System.out.println(e);
		}
		System.out.println("Converting HEIC document to PDF");
		try (PDFDoc doc = new PDFDoc()) {
			Convert.toPdf(doc, input_path + heic_input_file);
			outputFile = output_path + heic_input_file + ".pdf";
			doc.save(outputFile, SDFDoc.SaveMode.LINEARIZED, null);
			System.out.println("Result saved in " + outputFile);
		} catch (PDFNetException e) {
			System.out.println("Unable to convert HEIC document, error:");
			e.printStackTrace();
			System.out.println(e);
		}

		System.out.println("Converting PSD document to PDF");
		try (PDFDoc doc = new PDFDoc()) {
			Convert.toPdf(doc, input_path + psd_input_file);
			outputFile = output_path + psd_input_file + ".pdf";
			doc.save(outputFile, SDFDoc.SaveMode.LINEARIZED, null);
			System.out.println("Result saved in " + outputFile);
		} catch (PDFNetException e) {
			System.out.println("Unable to convert PSD document, error:");
			e.printStackTrace();
			System.out.println(e);
		}

		System.out.println("Done.");
		PDFNet.terminate();
	}
}
```

{% 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 <PDF/PDFNet.h>
#include <PDF/PDFDoc.h>
#include <PDF/Convert.h>
#include <PDF/AdvancedImagingModule.h>
#include <PDF/AdvancedImagingConvertOptions.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include "../../LicenseKey/CPP/LicenseKey.h"

using namespace pdftron;
using namespace pdftron::SDF;
using namespace PDF;
using namespace std;


//---------------------------------------------------------------------------------------
// The following sample illustrates how to convert AdvancedImaging documents to PDF format 
// 
// The AdvancedImaging module is an optional PDFNet Add-on that can be used to convert AdvancedImaging
// documents into PDF documents
//
// The Apryse SDK AdvancedImaging module can be downloaded from http://www.pdftron.com/
//---------------------------------------------------------------------------------------

UString inputPath("../../TestFiles/AdvancedImaging/");
UString outputPath("../../TestFiles/Output/");


int main(int argc, char *argv[])
{
	int ret = 0;
	
	try
	{
		// The first step in every application using PDFNet is to initialize the 
		// library and set the path to common PDF resources. The library is usually 
		// initialized only once, but calling Initialize() multiple times is also fine.
		PDFNet::Initialize(LicenseKey);
		PDFNet::AddResourceSearchPath("../../../Lib/");

		if(!AdvancedImagingModule::IsModuleAvailable())
		{
			cout << endl;
			cout << "Unable to run AdvancedImagingTest: Apryse SDK AdvancedImaging module not available." << endl;
			cout << "---------------------------------------------------------------" << endl;
			cout << "The AdvancedImaging module is an optional add-on, available for download" << endl;
			cout << "at http://www.pdftron.com/. If you have already downloaded this" << endl;
			cout << "module, ensure that the SDK is able to find the required files" << endl;
			cout << "using the PDFNet::AddResourceSearchPath() function." << endl << endl;
			return 0;
		}

		typedef struct
		{
			UString inputFile, outputFile;
		} TestFile;
		
		UString dicom_input_file, heic_input_file, psd_input_file;

		dicom_input_file = "xray.dcm";
		heic_input_file = "jasper.heic";
		psd_input_file = "tiger.psd";

		try
		{
			PDFDoc pdfdoc_dicom;
			AdvancedImagingConvertOptions opts;
			opts.SetDefaultDPI(72);
			Convert::FromDICOM(pdfdoc_dicom, inputPath + dicom_input_file, &opts);
			pdfdoc_dicom.Save(outputPath + dicom_input_file + UString(".pdf"), SDF::SDFDoc::e_linearized, NULL);
		}
		catch (Common::Exception& e)
		{
			cout << "Unable to convert DICOM test file" << endl;
			cout << e << endl;
			ret = 1;
		}
		catch (...)
		{
			cout << "Unknown Exception" << endl;
			ret = 1;
		}

		try
		{
			PDFDoc pdfdoc_heic;
			Convert::ToPdf(pdfdoc_heic, inputPath + heic_input_file);
			pdfdoc_heic.Save(outputPath + heic_input_file + UString(".pdf"), SDF::SDFDoc::e_linearized, NULL);
		}
		catch (Common::Exception& e)
		{
			cout << "Unable to convert the HEIC test file" << endl;
			cout << e << endl;
			ret = 1;
		}
		catch (...)
		{
			cout << "Unknown Exception" << endl;
			ret = 1;
		}

		try
		{
			PDFDoc pdfdoc_psd;
			Convert::ToPdf(pdfdoc_psd, inputPath + psd_input_file);
			pdfdoc_psd.Save(outputPath + psd_input_file + UString(".pdf"), SDF::SDFDoc::e_linearized, NULL);
		}
		catch (Common::Exception& e)
		{
			cout << "Unable to convert the PSD test file" << endl;
			cout << e << endl;
			ret = 1;
		}
		catch (...)
		{
			cout << "Unknown Exception" << endl;
			ret = 1;
		}


        PDFNet::Terminate();
	}
	catch (Common::Exception& e)
	{
		cout << e << endl;
		ret = 1;
	}
	catch (...)
	{
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	return ret;
}
```

{% 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 test files.
input_path = "../../TestFiles/AdvancedImaging/"
output_path = "../../TestFiles/Output/"

# ---------------------------------------------------------------------------------------
# The following sample illustrates how to use Advanced Imaging module
# --------------------------------------------------------------------------------------

def main():

    # The first step in every application using PDFNet is to initialize the
    # library and set the path to common PDF resources. The library is usually
    # initialized only once, but calling Initialize() multiple times is also fine.
    PDFNet.Initialize(LicenseKey)

    # The location of the Advanced Imaging Module
    PDFNet.AddResourceSearchPath("../../../PDFNetC/Lib/")

    if not AdvancedImagingModule.IsModuleAvailable():

        print("""
        Unable to run AdvancedImaging2PDFTest: PDFTron SDK Advanced Imaging module not available.
        ---------------------------------------------------------------
        The Advanced Imaging module is an optional add-on, available for download
        at https://dev.apryse.com/. If you have already downloaded this
        module, ensure that the SDK is able to find the required files
        using the PDFNet::AddResourceSearchPath() function.""")

    else:

        inputFileName1 = "xray.dcm"
        outputFileName1 = inputFileName1 + ".pdf"
        doc1 = PDFDoc()
        Convert.FromDICOM(doc1, input_path + inputFileName1, None)
        doc1.Save(output_path + outputFileName1, 0)

        inputFileName2 = "jasper.heic"
        outputFileName2 = inputFileName2 + ".pdf"
        doc2 = PDFDoc()
        Convert.ToPdf(doc2, input_path + inputFileName2)
        doc2.Save(output_path + outputFileName2, 0)

        inputFileName3 = "tiger.psd"
        outputFileName3 = inputFileName3 + ".pdf"
        doc3 = PDFDoc()
        Convert.ToPdf(doc3, input_path + inputFileName3)
        doc3.Save(output_path + outputFileName3, 0)

        print("DCM, HEIC and PSD image conversion example")
    PDFNet.Terminate()


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

{% endcode %}
{% endtab %}

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

```vb
Imports System
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
Imports pdftron
Imports pdftron.Common
Imports pdftron.PDF
Imports pdftron.SDF

Namespace AdvancedImagingTestVB
    Class Class1
        Private Shared pdfNetLoader As pdftron.PDFNetLoader = pdftron.PDFNetLoader.Instance()

        Shared Sub Main(ByVal args As String())
            PDFNet.Initialize(PDFTronLicense.Key)
            PDFNet.AddResourceSearchPath("../../../../../Lib/")

            If Not AdvancedImagingModule.IsModuleAvailable() Then
                Console.WriteLine()
                Console.WriteLine("Unable to run AdvancedImagingTest: Apryse SDK AdvancedImaging module not available.")
                Console.WriteLine("---------------------------------------------------------------")
                Console.WriteLine("The AdvancedImaging module is an optional add-on, available for download")
                Console.WriteLine("at http://www.pdftron.com/. If you have already downloaded this")
                Console.WriteLine("module, ensure that the SDK is able to find the required files")
                Console.WriteLine("using the PDFNet::AddResourceSearchPath() function.")
                Console.WriteLine()
            End If

            Dim input_path As String = "../../../../TestFiles/AdvancedImaging/"
            Dim output_path As String = "../../../../TestFiles/Output/"

            Dim dicom_input_file As String = "xray.dcm"
            Dim heic_input_file As String = "jasper.heic"
            Dim psd_input_file As String = "tiger.psd"

            Console.WriteLine("Example of advanced imaging module:")

            Try

                Using pdfdoc As PDFDoc = New PDFDoc()
        
                    Dim opts As AdvancedImagingConvertOptions = New AdvancedImagingConvertOptions()
                    opts.SetDefaultDPI(72.0)

                    pdftron.PDF.Convert.FromDICOM(pdfdoc, input_path & dicom_input_file, opts)
                    pdfdoc.Save(output_path & dicom_input_file & ".pdf", SDFDoc.SaveOptions.e_linearized)

                End Using

                Using pdfdoc As PDFDoc = New PDFDoc()

                    pdftron.PDF.Convert.ToPdf(pdfdoc, input_path & heic_input_file)
                    pdfdoc.Save(output_path & heic_input_file & ".pdf", SDFDoc.SaveOptions.e_linearized)

                End Using

                Using pdfdoc As PDFDoc = New PDFDoc()

                    pdftron.PDF.Convert.ToPdf(pdfdoc, input_path & psd_input_file)
                    pdfdoc.Save(output_path & psd_input_file & ".pdf", SDFDoc.SaveOptions.e_linearized)

                End Using

                Console.WriteLine("Done.")
            Catch e As PDFNetException
                Console.WriteLine(e.Message)
            End Try
            PDFNet.Terminate()
        End Sub
    End Class
End Namespace
```

{% 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/advancedimagingtest.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.
