RenderingTest.cs 1.4 KB

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