FileSpecification FileSpecification Function. FileSpecification Constructor. ABCpdf .NET PDF Library.

ABCpdf .net

 
   

FileSpecification Constructor

 

   
Syntax  

[C#]
FileSpecification(ObjectSoup soup)
FileSpecification(ObjectSoup soup, string path)

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

 

   

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

 

   

Notes
 

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.

 

   

Example
 

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.

[C#]
string[] files = {
  "Bentley.pdf",
  "Acrobat.pdf",
  "Noise.pdf",
  "ChecksModified.pdf",
};
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()) {
      subDoc.Read(file);
      data = subDoc.GetData();
    }
    EmbeddedFile embedFile = new EmbeddedFile(doc.ObjectSoup, data);
    embedFile.CompressFlate();
    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]);
  doc.Save("createportfolio.pdf");
}

[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()
        subDoc.Read(file)
        data = subDoc.GetData()
      End Using
      Dim embedFile As New EmbeddedFile(doc.ObjectSoup, data)
      embedFile.CompressFlate()
      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))
    Next
    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)
    Next
    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))
    doc.Save("createportfolio.pdf")
  End Using
End Sub