GenerationTest.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using QuestPDF.Fluent;
  2. using QuestPDF.Infrastructure;
  3. namespace QuestPDF.ZUGFeRD;
  4. public class Tests
  5. {
  6. [Test]
  7. public void ZUGFeRD_Test()
  8. {
  9. // TODO: Please make sure that you are eligible to use the Community license.
  10. // To learn more about the QuestPDF licensing, please visit:
  11. // https://www.questpdf.com/pricing.html
  12. QuestPDF.Settings.License = LicenseType.Community;
  13. Document
  14. .Create(document =>
  15. {
  16. document.Page(page =>
  17. {
  18. page.Content().Text("Your invoice content");
  19. });
  20. })
  21. .WithSettings(new DocumentSettings { PdfA = true }) // PDF/A-3b
  22. .GeneratePdf("invoice.pdf");
  23. DocumentOperation
  24. .LoadFile("invoice.pdf")
  25. .AddAttachment(new DocumentOperation.DocumentAttachment
  26. {
  27. Key = "factur-zugferd",
  28. FilePath = "resource-factur-x.xml",
  29. AttachmentName = "factur-x.xml",
  30. MimeType = "text/xml",
  31. Description = "Factur-X Invoice",
  32. Relationship = DocumentOperation.DocumentAttachmentRelationship.Source,
  33. CreationDate = DateTime.UtcNow,
  34. ModificationDate = DateTime.UtcNow
  35. })
  36. .ExtendMetadata(File.ReadAllText("resource-zugferd-metadata.xml"))
  37. .Save("zugferd-invoice.pdf");
  38. }
  39. }