Create DICOM encapsulated PDF?

1,474 views
Skip to first unread message

JRotella

unread,
Aug 6, 2013, 9:57:34 AM8/6/13
to fo-d...@googlegroups.com
I'm searching the Fellow Oak DICOM libraries for a class or set of classes that I can use to take an existing PDF document and convert it to DICOM encapsulated PDF.  So far, my investigation has come up empty.  Would I need to look in one of the codec related classes, or is there some other source of documentation I can peruse to understand this operation?

Thanks!

Rai Se

unread,
Aug 7, 2013, 2:16:53 AM8/7/13
to fo-d...@googlegroups.com
hi
this is how I experimentally decoded pdf from dicom object using mdcm...
 
just reverse it...
 

 if (ff.FileMetaInfo.MediaStorageSOPClassUID == DicomUID.EncapsulatedPDFStorage && ff.Dataset.Contains(DicomTags.EncapsulatedDocument))
                {
                    byte[] Buffer = new byte[ff.Dataset.GetOB(DicomTags.EncapsulatedDocument).Length];
                    Buffer = ff.Dataset.GetOB(DicomTags.EncapsulatedDocument).GetValues();
                    FileStream CreatePdf = new FileStream(ff.Dataset.GetUI(DicomTags.SOPInstanceUID).GetValueString() + ".pdf", FileMode.Create);
                    CreatePdf.Write(Buffer, 0, Buffer.Length);
                    CreatePdf.Close();
                    System.Diagnostics.Process proc;
                    proc = Process.Start(CreatePdf.Name);
                   

                }

HTH

raise

DeLe

unread,
Aug 8, 2013, 12:14:22 PM8/8/13
to fo-d...@googlegroups.com
 
This worked for me... of course you'll have to add in all your tags.
 
public void Encapsulate(string file, string outFile) {
   DicomDataset data = new DicomDataset();
   data.Add(DicomTag.SOPClassUID, DicomUID.EncapsulatedPDFStorage);
   byte[] fileData = ReadBytesFromFile(file);
   data.Add(DicomTag.EncapsulatedDocument, fileData);
   DicomFile ff = new DicomFile(data);
   ff.Save(@outFile);
}

public byte[] ReadBytesFromFile(string fileName) {
  FileStream fs = File.OpenRead(fileName);
  try
  {
     byte[] bytes = new byte[fs.Length];
     fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
     fs.Close();
     return bytes; 
   }
   finally 
   { 
       fs.Close(); 
    }
}

Joaquim Junior

unread,
May 12, 2014, 8:31:45 PM5/12/14
to fo-d...@googlegroups.com
Error In DicomFile ff = new DicomFile(data);
Object reference not set

I don't understand: DicomDataset accpt bytes()??

EDAN

unread,
Oct 16, 2017, 10:41:09 PM10/16/17
to Fellow Oak DICOM
Hello JRotella,
It's been a while since your last question post, may I know any updates? Do you have any encapsulate PDF report file sample that can share with us?
I finish the encapsulate PDF report development, need a sample for test and comparison.

BR,

Reply all
Reply to author
Forward
0 new messages