AdvancedImaging

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}

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales