Some test text!

menu

JavaScript DICOM to PDF converter

More languages

chevron_right
More languages
C++
C#
C# (.NET Core)
Java
JS (Node.js)
VB

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

Get StartedSamplesDownload

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

//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

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

const { PDFNet } = require('../../../lib/pdfnet.js');

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

	exports.runAdvancedImagingTest = () => {

		const main = async () => {

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

				if (!await PDFNet.AdvancedImagingModule.isModuleAvailable()) {
					console.log('\nUnable to run AdvancedImagingTest: PDFTron SDK Advanced Imaging module not available.');
					console.log('---------------------------------------------------------------');
					console.log('The Advanced Imaging 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 input_file_name = 'xray.dcm';
				const output_file_name = 'xray.pdf';

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

				const opts = new PDFNet.Convert.AdvancedImagingConvertOptions();
				opts.setDefaultDPI(72);
				await PDFNet.Convert.fromDICOM(doc, inputPath + input_file_name, opts);
				await doc.save(outputPath + output_file_name, PDFNet.SDFDoc.SaveOptions.e_linearized);
			} catch (err) {
				console.log(err);
			}
		};
		// add your own license key as the second parameter, e.g. PDFNet.runWithCleanup(main, 'YOUR_LICENSE_KEY')
		PDFNet.runWithCleanup(main).catch(function (error) {
			console.log('Error: ' + JSON.stringify(error));
		}).then(function () { PDFNet.shutdown(); });
	};
	exports.runAdvancedImagingTest();
})(exports);
// eslint-disable-next-line spaced-comment
//# sourceURL=AdvancedImagingTest.js
close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.