The PdfToDicom example demonstrates how to use DCF to create a dataset containing an encapsulated PDF from an existing PDF file.
Classes
Class | Description | |
---|---|---|
Program |
This example creates an encapsulated PDF dataset from an existing PDF data file.
|
Examples
PdfToDicom Sample Code
public class Program { private static readonly ILogger Logger = LogManager.GetCurrentClassLogger(); /// <summary> /// Main entry point for PdfToDicom. /// </summary> [STAThread] public static void Main() { string pdfFilePath = "Results_ENG.pdf"; try { EncapsulatedPdf encapsulatedPdf = new EncapsulatedPdf(); List<byte> pdfBytes = new List<byte>(File.ReadAllBytes(pdfFilePath)); // Pad the byte array if the length is odd if (pdfBytes.Count % 2 != 0) pdfBytes.Add(0x0); encapsulatedPdf.EncapsulatedDocument = new DicomOBElement(Tags.EncapsulatedDocument, pdfBytes.ToArray()); // these are tags that should be set by application encapsulatedPdf.StudyInstanceUID = new DicomUIElement(Tags.StudyInstanceUID, "1.2.3.4.5"); encapsulatedPdf.SeriesInstanceUID = new DicomUIElement(Tags.SeriesInstanceUID, "6.7.8.9.10"); encapsulatedPdf.PatientID = new DicomLOElement(Tags.PatientID, "123456789"); encapsulatedPdf.PatientName = new DicomPNElement(Tags.PatientName, "Doe^John"); encapsulatedPdf.PatientSex = new DicomCSElement(Tags.PatientSex, "F"); encapsulatedPdf.PatientBirthDate = new DicomDAElement(Tags.PatientBirthDate, "19700101"); encapsulatedPdf.StudyDate = new DicomDAElement(Tags.StudyDate, DateTime.Now.ToString("yyyyMMdd")); encapsulatedPdf.StudyTime = new DicomTMElement(Tags.StudyTime, DateTime.Now.ToString("HHmmss")); encapsulatedPdf.AccessionNumber = new DicomSHElement(Tags.AccessionNumber, "123456789"); encapsulatedPdf.StudyID = new DicomSHElement(Tags.StudyID, "1"); encapsulatedPdf.SeriesNumber = new DicomISElement(Tags.SeriesNumber, "1"); encapsulatedPdf.Modality = new DicomCSElement(Tags.Modality, "OT"); encapsulatedPdf.ReferringPhysicianName = new DicomPNElement(Tags.ReferringPhysicianName, String.Empty); encapsulatedPdf.NumberOfStudyRelatedInstances = new DicomISElement(Tags.NumberOfStudyRelatedInstances, "1"); encapsulatedPdf.NumberOfStudyRelatedSeries = new DicomISElement(Tags.NumberOfStudyRelatedSeries, "1"); encapsulatedPdf.NumberOfSeriesRelatedInstances = new DicomCSElement(Tags.NumberOfSeriesRelatedInstances, "1"); encapsulatedPdf.DocumentTitle = new DicomSTElement(Tags.DocumentTitle, "Results_ENG"); encapsulatedPdf.MIMETypeOfEncapsulatedDocument = new DicomLOElement(Tags.MIMETypeOfEncapsulatedDocument, "application/pdf"); string outputFilename = "Results_ENG.dcm"; if (File.Exists(outputFilename)) { Logger.ErrorFormat("File({0}) already exists. Remove before retrying write operation.", outputFilename); } else { // Write to disk using (DicomFileOutput dfo = new DicomFileOutput(outputFilename, Uids.ELE)) { dfo.WriteDataSet(encapsulatedPdf.DataSet); } } Logger.Info(encapsulatedPdf.ToString()); } catch (Exception e) { Logger.Error(e, "Problem encapsulating pdf:"); } if (System.Diagnostics.Debugger.IsAttached) { Console.Write("Press any key to continue . . . "); Console.ReadKey(); } } }