ImageTests.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. return Document
  25. .Create(document =>
  26. {
  27. document.Page(page =>
  28. {
  29. page.Margin(60);
  30. page.Content()
  31. .PaddingVertical(30)
  32. .Column(column =>
  33. {
  34. column.Item()
  35. .ExtendVertical()
  36. .AlignMiddle()
  37. .SemanticHeader1()
  38. .Text("Conformance Test:\nImages")
  39. .FontSize(36)
  40. .Bold()
  41. .FontColor(Colors.Blue.Darken2);
  42. column.Item().PageBreak();
  43. column.Item()
  44. .SemanticImage("Sample image description")
  45. .Column(column =>
  46. {
  47. column.Item().Width(300).Image(imagePath);
  48. column.Item().SemanticCaption().Text("Sample image caption");
  49. });
  50. });
  51. });
  52. })
  53. .WithMetadata(new DocumentMetadata
  54. {
  55. Language = "en-US",
  56. Title = "Conformance Test",
  57. Subject = "Images"
  58. });
  59. }
  60. protected override SemanticTreeNode? GetExpectedSemanticTree()
  61. {
  62. throw new NotImplementedException();
  63. }
  64. }