Advanced Imaging - Convert DICOM to PDF - Python Sample Code

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 and PDF Conversion Library.

1#---------------------------------------------------------------------------------------
2# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
3# Consult LICENSE.txt regarding license information.
4#---------------------------------------------------------------------------------------
5
6import site
7site.addsitedir("../../../PDFNetC/Lib")
8import sys
9from PDFNetPython import *
10
11sys.path.append("../../LicenseKey/PYTHON")
12from LicenseKey import *
13
14# Relative path to the folder containing test files.
15input_path = "../../TestFiles/AdvancedImaging/"
16output_path = "../../TestFiles/Output/"
17
18# ---------------------------------------------------------------------------------------
19# The following sample illustrates how to use Advanced Imaging module
20# --------------------------------------------------------------------------------------
21
22def main():
23
24 # The first step in every application using PDFNet is to initialize the
25 # library and set the path to common PDF resources. The library is usually
26 # initialized only once, but calling Initialize() multiple times is also fine.
27 PDFNet.Initialize(LicenseKey)
28
29 # The location of the Advanced Imaging Module
30 PDFNet.AddResourceSearchPath("../../../PDFNetC/Lib/")
31
32 if not AdvancedImagingModule.IsModuleAvailable():
33
34 print("""
35 Unable to run AdvancedImaging2PDFTest: PDFTron SDK Advanced Imaging module not available.
36 ---------------------------------------------------------------
37 The Advanced Imaging module is an optional add-on, available for download
38 at https://dev.apryse.com/. If you have already downloaded this
39 module, ensure that the SDK is able to find the required files
40 using the PDFNet::AddResourceSearchPath() function.""")
41
42 else:
43
44 inputFileName1 = "xray.dcm"
45 outputFileName1 = inputFileName1 + ".pdf"
46 doc1 = PDFDoc()
47 Convert.FromDICOM(doc1, input_path + inputFileName1, None)
48 doc1.Save(output_path + outputFileName1, 0)
49
50 inputFileName2 = "jasper.heic"
51 outputFileName2 = inputFileName2 + ".pdf"
52 doc2 = PDFDoc()
53 Convert.ToPdf(doc2, input_path + inputFileName2)
54 doc2.Save(output_path + outputFileName2, 0)
55
56 inputFileName3 = "tiger.psd"
57 outputFileName3 = inputFileName3 + ".pdf"
58 doc3 = PDFDoc()
59 Convert.ToPdf(doc3, input_path + inputFileName3)
60 doc3.Save(output_path + outputFileName3, 0)
61
62 print("DCM, HEIC and PSD image conversion example")
63 PDFNet.Terminate()
64
65
66if __name__ == '__main__':
67 main()

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales