''
'' This code is part of Document Solutions for PDF .NET demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports System.Collections.Generic
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Pdf.Layers
Imports GrapeCity.Documents.Pdf.Annotations
Imports GrapeCity.Documents.Pdf.Graphics
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Drawing
Imports GCTEXT = GrapeCity.Documents.Text
Imports GCDRAW = GrapeCity.Documents.Drawing
Public Class LangLayers
' Layer names correspond to included languages:
Private Const c_lyrEN As String = "English"
Private Const c_lyrFR As String = "French"
Private Const c_lyrRU As String = "Russian"
Public Function CreatePDF(ByVal stream As Stream) As Integer
Dim doc = New GcPdfDocument()
' Add layers for different languages,
' set default visibility to false for all languages except one:
doc.OptionalContent.AddLayer(c_lyrEN)
doc.OptionalContent.AddLayer(c_lyrFR)
doc.OptionalContent.SetLayerDefaultState(c_lyrFR, False)
doc.OptionalContent.AddLayer(c_lyrRU)
doc.OptionalContent.SetLayerDefaultState(c_lyrRU, False)
Dim page = doc.Pages.Add()
page.Landscape = True
Dim g = page.Graphics
' Background image:
Dim picBack = GCDRAW.Image.FromFile(Path.Combine("Resources", "ImagesBis", "2020-website-gcdocs-headers_tall.png"))
Dim rc = page.Bounds
rc.Height *= 0.5F
g.DrawImage(picBack, rc, Nothing, ImageAlign.StretchImage)
' Image with some screenshots:
Dim picScreens = GCDRAW.Image.FromFile(Path.Combine("Resources", "ImagesBis", "docs-main-02.png"))
Dim picScreensSize = New SizeF(picScreens.Width \ 2, picScreens.Height \ 2)
Dim rcScreen = New RectangleF(
page.Bounds.Width - picScreensSize.Width - 8,
8,
picScreensSize.Width,
picScreensSize.Height)
g.DrawImage(picScreens, rcScreen, Nothing, ImageAlign.StretchImage)
' Text formats:
Dim fReg = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSans-Regular.ttf"))
Dim fBold = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSans-Bold.ttf"))
Dim tfNorm = New TextFormat() With {.Font = fReg, .FontSize = 9, .ForeColor = Color.White}
Dim tfCap = New TextFormat(tfNorm) With {.FontSize = tfNorm.FontSize * 1.6F}
Dim tfBlack = New TextFormat(tfNorm) With {.ForeColor = Color.FromArgb(32, 32, 32)}
Dim tfHdr = New TextFormat(tfBlack) With {.Font = fBold}
' Draw English texts:
Dim ip = New PointF(36, 24)
Dim ip1 = ip
ip = DrawText1(c_lyrEN, doc, g, ip1, tfNorm, tfCap)
ip.Y += 82
Dim ip2 = ip
DrawText2(c_lyrEN, doc, g, ip2, tfHdr, tfBlack)
' Draw French texts:
DrawText1(c_lyrFR, doc, g, ip1, tfNorm, tfCap)
DrawText2(c_lyrFR, doc, g, ip2, tfHdr, tfBlack)
' Draw Russian texts:
DrawText1(c_lyrRU, doc, g, ip1, tfNorm, tfCap)
DrawText2(c_lyrRU, doc, g, ip2, tfHdr, tfBlack)
' Save the PDF:
doc.Save(stream)
Return doc.Pages.Count
End Function
Class Texts
Public Property Caption As String
Public Property SubCap As String
Public Property Bullet1 As String
Public Property Bullet2 As String
Public Property Bullet3 As String
Public Property Bullet4 As String
Public Property Bullet5 As String
Public Property Bullet6 As String
Public Property Pt1Hdr As String
Public Property Pt1Txt As String
Public Property Pt2Hdr As String
Public Property Pt2Txt As String
Public Property Pt3Hdr As String
Public Property Pt3Txt As String
Public Property Pt4Hdr As String
Public Property Pt4Txt As String
Public Property Pt5Hdr As String
Public Property Pt5Txt As String
Public Property Pt6Hdr As String
Public Property Pt6Txt As String
End Class
Private Shared _texts As Dictionary(Of String, Texts) = New Dictionary(Of String, Texts)() From {
{"English", New Texts() With {
.Caption = "Fast, Efficient Document APIs for .NET 8 and Java Applications",
.SubCap = "Take total control of your documents with ultra-fast, low-footprint APIs for enterprise apps.",
.Bullet1 = "Generate, load, edit, save XLSX spreadsheets, PDF, Images, and DOCX files using C# .NET, VB.NET, or Java",
.Bullet2 = "View, edit, print, fill and submit documents in JavaScript PDF Viewer and PDF Editor",
.Bullet3 = "Fully compatible with Windows, macOS, and Linux",
.Bullet4 = "No dependencies on Excel, Word, or Acrobat",
.Bullet5 = "Deploy to a variety of cloud-based services, including Azure, AWS, and AWS Lambda",
.Bullet6 = "Product available individually or as a bundle",
.Pt1Hdr = "High-Speed, Small Footprint, No Dependencies",
.Pt1Txt = "The .NET 8 Document API is designed to generate large, optimized documents fast – while remaining lightweight and extensible, giving you greater flexibility, and creativity in developing your applications.",
.Pt2Hdr = "Full .NET Support for Windows, Linux, and Mac",
.Pt2Txt = "Develop for any .NET platform or major operating system with a single code base. Use in your apps for .NET, C#, VB.NET .NET Framework, Mono, Xamarin.iOS, and Xamarin.Android.",
.Pt3Hdr = "Comprehensive, Highly Programmable",
.Pt3Txt = "Do more with your Excel spreadsheets, Word documents, PDFs, and images with our feature-rich APIs. Create, load, edit, save, and convert your business documents with intuitive tools.",
.Pt4Hdr = "Zero Dependencies",
.Pt4Txt = "Generate and edit digital documents in your applications without any dependencies on Adobe Acrobat, Microsoft Word, or Excel. Build your documents even faster with zero dependencies.",
.Pt5Hdr = "Deploy Apps to the Cloud",
.Pt5Txt = "Be everywhere with cloud-based deployment using NuGet and Document Solutions. You can now deploy to Azure, AWS, and AWS Lambda in a few short steps.",
.Pt6Hdr = "Supports Hundreds of Features",
.Pt6Txt = "Generate full-featured documents and nearly lossless imports! These APIs complete your toolkit through high-performance features, including Excel pivot tables, PDF digital signatures, and Word text comments."
}},
{"French", New Texts() With {
.Caption = "API de document rapides et efficaces pour les applications .NET 8 et Java",
.SubCap = "Prenez le contrôle total de vos documents avec des API ultra-rapides et à faible encombrement pour les applications d'entreprise.",
.Bullet1 = "Générez, chargez, modifiez et enregistrez des feuilles de calcul XLSX, des fichiers PDF, des images et des fichiers DOCX à l'aide de C# .NET, VB.NET ou Java",
.Bullet2 = "Affichez, modifiez, imprimez, remplissez et soumettez des documents dans JavaScript PDF Viewer et PDF Editor",
.Bullet3 = "Entièrement compatible avec Windows, macOS et Linux",
.Bullet4 = "Aucune dépendance à Excel, Word ou Acrobat",
.Bullet5 = "Déploiement sur une variété de services basés sur le cloud, y compris Azure, AWS et AWS Lambda",
.Bullet6 = "Produit disponible individuellement ou en lot",
.Pt1Hdr = "Haut vitesse, faible encombrement, aucune dépendance",
.Pt1Txt = "L'API de document .NET 8 est conçue pour générer rapidement des documents volumineux et optimisés, tout en restant léger et extensible, vous offrant une plus grande flexibilité et créativité dans le développement de vos applications.",
.Pt2Hdr = "Support complète de .NET pour Windows, Linux et Mac",
.Pt2Txt = "Développez pour n'importe quelle plate-forme .NET ou système d'exploitation majeur avec une base de code unique. À utiliser dans vos applications pour .NET, C#, VB.NET .NET Framework, Mono, Xamarin.iOS et Xamarin.Android.",
.Pt3Hdr = "Complet, hautement programmable",
.Pt3Txt = "Faites-en plus avec vos feuilles de calcul Excel, vos documents Word, vos PDF et vos images grâce à nos API riches en fonctionnalités. Créez, chargez, modifiez, enregistrez et convertissez vos documents commerciaux avec des outils intuitifs.",
.Pt4Hdr = "Zéro dépendances",
.Pt4Txt = "Générez et modifiez des documents numériques dans vos applications sans aucune dépendance à Adobe Acrobat, Microsoft Word ou Excel. Créez vos documents encore plus rapidement sans aucune dépendance.",
.Pt5Hdr = "Déployer des applications sur le cloud",
.Pt5Txt = "Soyez partout avec un déploiement basé sur le cloud à l'aide de NuGet et Document Solutions. Vous pouvez désormais déployer sur Azure, AWS et AWS Lambda en quelques étapes courtes.",
.Pt6Hdr = "Prend en charge des centaines de fonctionnalités",
.Pt6Txt = "Générez des documents complets et des importations presque sans pertes! Ces API complètent votre boîte à outils grâce à des fonctionnalités hautes performances, notamment des tableaux croisés dynamiques Excel, des signatures numériques PDF et des commentaires de texte Word."
}},
{"Russian", New Texts() With {
.Caption = "Document API - для быстрой и эффективной работы с офисными документами под .NET 8 и Java",
.SubCap = "Полный контроль над офисным документооборотом с помощью сверх-быстрых, нетребовательных к памяти библиотек Document API",
.Bullet1 = "Создание, загрузка, редактирование и сохранение файлов XLSX, PDF, DOCX и изображений из кода на C#, VB.NET и Java",
.Bullet2 = "Просмотр, редактирование, печать, заполнение и пересылка PDF файлов с помощью просмотрщика и редактора на чистом JavaScript",
.Bullet3 = "Полная совместимость с операционными системами Windows, macOS и Linux",
.Bullet4 = "Отсутствие зависимостей от Excel, Word и Acrobat",
.Bullet5 = "Развертывание на Azure, AWS и AWS Lambda",
.Bullet6 = "Продукты доступны индивидуально или в составе единой студии",
.Pt1Hdr = "Быстрые, маленькие библиотеки без внешних зависимостей",
.Pt1Txt = "Наши API созданы для генерации сложных оптимизированных документов с большой скоростью и малыми требованиями к памяти, для лёгкой и удобной разработки аппликаций.",
.Pt2Hdr = "Полная поддержка .NET под Windows, Linux и macOS",
.Pt2Txt = "Единый код для всех платформ и операционных систем, поддержка разработки на C# и VB.NET под .NET 8, .NET Framework, Mono, Xamarin.iOS и Xamarin.Android.",
.Pt3Hdr = "Функциональность и программируемость",
.Pt3Txt = "Полная поддержка функциональности MS Excel, MS Word и PDF документов и изображений. Создание, загрузка, редактирование, сохранение и конвертация документов.",
.Pt4Hdr = "Отсутствие внешних зависимостей",
.Pt4Txt = "Быстрое и эффективное создание и редактирование электронных документов без зависимостей от Adobe Acrobat, Microsoft Word и Excel.",
.Pt5Hdr = "Разворачивание аппликаций в ""облаке""",
.Pt5Txt = "Простое и удобное разворачивание аппликаций в Azure, AWS и AWS Lambda. Все зависимости от Document Solutions могут разрешаться через NuGet.",
.Pt6Hdr = "Широкая поддержка возможностей форматов",
.Pt6Txt = "Доступ практически ко всем возможностям, заложенным в спецификациях форматов документов - сводные таблицы Excel, множественные цифровые подписи PDF, комментарии и многое другое."
}}
}
' Draws the document caption and the main features bullet list on the blue background:
Private Shared Function DrawText1(lang As String, doc As GcPdfDocument, g As GcPdfGraphics, ip As PointF, tf As TextFormat, tfCap As TextFormat) As PointF
Dim txts = _texts(lang)
g.BeginLayer(lang)
Dim tl = g.CreateTextLayout()
tl.MaxWidth = 72 * 5
tl.AppendLine(txts.Caption, tfCap)
tl.AppendLine(tf)
tl.AppendLine(txts.SubCap, tf)
tl.AppendLine(tf)
g.DrawTextLayout(tl, ip)
' Bullet list:
ip.Y += tl.ContentHeight
tl.Clear()
Dim bullet As String = ChrW(&H2022) & ChrW(&H2003)
tl.FirstLineIndent = -g.MeasureString(bullet, tf).Width
tl.ParagraphSpacing += 4
tl.Append(bullet, tf)
tl.AppendLine(txts.Bullet1, tf)
tl.Append(bullet, tf)
tl.AppendLine(txts.Bullet2, tf)
tl.Append(bullet, tf)
tl.AppendLine(txts.Bullet3, tf)
tl.Append(bullet, tf)
tl.AppendLine(txts.Bullet4, tf)
tl.Append(bullet, tf)
tl.AppendLine(txts.Bullet5, tf)
tl.Append(bullet, tf)
tl.AppendLine(txts.Bullet6, tf)
g.DrawTextLayout(tl, ip)
g.EndLayer()
ip.Y += tl.ContentHeight
Return ip
End Function
' Draws the expanded descriptions of features in the lower part of the document:
Private Shared Sub DrawText2(lang As String, doc As GcPdfDocument, g As GcPdfGraphics, ip As PointF, tfHdr As TextFormat, tfBlack As TextFormat)
Dim picIcons = GCDRAW.Image.FromFile(Path.Combine("Resources", "ImagesBis", "2020-icon-sprites-dx.png"))
Dim iconSize = New SizeF(picIcons.Width \ 12, picIcons.Height \ 2)
Dim tl = g.CreateTextLayout()
tl.FirstLineIndent = 0
tl.MaxWidth = (doc.Pages(0).Bounds.Width - ip.X * 2 - 36) / 3
Dim ip1 = ip
Dim txts = _texts(lang)
DrawItem(ip, 0, txts.Pt1Hdr, txts.Pt1Txt, lang, tl, iconSize, g, picIcons, tfHdr, tfBlack)
ip.X += tl.MaxWidth.Value + 18
ip1.Y = Math.Max(ip1.Y, ip.Y + tl.ContentHeight)
DrawItem(ip, 1, txts.Pt2Hdr, txts.Pt2Txt, lang, tl, iconSize, g, picIcons, tfHdr, tfBlack)
ip.X += tl.MaxWidth.Value + 18
ip1.Y = Math.Max(ip1.Y, ip.Y + tl.ContentHeight)
DrawItem(ip, 2, txts.Pt3Hdr, txts.Pt3Txt, lang, tl, iconSize, g, picIcons, tfHdr, tfBlack)
ip1.Y = Math.Max(ip1.Y, ip.Y + tl.ContentHeight)
ip1.Y += iconSize.Height + 18
ip = ip1
DrawItem(ip, 3, txts.Pt4Hdr, txts.Pt4Txt, lang, tl, iconSize, g, picIcons, tfHdr, tfBlack)
ip.X += tl.MaxWidth.Value + 18
DrawItem(ip, 4, txts.Pt5Hdr, txts.Pt5Txt, lang, tl, iconSize, g, picIcons, tfHdr, tfBlack)
ip.X += tl.MaxWidth.Value + 18
DrawItem(ip, 5, txts.Pt6Hdr, txts.Pt6Txt, lang, tl, iconSize, g, picIcons, tfHdr, tfBlack)
End Sub
Private Shared Sub DrawItem(p As PointF, imgIdx As Integer, header As String, text As String,
lang As String, tl As TextLayout, iconSize As SizeF,
g As GcPdfGraphics, picIcons As GCDRAW.Image,
tfHdr As TextFormat, tfBlack As TextFormat)
If lang = c_lyrEN Then
' Draw icons just once:
Dim xImg = p.X + tl.MaxWidth.Value / 2 - iconSize.Width / 2
Dim xImgAll = xImg - imgIdx * iconSize.Width
Dim imgRc = New RectangleF(xImgAll, p.Y, iconSize.Width * 6, iconSize.Height)
Dim rcClip = New RectangleF(New PointF(xImg, p.Y), iconSize)
rcClip.Width -= 1
g.DrawImage(picIcons, imgRc, rcClip, ImageAlign.StretchImage)
End If
tl.Clear()
tl.AppendLine(header, tfHdr)
tl.AppendLine(text, tfBlack)
g.BeginLayer(lang)
g.DrawTextLayout(tl, New PointF(p.X, p.Y + iconSize.Height + 8))
g.EndLayer()
End Sub
End Class