I was creating an Encapsulated PDF DICOM file to send to a PACS server by simply doing:
dataset.Add(DicomTag.EncapsulatedDocument, File.ReadAllBytes(filename));
My PACS server rejected the file and after a bit of research I discovered that the DICOM standard requires data fields to be an even number of bytes. I added code to pad the byte array before handing it off:
byte[] data;
using (var fs = new FileStream(pdfFilePath, FileMode.Open, FileAccess.Read))
{
data = new byte[fs.Length % 2 == 0 ? fs.Length : fs.Length + 1];
fs.Read(data, 0, (int)fs.Length);
}
This appears to work. The file is accepted by my PACS server and I can open it in a DICOM viewer that supports PDF.
So I have two questions:
1) Can this be fixed in a future release?
2) Is this workaround valid or will it cause problems somehow?