ImageTests.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using QuestPDF.ConformanceTests.TestEngine;
  2. using QuestPDF.Drawing;
  3. using QuestPDF.Fluent;
  4. using QuestPDF.Helpers;
  5. using QuestPDF.Infrastructure;
  6. namespace QuestPDF.ConformanceTests;
  7. internal class ImageTests : ConformanceTestBase
  8. {
  9. protected override Document GetDocumentUnderTest()
  10. {
  11. var imageData = File.ReadAllBytes("Resources/photo.jpeg");
  12. return Document
  13. .Create(document =>
  14. {
  15. document.Page(page =>
  16. {
  17. page.Margin(60);
  18. page.Content()
  19. .PaddingVertical(30)
  20. .Column(column =>
  21. {
  22. column.Spacing(25);
  23. column.Item()
  24. .SemanticHeader1()
  25. .Text("Conformance Test: Images")
  26. .FontSize(24)
  27. .Bold()
  28. .FontColor(Colors.Blue.Darken2);
  29. column.Item()
  30. .Width(300)
  31. .SemanticImage("Sample image description")
  32. .Column(column =>
  33. {
  34. column.Item().Image(imageData);
  35. column.Item().PaddingTop(5).AlignCenter().SemanticCaption().Text("Sample image caption");
  36. });
  37. });
  38. });
  39. });
  40. }
  41. protected override SemanticTreeNode? GetExpectedSemanticTree()
  42. {
  43. return ExpectedSemanticTree.DocumentRoot(root =>
  44. {
  45. root.Child("H1", h1 => h1.Alt("Conformance Test: Images"));
  46. root.Child("Figure", figure =>
  47. {
  48. figure.Alt("Sample image description");
  49. figure.Child("Caption", caption => caption.Child("P"));
  50. });
  51. });
  52. }
  53. }