Printing without using DicomPrint


Although DicomPrint object is designed to make printing simple and easy for developers to code, it is possible to use a more advanced DicomConnection (COM version) or DicomAssociation (.NET version) object to meet your special requirement. The code below gives a starting point for those wishing to do this themselves

DicomObjects.NET

 
 DicomAssociation cn = new DicomAssociation();
 DicomDataSet printer;
 DicomImageCollection ims;
 DicomImage thisim;
 string BFSUID, filmboxUID, uidroot;
 DicomDataSetCollection ImageBoxList;
 DicomDataSet session;
 DicomDataSet filmbox;
 DicomDataSet refSessionItem;
 DicomDataSetCollection refSessionSequence;
 DicomDataSet ImageSequenceHolder;
 DicomDataSetCollection ImageSequence;
 DicomDataSet NullDataSet;
 int imno;
 int imnofilm;
 int uidint;
 
 // This example uses explicit UIDs for objects created.
 // This should not be necessary, as the SCP should create the item itself
 // if necessary, but it
 // a) Shows how to use an image object to create UIDs
 // b) Keeps certain validation tool happy
 
 uidroot = "1.2.840.12345.24256.2";
 uidint = 0;
 ims = Viewer.Images;
 
 DicomContext cx = cn.RequestedContexts.Add(DicomObjects.DicomUIDs.MetaSOPClasses.BasicGrayscalePrint);
 
 string[] tsList = new string[] { TransferSyntaxes.ImplicitVRLittleEndian, 
 			TransferSyntaxes.ExplicitVRLittleEndian };
 cx.OfferedTS = tsList;
 
 cn.Open("localhost", 104, "print SCU", "printer");
 cn.MetaSOPClass = DicomObjects.DicomUIDs.MetaSOPClasses.BasicGrayscalePrint;
 
 // Get the printer object (though you don't actually use it!)
 printer = new DicomDataSet();
 cn.NGet(SOPClasses.Printer, WellKnownInstances.Printer, printer);
 
 // Create a film session
 session = new DicomDataSet();
 session.Add(Keyword.NumberOfCopies, 1);
 uidint++;
 cn.NCreate(SOPClasses.BasicFilmSession, uidroot + uidint, session);
 BFSUID = cn.LastInstanceUID;
 
 imno = 0;
 do
 {
	imnofilm = 0;
	//Create a film box
	filmbox = new DicomDataSet();
	refSessionItem = new DicomDataSet();
	refSessionSequence = new DicomDataSetCollection();
	filmbox.Add(Keyword.ImageDisplayFormat, @"STANDARD\1,1");
	filmbox.Add(Keyword.FilmOrientation, "PORTRAIT");
	filmbox.Add(Keyword.FilmSizeID, "8INX10IN");
	filmbox.Add(Keyword.MagnificationType, "NONE");
	filmbox.Add(Keyword.BorderDensity, "BLACK");
	filmbox.Add(Keyword.EmptyImageDensity, "BLACK");
	filmbox.Add(Keyword.MinDensity, 6);
	filmbox.Add(Keyword.MaxDensity, 241);
	filmbox.Add(Keyword.Trim, "NO");
	refSessionItem.Add(Keyword.ReferencedSOPClassUID, DicomObjects.DicomUIDs.SOPClasses.BasicFilmSession);
	refSessionItem.Add(Keyword.ReferencedSOPInstanceUID, BFSUID);
	refSessionSequence.Add(refSessionItem);
	filmbox.Add(Keyword.ReferencedFilmSessionSequence, refSessionSequence);
	uidint++;
	cn.NCreate(DicomObjects.DicomUIDs.SOPClasses.BasicFilmBox, uidroot + uidint, filmbox);
  
	filmboxUID = cn.LastInstanceUID;
	ImageBoxList = cn.ReturnedIdentifier[Keyword.ReferencedImageBoxSequence].Value 
			as DicomDataSetCollection;  
	do
	{
	  thisim = Viewer.Images[imno];
	  thisim.StretchMode = StretchModes.StretchCentred;
   
	  // Fill the image boxes
	  ImageSequenceHolder = new DicomDataSet();
	  ImageSequence = new DicomDataSetCollection();
	  ImageSequenceHolder.Add(Keyword.ImageBoxPosition, imnofilm);
	  ImageSequence.Add(thisim); // yes, a DicomImage may be added to a DicomDatasets collection
	  ImageSequenceHolder.Add(Keyword.BasicGrayscaleImageSequence, ImageSequence);
   
	  cn.NSet(SOPClasses.BasicGrayscaleImageBox, 
	   ImageBoxList[imnofilm][Keyword.ReferencedSOPInstanceUID].Value.ToString(), ImageSequenceHolder);
   
	  imno++;
	  imnofilm++;
	}
	while (imno < Viewer.Images.Count && imnofilm < ImageBoxList.Count);

	NullDataSet = new DicomDataSet();
	cn.NAction(SOPClasses.BasicFilmBox, filmboxUID, 1, NullDataSet);
	cn.NDelete(SOPClasses.BasicFilmBox, filmboxUID);
 }
 while (imno < Viewer.Images.Count);

 cn.Close();


DicomObjects.COM

 Dim cn As DicomConnection
 Dim cx As DicomContexts
 Dim Printer As DicomDataSet
 Dim ims As DicomImages
 Dim Thisim As DicomImage
 Dim BFSUID As String, FilmboxUID As String
 Dim ImageBoxList As DicomDataSets
 Dim Session As DicomDataSet
 Dim Filmbox As DicomDataSet
 Dim RefSessionItem As DicomDataSet
 Dim RefSessionSequence As DicomDataSets
 Dim ImageSequenceHolder As DicomDataSet
 Dim ImageSequence As DicomDataSets
 Dim NullDataSet As DicomDataSet
 Dim imno As Integer, imnofilm As Integer

 ' This example uses explicit UIDs for objects created.
 ' This should not be necessary, as the SCP should create the item itself
 ' if necessary, but it
  ' a) Shows how to use an image object to create UIDs
  ' b) Keeps certain validation tool happy !

 Dim uidimage As New DicomImage
 Dim uidroot As String, uidint As Integer
 uidint = 0
 uidroot = uidimage.InstanceUID & "."

 Set cn = Viewer.New("dicomconnection")
 Set ims = Viewer.Images

 Set cx = cn.Contexts
 cx.Add doMeta_BasicGrayscalePrint
 Dim ts(3) As String
 ts(1) = doTS_ImplicitVRLittleEndian
 ts(2) = doTS_ExplicitVRLittleEndian
 ts(3) = doTS_ExplicitVRBigEndian
 cx(1).OfferedTS = ts

 cn.SetDestination "localhost", 104, "print SCU", "printer"
 cn.MetaSOPClass = doMeta_BasicGrayscalePrint
 cn.Wait

 ' Get the printer object (though you don't actually use it !)
 Set Printer = New DicomDataSet
 cn.NGet doSOP_Printer, doInstance_Printer, Printer
 cn.Wait

 ' Create a film session
 Set Session = New DicomDataSet
 Session.Attributes.Add &H2000, &H10, 1 ' copies
 uidint = uidint + 1
 cn.NCreate doSOP_BasicFilmSession, uidroot & uidint, Session
    
 cn.Wait
 BFSUID = cn.LastInstanceUID

 imno = 1
 Do While imno <= Viewer.Images.Count
  imnofilm = 1
  'Create a film box
  Set Filmbox = New DicomDataSet
  Set RefSessionItem = New DicomDataSet
  Set RefSessionSequence = New DicomDataSets
     
  Filmbox.Attributes.Add &H2010, &H10, OptionsBox.PrintFormat
  Filmbox.Attributes.Add &H2010, &H40, OptionsBox.PrintOrientation
  Filmbox.Attributes.Add &H2010, &H50, OptionsBox.FilmSize
  Filmbox.Attributes.Add &H2010, &H60, OptionsBox.Magnification
  Filmbox.Attributes.Add &H2010, &H100, "BLACK"
  Filmbox.Attributes.Add &H2010, &H110, "BLACK"
  Filmbox.Attributes.Add &H2010, &H120, 6
  Filmbox.Attributes.Add &H2010, &H130, 241
  Filmbox.Attributes.Add &H2010, &H140, "NO"
  RefSessionItem.Attributes.Add 8, &H1150, doSOP_BasicFilmSession
  RefSessionItem.Attributes.Add 8, &H1155, BFSUID
  RefSessionSequence.Add RefSessionItem
  Filmbox.Attributes.Add &H2010, &H500, RefSessionSequence
  uidint = uidint + 1
  cn.NCreate doSOP_BasicFilmBox, uidroot & uidint, Filmbox
     
  cn.Wait
  FilmboxUID = cn.LastInstanceUID
     
  Set ImageBoxList = cn.ReturnedDataSet.Attributes(&H2010, &H510).Value
     
  Do While imno <= Viewer.Images.Count And imnofilm <= ImageBoxList.Count
   Set Thisim = Viewer.Images(imno)
   Thisim.StretchMode = StretchCentred
   Thisim.Zoom = 1
   Set Thisim = Thisim.Capture(True)
 
   'Fill the image boxes
   Set ImageSequenceHolder = New DicomDataSet
   Set ImageSequence = New DicomDataSets
   ImageSequenceHolder.Attributes.Add &H2020, &H10, imnofilm
    
   ImageSequence.Add Thisim ' yes, a DicomImage may be added to a DicomDatasets collection
   ImageSequenceHolder.Attributes.Add &H2020, &H110, ImageSequence
 
   cn.NSet doSOP_BasicGrayscaleImageBox, ImageBoxList(imnofilm).Attributes(8, &H1155), ImageSequenceHolder
   cn.Wait
 
   imno = imno + 1
   imnofilm = imnofilm + 1
  Loop
     
  Set NullDataSet = New DicomDataSet
  cn.NAction doSOP_BasicFilmBox, FilmboxUID, 1, NullDataSet
  cn.Wait
     
  cn.NDelete doSOP_BasicFilmBox, FilmboxUID
  cn.Wait
 Loop
 cn.Close



We use cookies to give you the best possible experience on our website. By continuing to use this website, you agree with our use of cookies. for more information please click HERE