VintaSoft Imaging .NET SDK v8.6
Vintasoft.Imaging.Pdf.Tree.FileAttachments Namespace / PdfAttachmentCollectionSchema Class
Members Example



In This Topic
    PdfAttachmentCollectionSchema Class
    In This Topic
    Represents the dictionary that represents schema of PDF attachment collection.
    Object Model
    PdfAttachmentCollectionSchema ClassPdfAttachmentCollectionSchemaField Class
    Syntax
    Remarks
    Each key name is chosen at the discretion of the producer. The key name of each field is used to identify a corresponding data fields (Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFileSpecification.DataFields) in a file specification.
    Example
    This example shows how to create the schema of PDF attachment collection.
    ''' <summary>
    ''' Creates new PDF document with portfolio and portfolio schema:
    ''' </summary>
    ''' <param name="outputPdfFilename">The output PDF filename.</param>
    Public Shared Sub TestPdfAttachmentCollectionSchema(outputPdfFilename As String)
        ' create PDF document (version 1.7)
        Using document As New Vintasoft.Imaging.Pdf.PdfDocument(outputPdfFilename, Vintasoft.Imaging.Pdf.PdfFormat.Pdf_17)
            ' add page to PDF document
            Dim page As Vintasoft.Imaging.Pdf.Tree.PdfPage = document.Pages.Add(Vintasoft.Imaging.PaperSizeKind.A4)
                
            ' draw text on first page
            Using g As Vintasoft.Imaging.Pdf.Drawing.PdfGraphics = page.GetGraphics()
                Dim textBox As New Vintasoft.Imaging.Pdf.Drawing.GraphicsFigures.TextBoxFigure()
                textBox.Font = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman)
                textBox.FontSize = 30
                textBox.Location = New System.Drawing.PointF(0, 0)
                textBox.Size = page.MediaBox.Size
                textBox.TextAlignment = Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Top Or Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Left Or Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Right
                textBox.TextBrush = New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black)
                textBox.Text = "This document is Portfolio" & vbLf & "(Attachment Collection)" & vbLf & "To view Portfolio you should use PDF viewer compatible with PDF 1.7 ExtensionLevel 3."
                textBox.Draw(g)
            End Using
                
            ' create attachements
            document.CreateAttachments(True)
                
            ' set viewer settings
            document.Attachments.View = Vintasoft.Imaging.Pdf.Tree.FileAttachments.AttachmentCollectionViewMode.DetailsMode
            document.Attachments.SplitterBar = New Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSplitterBar(document)
            document.Attachments.SplitterBar.Direction = Vintasoft.Imaging.Pdf.Tree.FileAttachments.AttachmentCollectionSplitterBarDirection.None
            document.DocumentViewMode = Vintasoft.Imaging.Pdf.PdfDocumentViewMode.UseAttachments
                
            ' create folder and files
            Dim folder1 As Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentFolder = document.Attachments.RootFolder.AddFolder("Folder1")
            folder1.CreationDate = System.DateTime.Now
            Dim file1 As Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFileSpecification = AddFile(document.Attachments.RootFolder, "File1.txt", "Test File1")
            file1.CreationDate = System.DateTime.Now
            Dim file2 As Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFileSpecification = AddFile(document.Attachments.RootFolder, "File2.txt", "Test File2")
            file2.CreationDate = System.DateTime.Now
                
                
            ' create portfolio schema
            document.Attachments.Schema = New Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSchema(document)
                
            ' "File Name" column
            document.Attachments.Schema.Add("Filename", New Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSchemaField(document, "File Name", Vintasoft.Imaging.Pdf.Tree.FileAttachments.AttachmentCollectionSchemaFieldDataType.Filename))
            document.Attachments.Schema("Filename").Order = 0
                
            ' "Uncompressed Size" column
            document.Attachments.Schema.Add("UncompressedSize", New Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSchemaField(document, "Uncompressed Size", Vintasoft.Imaging.Pdf.Tree.FileAttachments.AttachmentCollectionSchemaFieldDataType.UncompressedSize))
            document.Attachments.Schema("UncompressedSize").Order = 1
                
            ' "Creation Date" column
            document.Attachments.Schema.Add("CreationDate", New Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSchemaField(document, "Creation Date", Vintasoft.Imaging.Pdf.Tree.FileAttachments.AttachmentCollectionSchemaFieldDataType.CreationDate))
            document.Attachments.Schema("CreationDate").Order = 2
                
            ' "Description" column
            document.Attachments.Schema.Add("Description", New Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSchemaField(document, "Description", Vintasoft.Imaging.Pdf.Tree.FileAttachments.AttachmentCollectionSchemaFieldDataType.FileDescription))
            document.Attachments.Schema("Description").Order = 3
            ' set Description field as editable
            document.Attachments.Schema("Description").IsSupportsEditing = True
                
            ' "UserName" custom column (string data)
            Dim userNameFieldName As String = "adobe:UserName"
            document.Attachments.Schema.Add(userNameFieldName, New Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSchemaField(document, "User Name", Vintasoft.Imaging.Pdf.Tree.FileAttachments.AttachmentCollectionSchemaFieldDataType.[String]))
            document.Attachments.Schema(userNameFieldName).Order = 4
            ' disable editing of UserName field
            document.Attachments.Schema(userNameFieldName).IsSupportsEditing = False
                
            ' invisible schema field that is used for sorting attachment collection items
            Dim orderFieldName As String = "Order"
            document.Attachments.Schema.Add(orderFieldName, New Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSchemaField(document, "Order", Vintasoft.Imaging.Pdf.Tree.FileAttachments.AttachmentCollectionSchemaFieldDataType.Number))
            document.Attachments.Schema(orderFieldName).Order = 5
            document.Attachments.Schema(orderFieldName).IsVisible = False
                
            ' specify the sorting order: first sort by "Order" field, second sort by "Filename" field
            document.Attachments.Sort = New Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSort(document)
            document.Attachments.Sort.FieldNames = New String() {orderFieldName, "Filename"}
                
                
            ' create data fields of Folder1
            folder1.DataFields = New Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentDataFieldCollection(document)
            folder1.DataFields.Add(userNameFieldName, "User of Folder1")
            folder1.DataFields.Add(orderFieldName, 0)
                
            ' create data fields of File1
            file1.DataFields = New Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentDataFieldCollection(document)
            file1.DataFields.Add(userNameFieldName, "User of File1")
            file1.DataFields.Add(orderFieldName, 1)
                
            ' create data fields of File2
            file2.DataFields = New Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentDataFieldCollection(document)
            file2.DataFields.Add(userNameFieldName, "User of File2")
            file2.DataFields.Add(orderFieldName, 2)
                
            ' set descriptions
            folder1.Description = "Is empty folder."
            file1.Description = "Description of File1"
            file2.Description = "Description of File2"
                
                
            ' save changes in PDF document
            document.SaveChanges()
        End Using
    End Sub
                
    ''' <summary>
    ''' Adds the file to specified portfolio folder.
    ''' </summary>
    ''' <param name="folder">The portfolio folder.</param>
    ''' <param name="filename">The filename.</param>
    ''' <param name="fileContent">Content of the file.</param>
    ''' <returns>Embedded file specification that contains added file.</returns>
    Private Shared Function AddFile(folder As Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentFolder, filename As String, fileContent As String) As Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFileSpecification
        Using stream As New System.IO.MemoryStream()
            Using writer As System.IO.TextWriter = New System.IO.StreamWriter(stream)
                writer.Write(fileContent)
                writer.Flush()
                stream.Position = 0
                Dim embeddedFile As New Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFile(folder.Document, stream)
                Return folder.AddFile(embeddedFile, filename)
            End Using
        End Using
    End Function
    /// <summary>
    /// Creates new PDF document with portfolio and portfolio schema:
    /// </summary>
    /// <param name="outputPdfFilename">The output PDF filename.</param>
    public static void TestPdfAttachmentCollectionSchema(string outputPdfFilename)
    {
        // create PDF document (version 1.7)
        using (Vintasoft.Imaging.Pdf.PdfDocument document =
            new Vintasoft.Imaging.Pdf.PdfDocument(outputPdfFilename, Vintasoft.Imaging.Pdf.PdfFormat.Pdf_17))
        {
            // add page to PDF document
            Vintasoft.Imaging.Pdf.Tree.PdfPage page = document.Pages.Add(Vintasoft.Imaging.PaperSizeKind.A4);
                
            // draw text on first page
            using (Vintasoft.Imaging.Pdf.Drawing.PdfGraphics g = page.GetGraphics())
            {
                Vintasoft.Imaging.Pdf.Drawing.GraphicsFigures.TextBoxFigure textBox =
                    new Vintasoft.Imaging.Pdf.Drawing.GraphicsFigures.TextBoxFigure();
                textBox.Font = document.FontManager.GetStandardFont(
                    Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman);
                textBox.FontSize = 30;
                textBox.Location = new System.Drawing.PointF(0, 0);
                textBox.Size = page.MediaBox.Size;
                textBox.TextAlignment =
                    Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Top |
                    Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Left |
                    Vintasoft.Imaging.Pdf.Drawing.PdfContentAlignment.Right;
                textBox.TextBrush = new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black);
                textBox.Text = "This document is Portfolio\n(Attachment Collection)\nTo view Portfolio you should use PDF viewer compatible with PDF 1.7 ExtensionLevel 3.";
                textBox.Draw(g);
            }
                
            // create attachements
            document.CreateAttachments(true);
                
            // set viewer settings
            document.Attachments.View = Vintasoft.Imaging.Pdf.Tree.FileAttachments.AttachmentCollectionViewMode.DetailsMode;
            document.Attachments.SplitterBar = new Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSplitterBar(document);
            document.Attachments.SplitterBar.Direction = Vintasoft.Imaging.Pdf.Tree.FileAttachments.AttachmentCollectionSplitterBarDirection.None;
            document.DocumentViewMode = Vintasoft.Imaging.Pdf.PdfDocumentViewMode.UseAttachments;
                
            // create folder and files
            Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentFolder folder1 = document.Attachments.RootFolder.AddFolder("Folder1");
            folder1.CreationDate = System.DateTime.Now;
            Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFileSpecification file1 = AddFile(document.Attachments.RootFolder, "File1.txt", "Test File1");
            file1.CreationDate = System.DateTime.Now;
            Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFileSpecification file2 = AddFile(document.Attachments.RootFolder, "File2.txt", "Test File2");
            file2.CreationDate = System.DateTime.Now;
                
                
            // create portfolio schema
            document.Attachments.Schema =
                new Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSchema(document);
                
            // "File Name" column
            document.Attachments.Schema.Add("Filename",
                new Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSchemaField(document, "File Name",
                    Vintasoft.Imaging.Pdf.Tree.FileAttachments.AttachmentCollectionSchemaFieldDataType.Filename));
            document.Attachments.Schema["Filename"].Order = 0;
                
            // "Uncompressed Size" column
            document.Attachments.Schema.Add("UncompressedSize",
                new Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSchemaField(document, "Uncompressed Size",
                    Vintasoft.Imaging.Pdf.Tree.FileAttachments.AttachmentCollectionSchemaFieldDataType.UncompressedSize));
            document.Attachments.Schema["UncompressedSize"].Order = 1;
                
            // "Creation Date" column
            document.Attachments.Schema.Add("CreationDate",
                new Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSchemaField(document, "Creation Date",
                    Vintasoft.Imaging.Pdf.Tree.FileAttachments.AttachmentCollectionSchemaFieldDataType.CreationDate));
            document.Attachments.Schema["CreationDate"].Order = 2;
                
            // "Description" column
            document.Attachments.Schema.Add("Description",
                new Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSchemaField(document, "Description",
                    Vintasoft.Imaging.Pdf.Tree.FileAttachments.AttachmentCollectionSchemaFieldDataType.FileDescription));
            document.Attachments.Schema["Description"].Order = 3;
            // set Description field as editable
            document.Attachments.Schema["Description"].IsSupportsEditing = true;
                
            // "UserName" custom column (string data)
            string userNameFieldName = "adobe:UserName";
            document.Attachments.Schema.Add(userNameFieldName,
                new Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSchemaField(document, "User Name",
                    Vintasoft.Imaging.Pdf.Tree.FileAttachments.AttachmentCollectionSchemaFieldDataType.String));
            document.Attachments.Schema[userNameFieldName].Order = 4;
            // disable editing of UserName field
            document.Attachments.Schema[userNameFieldName].IsSupportsEditing = false;
                
            // invisible schema field that is used for sorting attachment collection items
            string orderFieldName = "Order";
            document.Attachments.Schema.Add(orderFieldName,
                new Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSchemaField(document, "Order",
                    Vintasoft.Imaging.Pdf.Tree.FileAttachments.AttachmentCollectionSchemaFieldDataType.Number));
            document.Attachments.Schema[orderFieldName].Order = 5;
            document.Attachments.Schema[orderFieldName].IsVisible = false;
                
            // specify the sorting order: first sort by "Order" field, second sort by "Filename" field
            document.Attachments.Sort = new Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSort(document);
            document.Attachments.Sort.FieldNames = new string[] { orderFieldName, "Filename" };
                
                
            // create data fields of Folder1
            folder1.DataFields = new Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentDataFieldCollection(document);
            folder1.DataFields.Add(userNameFieldName, "User of Folder1");
            folder1.DataFields.Add(orderFieldName, 0);
                
            // create data fields of File1
            file1.DataFields = new Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentDataFieldCollection(document);
            file1.DataFields.Add(userNameFieldName, "User of File1");
            file1.DataFields.Add(orderFieldName, 1);
                
            // create data fields of File2
            file2.DataFields = new Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentDataFieldCollection(document);
            file2.DataFields.Add(userNameFieldName, "User of File2");
            file2.DataFields.Add(orderFieldName, 2);
                
            // set descriptions
            folder1.Description = "Is empty folder.";
            file1.Description = "Description of File1";
            file2.Description = "Description of File2";
                
                
            // save changes in PDF document
            document.SaveChanges();
        }
    }
                
    /// <summary>
    /// Adds the file to specified portfolio folder.
    /// </summary>
    /// <param name="folder">The portfolio folder.</param>
    /// <param name="filename">The filename.</param>
    /// <param name="fileContent">Content of the file.</param>
    /// <returns>Embedded file specification that contains added file.</returns>
    private static Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFileSpecification AddFile(
        Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentFolder folder,
        string filename,
        string fileContent)
    {
        using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
        {
            using (System.IO.TextWriter writer = new System.IO.StreamWriter(stream))
            {
                writer.Write(fileContent);
                writer.Flush();
                stream.Position = 0;
                Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFile embeddedFile =
                    new Vintasoft.Imaging.Pdf.Tree.PdfEmbeddedFile(folder.Document, stream);
                return folder.AddFile(embeddedFile, filename);
            }
        }
    }
    Inheritance Hierarchy

    System.Object
       Vintasoft.Imaging.Pdf.Tree.PdfTreeNodeBase
          Vintasoft.Imaging.Pdf.Tree.PdfNamedDictionaryBase<T>
             Vintasoft.Imaging.Pdf.Tree.PdfNamedDictionary<T>
                Vintasoft.Imaging.Pdf.Tree.FileAttachments.PdfAttachmentCollectionSchema

    Requirements

    Target Platforms: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also