GenerationTest.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. .WithMetadata(new DocumentMetadata
  22. {
  23. Title = "Conformance Test: ZUGFeRD",
  24. Author = "SampleCompany",
  25. Subject = "ZUGFeRD Test Document",
  26. Language = "en-US"
  27. })
  28. .WithSettings(new DocumentSettings { PdfA = true }) // PDF/A-3b
  29. .GeneratePdf("invoice.pdf");
  30. DocumentOperation
  31. .LoadFile("invoice.pdf")
  32. .AddAttachment(new DocumentOperation.DocumentAttachment
  33. {
  34. Key = "factur-zugferd",
  35. FilePath = "resource-factur-x.xml",
  36. AttachmentName = "factur-x.xml",
  37. MimeType = "text/xml",
  38. Description = "Factur-X Invoice",
  39. Relationship = DocumentOperation.DocumentAttachmentRelationship.Source,
  40. CreationDate = DateTime.UtcNow,
  41. ModificationDate = DateTime.UtcNow
  42. })
  43. .ExtendMetadata(File.ReadAllText("resource-zugferd-metadata.xml"))
  44. .Save("zugferd-invoice.pdf");
  45. }
  46. }