''
'' This code is part of Document Solutions for PDF demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
'' Shows how to set various document properties such as PDF version, document info And metadata.
Public Class DocProperties
Sub CreatePDF(ByVal stream As Stream)
'' Create a new PDF document:
Dim doc = New GcPdfDocument()
'' While normally the PDF Version written into the document is determined automatically
'' (as the minimal version needed for the features actually used in this document),
'' it can be explicitly set:
doc.PdfVersion = "1.7"
'' By default, GcPdfDocument uses compression level 6 to reduce the file size.
'' Setting the level to 0 will result in uncompressed PDF:
doc.CompressionLevel = 0
'' By default, font subsets containing just the glyphs used in the document,
'' are embedded. This can be changed to embed whole fonts (which may result in
'' huge file size) or to not embed fonts as we do here (embedding can also
'' be controlled for individual fonts using the GcPdfDocument.Fonts collection):
doc.FontEmbedMode = FontEmbedMode.NotEmbed
''
'' Document properties such as title, author etc. can be set on GcPdfDocument.DocumentInfo,
'' but it should be noted that similar properties can be set in the GcPdfDocument.Metadata
'' and in most PDF readers properties set in metadata (see below) take precedence.
'' Here we set some of the properties available in DocumentInfo:
doc.DocumentInfo.Title = "DsPdf Document Info Sample"
doc.DocumentInfo.Author = "Jaime Smith"
doc.DocumentInfo.Subject = "GcPdfDocument.DocumentInfo"
doc.DocumentInfo.Producer = "DsPdfWeb Producer"
doc.DocumentInfo.Creator = "DsPdfWeb Creator"
'' For sample sake, set CreationDate to a date 10 years in the future:
doc.DocumentInfo.CreationDate = Util.TimeNow().AddYears(10)
''
'' Document metadata is available via the GcPdfDocument.Metadata property.
'' It provides a number of predefined accessors, such as:
doc.Metadata.Contributors.Add("contributor 1")
doc.Metadata.Contributors.Add("contributor 2")
doc.Metadata.Contributors.Add("contributor 3")
doc.Metadata.Copyright = "MESCIUS inc."
doc.Metadata.Creators.Add("Creator 1")
doc.Metadata.Creators.Add("Creator 2")
doc.Metadata.Creators.Add("Creator 3")
doc.Metadata.Description = "Sample document description"
doc.Metadata.Keywords.Add("Keyword1")
doc.Metadata.Keywords.Add("MESCIUS")
doc.Metadata.Keywords.Add("Keyword3")
doc.Metadata.Source = "Sourced by DsPdfWeb"
'' Arbitrary metadata can also be added using the AddProperty method:
doc.Metadata.AddProperty("http://purl.org/dc/elements/1.1/", "language", "English")
''
'' Finally, add a page and some text to the document and save it:
Dim rc = Util.AddNote("DsPdf Document Properties sample.", doc.NewPage())
''
Dim pg = doc.Pages.Last
Dim g = pg.Graphics
Dim tl = g.CreateTextLayout()
tl.AppendLine("See the source code of this demo (C# or VB.NET) for details on how to access the document properties and metadata.")
tl.AppendLine()
tl.AppendLine("When viewing the PDF, click the 'Document properties' button located in the top right part of the DsPdfViewer toolbar " +
"to see the properties associated with this PDF document.")
tl.MaxWidth = pg.Bounds.Width - rc.X * 2
tl.MarginLeft = rc.X
tl.MarginTop = rc.Bottom + 36
g.DrawTextLayout(tl, PointF.Empty)
'' Done:
doc.Save(stream)
End Sub
End Class