使用ABCPDF 9将两个或多个PDF ObjectStream组合成单个Stream

时间:2013-09-23 23:47:47

标签: pdf abcpdf

我试图找到一种方法来编写一个函数,传递一个包含多个对象id的param数组(至少两个),然后它将对象组合成一个单独的流并返回新流对象的id。

这是我到目前为止所做的:

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

当传入的对象不再出现在文档中时,该功能当前不起作用。我感觉它与流如何连接在一起或者新文件流没有在文档中的任何地方引用有关,因此在保存pdf时被删除(“废弃”或未引用的对象被删除)。

感谢您的帮助。

0 个答案:

没有答案