'''' 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.'' Selected portions of the fetched invoice data are printed to the PDF generated by this sample.'' See ZugferdInfoExt for a similar sample that prints out all 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.PublicClassZugferdInfoFunctionCreatePDF(ByVal stream AsStream) AsInteger'' The sample invoice with ZUGFeRD data:Dim invoicePdf = Path.Combine("Resources", "PDFs", "zugferd-invoice.pdf") '' Text formats for output:Dim tfData = NewTextFormat() With { .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSans-Regular.ttf")), .FontSize = 12 }Dim tfStrong = NewTextFormat(tfData) With { .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSans-Bold.ttf")) }Dim tfLabels = NewTextFormat(tfData) With { .Font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSans-Italic.ttf")), .FontSize = 11 }Dim margin = 36 '' 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 culture = CultureInfo.CreateSpecificCulture("en-US") '' Print out the invoice data:Dim page = doc.NewPage()Dim g = page.GraphicsDim tl = g.CreateTextLayout() tl.MaxWidth = page.Size.Width tl.MaxHeight = page.Size.Height tl.MarginAll = margin '' The invoice header: tl.Append($"Invoice Number: ", tfLabels) tl.AppendLine($"{descriptor.InvoiceNo}", tfData) tl.Append($"Invoice Date: ", tfLabels) tl.AppendLine($"{descriptor.InvoiceDate.Value:yyyy-MM-dd}", tfData) tl.Append($"Seller Name: ", tfLabels) tl.AppendLine($"{descriptor.Seller.Name}", tfData) tl.Append($"Seller Address: ", tfLabels) tl.AppendLine($"{descriptor.Seller.Street}, {descriptor.Seller.City}, {descriptor.Seller.Postcode}, {descriptor.Seller.Country}", tfData) tl.Append($"Buyer Name: ", tfLabels) tl.AppendLine($"{descriptor.BuyerContact.Name}{descriptor.Buyer.Name}", tfData) tl.Append($"Buyer Address: ", tfLabels) tl.AppendLine($"{descriptor.Buyer.Street}, {descriptor.Buyer.City}, {descriptor.Buyer.Postcode}, {descriptor.Buyer.Country}", tfData) tl.AppendLine() '' The invoice positions: tl.TabStops = NewList(OfTabStop) From {NewTabStop(margin, TabStopAlignment.Leading),NewTabStop(page.Size.Width - margin * 2 - 144, TabStopAlignment.Trailing),NewTabStop(page.Size.Width - margin * 2, TabStopAlignment.Trailing) }Dim totals AsDecimal = 0Dim index = 1 tl.AppendLine($"#{vbTab}Name{vbTab}Quantity{vbTab}Amount", tfLabels) descriptor.TradeLineItems.ForEach(Sub(it) tl.AppendLine($"{index}{vbTab}{it.Name}{vbTab}{Convert.ToInt32(it.BilledQuantity)}{vbTab}{it.LineTotalAmount.Value.ToString("C", culture)}", tfData) index += 1 totals += it.LineTotalAmount.ValueEndSub )'' The invoice total: tl.AppendLine($"{vbTab}TOTAL:{vbTab}{vbTab}{totals.ToString("C", culture)}", tfStrong) g.DrawTextLayout(tl, PointF.Empty)'' Done: doc.Save(stream)Return doc.Pages.CountEndUsingElseReturn0EndIfEndUsingEndFunctionEndClass