Sample C# code demonstrates how to use the Apryse Advanced Imaging module for direct, high-quality conversion from DICOM to PDF. Learn more about our Server SDK and PDF Conversion Library.
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6using System;
7using System.Drawing;
8using System.Drawing.Imaging;
9using System.Runtime.InteropServices;
10
11using pdftron;
12using pdftron.Common;
13using pdftron.PDF;
14using pdftron.SDF;
15
16namespace AdvancedImagingTestCS
17{
18 /// <summary>
19 //---------------------------------------------------------------------------------------
20 // The following sample illustrates how to convert AdvancedImaging documents (such as dcm,
21 // png) to pdf
22 //---------------------------------------------------------------------------------------
23 /// </summary>
24 class Class1
25 {
26 private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
27 static Class1() {}
28
29
30 /// <summary>
31 /// The main entry point for the application.
32 /// </summary>
33 static void Main(string[] args)
34 {
35 // The first step in every application using PDFNet is to initialize the
36 // library and set the path to common PDF resources. The library is usually
37 // initialized only once, but calling Initialize() multiple times is also fine.
38 PDFNet.Initialize(PDFTronLicense.Key);
39 PDFNet.AddResourceSearchPath("../../../../../Lib/");
40 if (!AdvancedImagingModule.IsModuleAvailable())
41 {
42 Console.WriteLine();
43 Console.WriteLine("Unable to run AdvancedImagingTest: Apryse SDK AdvancedImaging module not available.");
44 Console.WriteLine("---------------------------------------------------------------");
45 Console.WriteLine("The AdvancedImaging module is an optional add-on, available for download");
46 Console.WriteLine("at http://www.pdftron.com/. If you have already downloaded this");
47 Console.WriteLine("module, ensure that the SDK is able to find the required files");
48 Console.WriteLine("using the PDFNet::AddResourceSearchPath() function.");
49 Console.WriteLine();
50 }
51
52 // Relative path to the folder containing test files.
53 string input_path = "../../../../TestFiles/AdvancedImaging/";
54 string output_path = "../../../../TestFiles/Output/";
55
56 string dicom_input_file = "xray.dcm";
57 string heic_input_file = "jasper.heic";
58 string psd_input_file = "tiger.psd";
59 string output_ext = ".pdf";
60
61 Console.WriteLine("Example of advanced imaging module:");
62 try
63 {
64 using (PDFDoc pdfdoc = new PDFDoc())
65 {
66 AdvancedImagingConvertOptions opts = new AdvancedImagingConvertOptions();
67 opts.SetDefaultDPI(72.0);
68
69 pdftron.PDF.Convert.FromDICOM(pdfdoc, input_path + dicom_input_file, opts);
70 pdfdoc.Save(output_path + dicom_input_file + output_ext, SDFDoc.SaveOptions.e_remove_unused);
71 }
72
73 using (PDFDoc pdfdoc = new PDFDoc())
74 {
75 pdftron.PDF.Convert.ToPdf(pdfdoc, input_path + heic_input_file);
76 pdfdoc.Save(output_path + heic_input_file + output_ext, SDFDoc.SaveOptions.e_remove_unused);
77 }
78
79 using (PDFDoc pdfdoc = new PDFDoc())
80 {
81 pdftron.PDF.Convert.ToPdf(pdfdoc, input_path + psd_input_file);
82 pdfdoc.Save(output_path + psd_input_file + output_ext, SDFDoc.SaveOptions.e_remove_unused);
83 }
84
85 Console.WriteLine("Done.");
86 }
87 catch (PDFNetException e)
88 {
89 Console.WriteLine(e.Message);
90 }
91 PDFNet.Terminate();
92 }
93 }
94}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6//---------------------------------------------------------------------------------------
7// The following sample illustrates how to convert AdvancedImaging documents to PDF format
8//
9// The AdvancedImaging module is an optional PDFNet Add-on that can be used to convert AdvancedImaging
10// documents into PDF documents
11//
12// The Apryse SDK AdvancedImaging module can be downloaded from http://www.pdftron.com/
13//---------------------------------------------------------------------------------------
14
15const { PDFNet } = require('@pdftron/pdfnet-node');
16const PDFTronLicense = require('../LicenseKey/LicenseKey');
17
18((exports) => {
19 'use strict';
20
21 exports.runAdvancedImagingTest = () => {
22
23 const main = async () => {
24
25 try {
26 await PDFNet.addResourceSearchPath('../../lib/');
27
28 if (!await PDFNet.AdvancedImagingModule.isModuleAvailable()) {
29 console.log('\nUnable to run AdvancedImagingTest: Apryse SDK AdvancedImaging module not available.');
30 console.log('---------------------------------------------------------------');
31 console.log('The AdvancedImaging module is an optional add-on, available for download');
32 console.log('at http://www.pdftron.com/. If you have already downloaded this');
33 console.log('module, ensure that the SDK is able to find the required files');
34 console.log('using the PDFNet::AddResourceSearchPath() function.\n');
35
36 return;
37 }
38
39 // Relative path to the folder containing test files.
40 const inputPath = '../TestFiles/AdvancedImaging/';
41 const outputPath = '../TestFiles/Output/';
42
43 const dicom_input_file = 'xray.dcm';
44 const heic_input_file = 'jasper.heic';
45 const psd_input_file = 'tiger.psd';
46 const output_ext = '.pdf';
47
48 const doc = await PDFNet.PDFDoc.create();
49 doc.initSecurityHandler();
50
51 const opts = new PDFNet.Convert.AdvancedImagingConvertOptions();
52 opts.setDefaultDPI(72);
53 await PDFNet.Convert.fromDICOM(doc, inputPath + dicom_input_file, opts);
54 await doc.save(outputPath + dicom_input_file + output_ext, PDFNet.SDFDoc.SaveOptions.e_linearized);
55
56 const doc2 = await PDFNet.PDFDoc.create();
57 doc2.initSecurityHandler();
58
59 await PDFNet.Convert.toPdf(doc2, inputPath + heic_input_file);
60 await doc2.save(outputPath + heic_input_file + output_ext, PDFNet.SDFDoc.SaveOptions.e_linearized);
61
62 const doc3 = await PDFNet.PDFDoc.create();
63 doc3.initSecurityHandler();
64
65 await PDFNet.Convert.toPdf(doc3, inputPath + psd_input_file);
66 await doc3.save(outputPath + psd_input_file + output_ext, PDFNet.SDFDoc.SaveOptions.e_linearized);
67 } catch (err) {
68 console.log(err);
69 }
70 };
71 PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) {
72 console.log('Error: ' + JSON.stringify(error));
73 }).then(function () { return PDFNet.shutdown(); });
74 };
75 exports.runAdvancedImagingTest();
76})(exports);
77// eslint-disable-next-line spaced-comment
78//# sourceURL=AdvancedImagingTest.js
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6import com.pdftron.common.PDFNetException;
7import com.pdftron.pdf.*;
8import com.pdftron.sdf.Obj;
9import com.pdftron.sdf.ObjSet;
10import com.pdftron.sdf.SDFDoc;
11
12//---------------------------------------------------------------------------------------
13// The following sample illustrates how to convert AdvancedImaging documents to PDF format using
14// the AdvancedImaging class.
15//
16// 'pdftron.PDF.AdvancedImaging' is an optional PDFNet Add-On utility class that can be
17// used to convert AdvancedImaging documents into PDF documents by using an external module (AdvancedImaging).
18//
19// AdvancedImaging modules can be downloaded from http://www.pdftron.com/pdfnet/downloads.html.
20//---------------------------------------------------------------------------------------
21public class AdvancedImagingTest {
22
23 public static void main(String[] args)
24 {
25 System.getProperty("sun.arch.data.model");
26
27 PDFNet.initialize(PDFTronLicense.Key());
28 try {
29 PDFNet.addResourceSearchPath("../../../Lib/");
30 if(!AdvancedImagingModule.isModuleAvailable())
31 {
32 System.out.println();
33 System.out.println("Unable to run AdvancedImagingTest: Apryse SDK AdvancedImaging module not available.");
34 System.out.println("---------------------------------------------------------------");
35 System.out.println("The AdvancedImaging module is an optional add-on, available for download");
36 System.out.println("at http://www.pdftron.com/. If you have already downloaded this");
37 System.out.println("module, ensure that the SDK is able to find the required files");
38 System.out.println("using the PDFNet::AddResourceSearchPath() function." );
39 System.out.println();
40 }
41 } catch (PDFNetException e) {
42 System.out.println("AdvancedImaging module not available, error:");
43 e.printStackTrace();
44 System.out.println(e);
45 }
46
47 // Relative path to the folder containing test files.
48 String input_path = "../../TestFiles/AdvancedImaging/";
49 String output_path = "../../TestFiles/Output/";
50 // The input file names
51 String dicom_input_file = "xray.dcm";
52 String heic_input_file = "jasper.heic";
53 String psd_input_file = "tiger.psd";
54 String outputFile;
55
56 System.out.println("-------------------------------------------------");
57 System.out.println("Converting DICOM document to PDF");
58
59 try (PDFDoc doc = new PDFDoc()) {
60 AdvancedImagingConvertOptions opts = new AdvancedImagingConvertOptions();
61 opts.setDefaultDPI(72.0);
62 Convert.fromDICOM(doc, input_path + dicom_input_file, opts);
63 outputFile = output_path + dicom_input_file + ".pdf";
64 doc.save(outputFile, SDFDoc.SaveMode.LINEARIZED, null);
65 System.out.println("Result saved in " + outputFile);
66 } catch (PDFNetException e) {
67 System.out.println("Unable to convert DICOM document, error:");
68 e.printStackTrace();
69 System.out.println(e);
70 }
71 System.out.println("Converting HEIC document to PDF");
72 try (PDFDoc doc = new PDFDoc()) {
73 Convert.toPdf(doc, input_path + heic_input_file);
74 outputFile = output_path + heic_input_file + ".pdf";
75 doc.save(outputFile, SDFDoc.SaveMode.LINEARIZED, null);
76 System.out.println("Result saved in " + outputFile);
77 } catch (PDFNetException e) {
78 System.out.println("Unable to convert HEIC document, error:");
79 e.printStackTrace();
80 System.out.println(e);
81 }
82
83 System.out.println("Converting PSD document to PDF");
84 try (PDFDoc doc = new PDFDoc()) {
85 Convert.toPdf(doc, input_path + psd_input_file);
86 outputFile = output_path + psd_input_file + ".pdf";
87 doc.save(outputFile, SDFDoc.SaveMode.LINEARIZED, null);
88 System.out.println("Result saved in " + outputFile);
89 } catch (PDFNetException e) {
90 System.out.println("Unable to convert PSD document, error:");
91 e.printStackTrace();
92 System.out.println(e);
93 }
94
95 System.out.println("Done.");
96 PDFNet.terminate();
97 }
98}
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5
6#include <PDF/PDFNet.h>
7#include <PDF/PDFDoc.h>
8#include <PDF/Convert.h>
9#include <PDF/AdvancedImagingModule.h>
10#include <PDF/AdvancedImagingConvertOptions.h>
11#include <string>
12#include <iostream>
13#include <stdio.h>
14#include "../../LicenseKey/CPP/LicenseKey.h"
15
16using namespace pdftron;
17using namespace pdftron::SDF;
18using namespace PDF;
19using namespace std;
20
21
22//---------------------------------------------------------------------------------------
23// The following sample illustrates how to convert AdvancedImaging documents to PDF format
24//
25// The AdvancedImaging module is an optional PDFNet Add-on that can be used to convert AdvancedImaging
26// documents into PDF documents
27//
28// The Apryse SDK AdvancedImaging module can be downloaded from http://www.pdftron.com/
29//---------------------------------------------------------------------------------------
30
31UString inputPath("../../TestFiles/AdvancedImaging/");
32UString outputPath("../../TestFiles/Output/");
33
34
35int main(int argc, char *argv[])
36{
37 int ret = 0;
38
39 try
40 {
41 // The first step in every application using PDFNet is to initialize the
42 // library and set the path to common PDF resources. The library is usually
43 // initialized only once, but calling Initialize() multiple times is also fine.
44 PDFNet::Initialize(LicenseKey);
45 PDFNet::AddResourceSearchPath("../../../Lib/");
46
47 if(!AdvancedImagingModule::IsModuleAvailable())
48 {
49 cout << endl;
50 cout << "Unable to run AdvancedImagingTest: Apryse SDK AdvancedImaging module not available." << endl;
51 cout << "---------------------------------------------------------------" << endl;
52 cout << "The AdvancedImaging module is an optional add-on, available for download" << endl;
53 cout << "at http://www.pdftron.com/. If you have already downloaded this" << endl;
54 cout << "module, ensure that the SDK is able to find the required files" << endl;
55 cout << "using the PDFNet::AddResourceSearchPath() function." << endl << endl;
56 return 0;
57 }
58
59 typedef struct
60 {
61 UString inputFile, outputFile;
62 } TestFile;
63
64 UString dicom_input_file, heic_input_file, psd_input_file;
65
66 dicom_input_file = "xray.dcm";
67 heic_input_file = "jasper.heic";
68 psd_input_file = "tiger.psd";
69
70 try
71 {
72 PDFDoc pdfdoc_dicom;
73 AdvancedImagingConvertOptions opts;
74 opts.SetDefaultDPI(72);
75 Convert::FromDICOM(pdfdoc_dicom, inputPath + dicom_input_file, &opts);
76 pdfdoc_dicom.Save(outputPath + dicom_input_file + UString(".pdf"), SDF::SDFDoc::e_linearized, NULL);
77 }
78 catch (Common::Exception& e)
79 {
80 cout << "Unable to convert DICOM test file" << endl;
81 cout << e << endl;
82 ret = 1;
83 }
84 catch (...)
85 {
86 cout << "Unknown Exception" << endl;
87 ret = 1;
88 }
89
90 try
91 {
92 PDFDoc pdfdoc_heic;
93 Convert::ToPdf(pdfdoc_heic, inputPath + heic_input_file);
94 pdfdoc_heic.Save(outputPath + heic_input_file + UString(".pdf"), SDF::SDFDoc::e_linearized, NULL);
95 }
96 catch (Common::Exception& e)
97 {
98 cout << "Unable to convert the HEIC test file" << endl;
99 cout << e << endl;
100 ret = 1;
101 }
102 catch (...)
103 {
104 cout << "Unknown Exception" << endl;
105 ret = 1;
106 }
107
108 try
109 {
110 PDFDoc pdfdoc_psd;
111 Convert::ToPdf(pdfdoc_psd, inputPath + psd_input_file);
112 pdfdoc_psd.Save(outputPath + psd_input_file + UString(".pdf"), SDF::SDFDoc::e_linearized, NULL);
113 }
114 catch (Common::Exception& e)
115 {
116 cout << "Unable to convert the PSD test file" << endl;
117 cout << e << endl;
118 ret = 1;
119 }
120 catch (...)
121 {
122 cout << "Unknown Exception" << endl;
123 ret = 1;
124 }
125
126
127 PDFNet::Terminate();
128 }
129 catch (Common::Exception& e)
130 {
131 cout << e << endl;
132 ret = 1;
133 }
134 catch (...)
135 {
136 cout << "Unknown Exception" << endl;
137 ret = 1;
138 }
139
140 return ret;
141}
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()
1Imports System
2Imports System.Drawing
3Imports System.Drawing.Imaging
4Imports System.Runtime.InteropServices
5Imports pdftron
6Imports pdftron.Common
7Imports pdftron.PDF
8Imports pdftron.SDF
9
10Namespace AdvancedImagingTestVB
11 Class Class1
12 Private Shared pdfNetLoader As pdftron.PDFNetLoader = pdftron.PDFNetLoader.Instance()
13
14 Shared Sub Main(ByVal args As String())
15 PDFNet.Initialize(PDFTronLicense.Key)
16 PDFNet.AddResourceSearchPath("../../../../../Lib/")
17
18 If Not AdvancedImagingModule.IsModuleAvailable() Then
19 Console.WriteLine()
20 Console.WriteLine("Unable to run AdvancedImagingTest: Apryse SDK AdvancedImaging module not available.")
21 Console.WriteLine("---------------------------------------------------------------")
22 Console.WriteLine("The AdvancedImaging module is an optional add-on, available for download")
23 Console.WriteLine("at http://www.pdftron.com/. If you have already downloaded this")
24 Console.WriteLine("module, ensure that the SDK is able to find the required files")
25 Console.WriteLine("using the PDFNet::AddResourceSearchPath() function.")
26 Console.WriteLine()
27 End If
28
29 Dim input_path As String = "../../../../TestFiles/AdvancedImaging/"
30 Dim output_path As String = "../../../../TestFiles/Output/"
31
32 Dim dicom_input_file As String = "xray.dcm"
33 Dim heic_input_file As String = "jasper.heic"
34 Dim psd_input_file As String = "tiger.psd"
35
36 Console.WriteLine("Example of advanced imaging module:")
37
38 Try
39
40 Using pdfdoc As PDFDoc = New PDFDoc()
41
42 Dim opts As AdvancedImagingConvertOptions = New AdvancedImagingConvertOptions()
43 opts.SetDefaultDPI(72.0)
44
45 pdftron.PDF.Convert.FromDICOM(pdfdoc, input_path & dicom_input_file, opts)
46 pdfdoc.Save(output_path & dicom_input_file & ".pdf", SDFDoc.SaveOptions.e_linearized)
47
48 End Using
49
50 Using pdfdoc As PDFDoc = New PDFDoc()
51
52 pdftron.PDF.Convert.ToPdf(pdfdoc, input_path & heic_input_file)
53 pdfdoc.Save(output_path & heic_input_file & ".pdf", SDFDoc.SaveOptions.e_linearized)
54
55 End Using
56
57 Using pdfdoc As PDFDoc = New PDFDoc()
58
59 pdftron.PDF.Convert.ToPdf(pdfdoc, input_path & psd_input_file)
60 pdfdoc.Save(output_path & psd_input_file & ".pdf", SDFDoc.SaveOptions.e_linearized)
61
62 End Using
63
64 Console.WriteLine("Done.")
65 Catch e As PDFNetException
66 Console.WriteLine(e.Message)
67 End Try
68 PDFNet.Terminate()
69 End Sub
70 End Class
71End Namespace
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales