Performing Basic Print Management Example for VB.NET

Private Sub PerformBasicPM()
   Dim objPrintSCU As New LTDICPRNSCULib.LEADDicomPrintSCU
   objPrintSCU.Timeout = 60 ' 60 seconds
   objPrintSCU.EnableMethodErrors = False
   ' Establish the Association
   Dim nRet As Short
   nRet = objPrintSCU.Associate("10.0.2.20", 7104, "PrintSCP", "PrintSCU", LTDICPRNSCULib.DicomClassEnum.PRNSCU_BASIC_GRAYSCALE_PM_META_SOP_CLASS + LTDICPRNSCULib.DicomClassEnum.PRNSCU_BASIC_COLOR_PM_META_SOP_CLASS + LTDICPRNSCULib.DicomClassEnum.PRNSCU_BASIC_ANNOTATION_BOX_SOP_CLASS + LTDICPRNSCULib.DicomClassEnum.PRNSCU_BASIC_PRINT_IMAGE_OVERLAY_BOX_SOP_CLASS + LTDICPRNSCULib.DicomClassEnum.PRNSCU_PRESENTATION_LUT_SOP_CLASS + LTDICPRNSCULib.DicomClassEnum.PRNSCU_PRINT_JOB_SOP_CLASS + LTDICPRNSCULib.DicomClassEnum.PRNSCU_PRINTER_CONFIGURATION_RETRIEVAL_SOP_CLASS)
   If nRet = LTDicomKernelLib.DicomErrorCodes.DICOM_ERROR_PRINTSCU_ASSOCIATE_RQ_REJECTED Then
      MessageBox.Show("Source = " & objPrintSCU.AssociateRejectSource & ", " & "Reason = " & objPrintSCU.AssociateRejectReason, "Association Request was Rejected")
      Exit Sub
   ElseIf nRet <> LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS Then
      MessageBox.Show("Error code: " & nRet, "Failed to Establish the Association")
   Exit Sub
   End If
   ' Abort the Association if none of the Basic Print Management Meta SOP Classes
   ' is supported on the Association
   If objPrintSCU.IsClassSupported(LTDICPRNSCULib.DicomClassEnum.PRNSCU_BASIC_GRAYSCALE_PM_META_SOP_CLASS) = False And objPrintSCU.IsClassSupported(LTDICPRNSCULib.DicomClassEnum.PRNSCU_BASIC_COLOR_PM_META_SOP_CLASS) = False Then
      objPrintSCU.AbortAssociation()
      Exit Sub
   End If
   ' Display some printer info
   'GetPrinterInfo objPrintSCU
   ' Display some printer configuration info
   'GetPrinterConfigInfo objPrintSCU
   ' Create a Film Session
   With objPrintSCU.FilmSession
      .IncludedParameters = 0
      .Create()
      MessageBox.Show(.SOPInstanceUID, "Film Session SOP Instance UID")
   End With
   ' Update the Number of Copies and Print Priority of the Film Session
   With objPrintSCU.FilmSession
      .IncludedParameters = LTDICPRNSCULib.FilmSessionParameterEnum.FS_NUMBER_OF_COPIES + LTDICPRNSCULib.FilmSessionParameterEnum.FS_PRINT_PRIORITY
      .NumberOfCopies = 1
      .PrintPriority = "MED"
      .Update()
   End With
   With objPrintSCU.FilmBox
      .IncludedParameters = 0
      If .MainObject.IsClassSupported(LTDICPRNSCULib.DicomClassEnum.PRNSCU_BASIC_ANNOTATION_BOX_SOP_CLASS) Then
         .IncludedParameters = .IncludedParameters + LTDICPRNSCULib.FilmBoxParameterEnum.FB_ANNOTATION_DISPLAY_FORMAT_ID
         .AnnotationDisplayFormatID = "SomeID"
      End If
      ' Create a Film Box
      .Create()
      MessageBox.Show(.SOPInstanceUID, "Film Box SOP Instance UID")
   End With
   Dim sPresLUTInstanceUID As String
   ' Create a Presentation LUT
   With objPrintSCU.PresentationLUT
      If .MainObject.IsClassSupported(LTDICPRNSCULib.DicomClassEnum.PRNSCU_PRESENTATION_LUT_SOP_CLASS) Then
         If .Create("C:\PresLUT.dic") = LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS Then
            sPresLUTInstanceUID = .GetSOPInstanceUID()
            MessageBox.Show(sPresLUTInstanceUID, "Pres LUT SOP Instance UID")
         End If
      End If
   End With
   If Len(sPresLUTInstanceUID) Then
      ' Update the Film Box to reference the Presentation LUT we just created
      With objPrintSCU.FilmBox
         .IncludedParameters = LTDICPRNSCULib.FilmBoxParameterEnum.FB_REF_PRES_LUT_INSTANCE_UID
         .RefPresLUTInstanceUID = sPresLUTInstanceUID
         .Update()
      End With
   End If
   Dim sOverlayBoxInstanceUID As String
   ' Create an Image Overlay Box
   With objPrintSCU.ImageOverlayBox
      If .MainObject.IsClassSupported(LTDICPRNSCULib.DicomClassEnum.PRNSCU_BASIC_PRINT_IMAGE_OVERLAY_BOX_SOP_CLASS) Then
         .OverlayOriginRow = 1
         .OverlayOriginColumn = 1
         .IncludedParameters = 0
         If .Create("C:\Overlay.dic") = LTDicomKernelLib.DicomErrorCodes.DICOM_SUCCESS Then
            sOverlayBoxInstanceUID = .GetSOPInstanceUID()
            MessageBox.Show(sOverlayBoxInstanceUID, "Image Overlay Box SOP Instance UID")
         End If
      End If
   End With
   ' Update the Image Box. Since the Image Display Format of the Film Box was
   ' set to "STANDARD\1,1", then we are supposed to have one Image Box created
   ' by the Print SCP.
   If objPrintSCU.ImageBoxes.Count Then
      With objPrintSCU.ImageBoxes.Item(0)
         MessageBox.Show(.SOPInstanceUID, "Image Box SOP Instance UID")
         .IncludedParameters = 0
         If Len(sOverlayBoxInstanceUID) Then
            .IncludedParameters = .IncludedParameters + LTDICPRNSCULib.ImageBoxParameterEnum.IB_REF_IMAGE_OVERLAY_BOX_INSTANCE_UID .RefImageOverlayBoxInstanceUID = sOverlayBoxInstanceUID
         End If
         .Update("C:\Image.dic")
      End With
   End If
   ' Update the Annotation Boxes (if there are any)
   Dim AnnBox As LTDICPRNSCULib.LAnnotationBox
   For Each AnnBox In objPrintSCU.AnnotationBoxes
      AnnBox.TextString = "Some Text"
      AnnBox.Update()
   Next AnnBox
   ' Change the Overlay Origin of the Image Overlay Box referenced by the
   ' Image Box
   If Len(sOverlayBoxInstanceUID) Then
      With objPrintSCU.ImageOverlayBox
         .IncludedParameters = LTDICPRNSCULib.OverlayBoxParameterEnum.OB_OVERLAY_ORIGIN
         .OverlayOriginRow = 10
         .OverlayOriginColumn = 10
         .Update(sOverlayBoxInstanceUID)
      End With
   End If
   Dim sPrintJobInstanceUID As String
   ' Print the Film Session (or the Film Box; there is no difference since we
   ' have a single Film Box in the Film Session)
   If True Then
      With objPrintSCU.FilmSession
         .PrintSession()
         sPrintJobInstanceUID = .PrintJobSOPInstanceUID
      End With
   Else
      With objPrintSCU.FilmBox
         .PrintBox()
         sPrintJobInstanceUID = .PrintJobSOPInstanceUID
      End With
   End If
   ' Display some info about the Print Job
   If (objPrintSCU.IsClassSupported(LTDICPRNSCULib.DicomClassEnum.PRNSCU_PRINT_JOB_SOP_CLASS)) Then
      'GetPrintJobInfo objPrintSCU, sPrintJobInstanceUID
   End If
   ' Delete the Film Box (anyway, it would be deleted when the Film Session
   ' is deleted)
   objPrintSCU.FilmBox.Delete()
   ' Delete the Film Session
   objPrintSCU.FilmSession.Delete()
   ' Delete the Presentation LUT
   If Len(sPresLUTInstanceUID) Then
      objPrintSCU.PresentationLUT.Delete(sPresLUTInstanceUID)
   End If
   ' Delete the Image Overlay Box
   If Len(sOverlayBoxInstanceUID) Then
      objPrintSCU.ImageOverlayBox.Delete(sOverlayBoxInstanceUID)
   End If
   ' Release the Association and close the connection
   objPrintSCU.ReleaseAssociation()
End Sub