'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.LinqImportsSystem.ReflectionImportsSystem.Collections.GenericImportsSystem.GlobalizationImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.TextImportss2industries.ZUGFeRDImports GCTEXT = GrapeCity.Documents.Text '' This sample demonstrates how to retrieve invoice data from a ZUGFeRD compliant XML attachment.'' All ZUGFeRD data is printed to the PDF generated by this sample.'' See ZugferdInfo for a similar sample that prints selected portions of the ZUGFeRD data. '' The sample PDF invoice containing ZUGFeRD data which this sample uses as input'' was generated by ZugferdInvoice.'''' ZUGFeRD is a German e-invoicing standard based around PDF and XML file formats.'' Its poised to change the way invoices are handled and can be used by any sort of business.'' It will make invoice processing more efficient for senders and customers.'' For details please see www.ferd-net.de.'''' This sample uses the ZUGFeRD-csharp package'' to parse the ZUGFeRD-compatible XML that is attached to the invoice.PublicClassZugferdInfoExtFunctionCreatePDF(ByVal stream AsStream) AsInteger'' The sample invoice with ZUGFeRD data:Dim invoicePdf = Path.Combine("Resources", "PDFs", "zugferd-invoice.pdf") '' Output document:Dim doc = NewGcPdfDocument()Using fs = File.OpenRead(invoicePdf)'' Load the ZUGFeRD compliant invoice PDF:Dim invoice = NewGcPdfDocument() invoice.Load(fs) '' Get the ZUGFeRD attachment from the invoice by the ZUGFeRD 1.x standard file name:Dim attachment = invoice.EmbeddedFiles.Values.FirstOrDefault(Function(it) it.File.FileName = "ZUGFeRD-invoice.xml")If attachment IsNotNothingThenUsing xmlstream = attachment.GetStream()'' Load the invoice descriptor:Dim descriptor = InvoiceDescriptor.Load(xmlstream) Dim tl = NewTextLayout(72) tl.MaxWidth = doc.PageSize.Width tl.MaxHeight = doc.PageSize.Height tl.MarginAll = tl.Resolution tl.DefaultTabStops = 24 '' Recursively render all InvoiceDescriptor properties to text layout: tl.AppendLine($"{NameOf(InvoiceDescriptor)}:", _tfStrong)RenderProperties(descriptor, tl, 1) '' Write text layout to output PDF tl.PerformLayout(True)Dim topt = NewTextSplitOptions(tl)While (True)Dim rest AsTextLayout = NothingDim splitResult = tl.Split(topt, rest) doc.Pages.Add().Graphics.DrawTextLayout(tl, PointF.Empty)If splitResult <> SplitResult.SplitThenExitWhileEndIf tl = restEndWhile'' Done: doc.Save(stream)Return doc.Pages.CountEndUsingElseReturn0EndIfEndUsingEndFunction '' Recursively print all source's properties to text layout:SharedSubRenderProperties(ByVal source AsObject, ByVal tl AsTextLayout, ByVal level AsInteger)If source IsNothingThenReturnEndIfDim props = source.GetType().GetProperties()ForEach prop In propsRenderProperty(prop, source, tl, level)NextEndSub '' Text formats for output:PrivateSharedReadOnly_tfData = NewTextFormat() With { .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSans-Regular.ttf")), .FontSize = 12 }PrivateSharedReadOnly_tfStrong = NewTextFormat(_tfData) With { .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSans-Bold.ttf")) }PrivateSharedReadOnly_tfLabels = NewTextFormat(_tfData) With { .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSans-Italic.ttf")), .FontSize = 11 } '' Print a property:SharedSubRenderProperty(ByVal prop AsPropertyInfo, ByVal parent AsObject, ByVal tl AsTextLayout, ByVal level AsInteger)Dim space = String.EmptyFor i = 0To level - 1 space += vbTabNextDim name = prop.NameDim value = prop.GetValue(parent, Nothing)If value IsNothingThen tl.Append(space, _tfLabels) tl.AppendLine($"{name}:", _tfLabels)ElseIf (value.GetType().IsValueTypeOrElse value.GetType() IsGetType(String)) Then tl.Append(space, _tfLabels) tl.Append($"{name}: ", _tfLabels) tl.AppendLine(String.Format(CultureInfo.GetCultureInfo("en-US"), "{0}", value), _tfData)ElseIfTypeOf value IsIEnumerable(OfObject) ThenDim collection AsIEnumerable(OfObject) = CType(value, IEnumerable(OfObject))Dim index = 0ForEach item In collection tl.Append(space, _tfLabels) tl.AppendLine($"Collection item {name} [{index}]:", _tfStrong) index += 1RenderProperties(item, tl, level + 1)NextElse tl.Append(space, _tfLabels) tl.AppendLine($"Container {name}:", _tfStrong)RenderProperties(value, tl, level + 1)EndIfEndIfEndSubEndClass