ImageTests.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. [OneTimeSetUp]
  10. public void Setup()
  11. {
  12. // PDF/A-1a and PDF/A-1b require ICC profile version 2
  13. // prepare an image with ICC profile version 2
  14. var sourceImagePath = Path.Combine("Resources", "photo.jpeg");
  15. var targetImagePath = Path.Combine("Resources", "photo-icc2.jpeg");
  16. ImageHelpers.ConvertImageIccColorSpaceProfileToVersion2(sourceImagePath, targetImagePath);
  17. }
  18. protected override Document GetDocumentUnderTest()
  19. {
  20. var useImageWithIcc2 = TestContext.CurrentContext.Test.Arguments.FirstOrDefault() is PDFA_Conformance.PDFA_1A or PDFA_Conformance.PDFA_1B;
  21. var imagePath = useImageWithIcc2
  22. ? Path.Combine("Resources", "photo-icc2.jpeg")
  23. : Path.Combine("Resources", "photo.jpeg");
  24. var imageData = File.ReadAllBytes(imagePath);
  25. return Document
  26. .Create(document =>
  27. {
  28. document.Page(page =>
  29. {
  30. page.Margin(60);
  31. page.Content()
  32. .PaddingVertical(30)
  33. .Column(column =>
  34. {
  35. column.Spacing(25);
  36. column.Item()
  37. .SemanticHeader1()
  38. .Text("Conformance Test: Images")
  39. .FontSize(24)
  40. .Bold()
  41. .FontColor(Colors.Blue.Darken2);
  42. column.Item()
  43. .Width(300)
  44. .SemanticImage("Sample image description")
  45. .Column(column =>
  46. {
  47. column.Item().Image(imageData);
  48. column.Item().PaddingTop(5).AlignCenter().SemanticCaption().Text("Sample image caption");
  49. });
  50. });
  51. });
  52. });
  53. }
  54. protected override SemanticTreeNode? GetExpectedSemanticTree()
  55. {
  56. return ExpectedSemanticTree.DocumentRoot(root =>
  57. {
  58. root.Child("H1", h1 => h1.Alt("Conformance Test: Images"));
  59. root.Child("Figure", figure =>
  60. {
  61. figure.Alt("Sample image description");
  62. figure.Child("Caption", caption => caption.Child("P"));
  63. });
  64. });
  65. }
  66. }