FileSpecification Constructor




FileSpecification(ObjectSoup soup)
FileSpecification(ObjectSoup soup, string path)

[Visual Basic]
Sub New(soup As ObjectSoup)
Sub New(soup As ObjectSoup, path As String)



Name Description
soup The ObjectSoup to contain the newly created FileSpecification.
path A file to embed within the file specification.




Create a FileSpecification.

This constructor which takes a path to a file will embed and compress the file data using using the CompressFlate function. It will also insert appropriate metadata using the EmbeddedFileUpdateMetadata function.

The constructor which takes an array of data will similarly embed and compress the data. However since there is no file path metadata will not be assigned.




The example below shows how to combine a set of PDF documents into a portfolio. See the Catalog.GetEmbeddedFiles function for how to extract files from a portfolio.

string[] files = {
using (Doc doc = new Doc()) {
  List<Tuple<string, FileSpecification>> fileSpecs = new List<Tuple<string, FileSpecification>>();
  foreach (string file in files) {
    byte[] data = null;
    using (Doc subDoc = new Doc()) {
      data = subDoc.GetData();
    EmbeddedFile embedFile = new EmbeddedFile(doc.ObjectSoup, data);
    FileSpecification fileSpec = new FileSpecification(doc.ObjectSoup);
    fileSpec.EmbeddedFile = embedFile;
    fileSpec.Uri = file;
    string name = Path.GetFileName(file);
    fileSpecs.Add(new Tuple<string, FileSpecification>(name, fileSpec));
  fileSpecs.Sort((a, b) => a.Item1.CompareTo(b.Item1));
  // we don't really need to delete existing files but we do so as an example
  doc.SetInfo(doc.Root, "/Names*/EmbeddedFiles*/Names:Del", "");
  foreach (Tuple<string, FileSpecification> fileSpec in fileSpecs) {
    doc.SetInfo(doc.Root, "/Names*/EmbeddedFiles*/Names*[]:Text", fileSpec.Item1);
    doc.SetInfo(doc.Root, "/Names*/EmbeddedFiles*/Names*[]:Ref", fileSpec.Item2.ID);
  doc.SetInfo(doc.Root, "/Names*/EmbeddedFiles*/Limits*[]:Ref", fileSpecs[0].Item1);
  doc.SetInfo(doc.Root, "/Names*/EmbeddedFiles*/Limits*[]:Ref", fileSpecs[fileSpecs.Count - 1].Item1);
  doc.SetInfo(doc.Root, "/Collection*/D:Text", files[0]);

[Visual Basic]
Sub ...
  Dim files As String() = {"Bentley.pdf", "Acrobat.pdf", "Noise.pdf", "ChecksModified.pdf"}
  Using doc As New Doc()
    Dim fileSpecs As New List(Of Tuple(Of String, FileSpecification))()
    For Each file As String In files
      Dim data As Byte() = Nothing
      Using subDoc As New Doc()
        data = subDoc.GetData()
      End Using
      Dim embedFile As New EmbeddedFile(doc.ObjectSoup, data)
      Dim fileSpec As New FileSpecification(doc.ObjectSoup)
      fileSpec.EmbeddedFile = embedFile
      fileSpec.Uri = file
      Dim name As String = Path.GetFileName(file)
      fileSpecs.Add(New Tuple(Of String, FileSpecification)(name, fileSpec))
    fileSpecs.Sort(Function(a, b) a.Item1.CompareTo(b.Item1))
    ' we don't really need to delete existing files but we do so as an example
    doc.SetInfo(doc.Root, "/Names*/EmbeddedFiles*/Names:Del", "")
    For Each fileSpec As Tuple(Of String, FileSpecification) In fileSpecs
      doc.SetInfo(doc.Root, "/Names*/EmbeddedFiles*/Names*[]:Text", fileSpec.Item1)
      doc.SetInfo(doc.Root, "/Names*/EmbeddedFiles*/Names*[]:Ref", fileSpec.Item2.ID)
    doc.SetInfo(doc.Root, "/Names*/EmbeddedFiles*/Limits*[]:Ref", fileSpecs(0).Item1)
    doc.SetInfo(doc.Root, "/Names*/EmbeddedFiles*/Limits*[]:Ref", fileSpecs(fileSpecs.Count - 1).Item1)
    doc.SetInfo(doc.Root, "/Collection*/D:Text", files(0))
  End Using
End Sub