''' <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