PDF to DICOM Converter
Convert PDFs into standards-compliant DICOM files for PACS, radiology, and healthcare interoperability workflows.
- Convert PDFs to Encapsulated DICOM or RGB Secondary Capture DICOM
- Preserve patient/study metadata from template DICOMs
- Simple Python API built on pydicom
- Compatible with PACS workflows
The python package is available for use on PyPI. It can be setup simply via pip
pip install pdf2dcmTo the check the setup, simply check the version number of the pdf2dcm package by
python -c 'import pdf2dcm; print(pdf2dcm.__version__)'Poppler is a popular project that is used for the creation of Dicom RGB Secondary Capture. You can check if you already have it installed by calling pdftoppm -h in your terminal/cmd. To install poppler these are some of the recommended ways-
Conda
conda install -c conda-forge popplerUbuntu
sudo apt-get install poppler-utilsMacOS
brew install popplerStores the original PDF directly inside a DICOM object. This is useful for:
- Radiology or pathology or any structured clinical documents
- PACS archival workflows
from pdf2dcm import Pdf2EncapsDCM
converter = Pdf2EncapsDCM()
converted_dcm = converter.run(path_pdf='tests/test_data/test_file.pdf', path_template_dcm='tests/test_data/CT_small.dcm', suffix =".dcm")
print(converted_dcm)
# [ 'tests/test_data/test_file.dcm' ]Parameters converter.run:
path_pdf (str): path of the pdf that needs to be encapsulatedpath_template_dcm (str, optional): Optional template DICOM used for metadata inheritance.suffix (str, optional): suffix of the dicom files. Defaults to ".dcm".
Returns:
List[Path]: list of path of the stored encapsulated dcm
Renders PDF pages as RGB images and stores them as Secondary Capture DICOM instances. Useful when:
- Encapsulated PDFs are unsupported
- Image-based viewing is preferred
- Legacy PACS compatibility is required
from pdf2dcm import Pdf2RgbSC
converter = Pdf2RgbSC()
converted_dcm = converter.run(path_pdf='tests/test_data/test_file.pdf', path_template_dcm='tests/test_data/CT_small.dcm', suffix =".dcm")
print(converted_dcm)
# [ 'tests/test_data/test_file_0.dcm', 'tests/test_data/test_file_1.dcm' ]Parameters converter.run:
path_pdf (str): path of the pdf that needs to be convertedpath_template_dcm (str, optional): Optional template DICOM used for metadata inheritance.suffix (str, optional): suffix of the dicom files. Defaults to ".dcm".
Returns:
List[Path]: list of paths of the stored secondary capture dcm
- Output DICOM filenames are derived from the input PDF filename.
- If no template is provided no repersonalisation takes place
- It is possible to produce dicoms without a suffix by simply passing
suffix=""to theconverter.run()
Metadata can optionally be copied from a template DICOM file to preserve patient and study context. Currently, the fields that is inherited by default are-
- PatientName
- PatientID
- PatientSex
- StudyInstanceUID
SeriesInstanceUIDSOPInstanceUID
The fields SeriesInstanceUID and SOPInstanceUID have been removed from the inheritance by copying as it violates the DICOM standards.
You can set the fields to repersonalize by passing repersonalisation_fields into Pdf2EncapsDCM(), or Pdf2RgbSC()
Example:
fields = [
"PatientName",
"PatientID",
"PatientSex",
"StudyInstanceUID",
"AccessionNumber"
]
converter = Pdf2RgbSC(repersonalisation_fields=fields)note: this will overwrite the default fields.