RenderingTest.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Diagnostics;
  3. using QuestPDF.Elements;
  4. using QuestPDF.Fluent;
  5. using QuestPDF.Infrastructure;
  6. namespace QuestPDF.Examples.Engine
  7. {
  8. public class RenderingTest
  9. {
  10. private string FileNamePrefix = "test";
  11. private decimal ImageDpi = 2;
  12. private Size Size { get; set; }
  13. private RenderingTest()
  14. {
  15. }
  16. public static RenderingTest Create()
  17. {
  18. return new RenderingTest();
  19. }
  20. public RenderingTest FileName(string fileName)
  21. {
  22. FileNamePrefix = fileName;
  23. return this;
  24. }
  25. public RenderingTest Dpi(decimal value = 2)
  26. {
  27. ImageDpi = value;
  28. return this;
  29. }
  30. public RenderingTest PageSize(int width, int height)
  31. {
  32. Size = new Size(width, height);
  33. return this;
  34. }
  35. public void Render(Action<IContainer> content)
  36. {
  37. var container = new Container();
  38. content.Invoke(container);
  39. Func<int, string> fileNameSchema = i => $"{FileNamePrefix}-${i}.png";
  40. var document = new SimpleDocument(container, Size);
  41. document.GenerateImages(fileNameSchema);
  42. Process.Start("explorer", fileNameSchema(0));
  43. }
  44. }
  45. }