1

I am try to find a way to write a function that you pass a param array of a number of object ids (at least two) and it combines the objects into a single stream and returns the id of the new stream object.

Here is what I have so far:

Public Function CombineToStream(ParamArray objects As Integer()) As Integer
    Dim stream = New StreamObject(myDoc.ObjectSoup)
    Dim sb As New StringBuilder()
    Dim soType As Type = GetType(StreamObject)

    If objects.Length < 2 Then
      Return objects.FirstOrDefault()
    End If

    For index As Integer = 0 To objects.Length - 1
      Dim objectId As Integer = objects(index)

      Dim obj = myDoc.ObjectSoup.Item(objectId)

      Dim objType As Type = obj.GetType


      If objType = soType OrElse objType.IsSubclassOf(soType) Then

        Dim typedObj As StreamObject = TryCast(obj, StreamObject)

        If typedObj.Compressed Then
          typedObj.Decompress()
        End If

        Dim data As Byte() = typedObj.GetData()
        sb.Append(Encoding.ASCII.GetString(data))
      End If
    Next

    stream.SetData(Encoding.ASCII.GetBytes(sb.ToString()))

    For index As Integer = 0 To objects.Length - 1
      Dim objectId As Integer = objects(index)

      myDoc.Delete(objectId)
    Next

    Return stream.ID
  End Function

The function currently doesn't work as the objects passed in no longer appear in the document. I have a feeling it is something to do with either how the streams are being concatenated together or perhaps the new stream is not referenced anywhere in the document so is being removed when the pdf is saved ("abandoned" or unreferenced objects are deleted).

Thanks for the help in advance.

4

0 に答える 0