Some test text!

Discord Logo

Chat with us

PDFTron is now Apryse, learn more here.

Python DICOM to PDF converter

More languages

More languages
C# (.NET Core)
JS (Node.js)

Sample Python code demonstrates how to use the PDFTron Advanced Imaging module for direct, high-quality conversion from DICOM to PDF. Learn more about our Python PDF Library and PDF Conversion Library.

Get Started Samples Download

To run this sample, get started with a free trial of Apryse SDK.

# Copyright (c) 2001-2022 by PDFTron Systems Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.

import site
import sys
from PDFNetPython import *

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.

    # The location of the Advanced Imaging Module

    if not AdvancedImagingModule.IsModuleAvailable():

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


        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")

if __name__ == '__main__':