using System;
using gdcm;
public class ExtractEncapsulatedFile
{
public static int Main(string[] args)
{
string file = args[0];
Reader reader = new Reader();
reader.SetFileName( file );
bool ret = reader.Read();
if( !ret )
{
return 1;
}
File f = reader.GetFile();
DataSet ds = f.GetDataSet();
Tag tencapsulated_stream = new Tag(0x0042,0x0011);
if( !ds.FindDataElement( tencapsulated_stream ) )
{
return 1;
}
DataElement de = ds.GetDataElement( tencapsulated_stream );
ByteValue bv = de.GetByteValue();
uint len = bv.GetLength();
byte[] encapsulated_stream = new byte[len];
bv.GetBuffer( encapsulated_stream, len );
using (System.IO.Stream stream =
System.IO.File.Open(@"/tmp/dd.pdf",
System.IO.FileMode.Create))
{
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
writer.Write( encapsulated_stream );
}
return 0;
}
}