QuestPdfManager.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Hotline.Ai.Quality;
  2. using QuestPDF.Fluent;
  3. using QuestPDF.Helpers;
  4. using QuestPDF.Infrastructure;
  5. namespace Hotline.Pdf
  6. {
  7. public class QuestPdfManager : IPdfManager
  8. {
  9. public void GeneratePdf(string title, string content, Stream stream) => CreateDocument(title, content).GeneratePdf(stream);
  10. public void GeneratePdf(string title, string content, string path) => CreateDocument(title, content).GeneratePdf(path);
  11. private Document CreateDocument(string title, string content)
  12. {
  13. return Document.Create(container =>
  14. {
  15. container.Page(page =>
  16. {
  17. page.Size(PageSizes.A4);
  18. page.Margin(2, Unit.Centimetre);
  19. page.PageColor(Colors.White);
  20. page.DefaultTextStyle(x => x.FontSize(20));
  21. page.Header()
  22. .Text(title)
  23. .SemiBold().FontSize(36).FontColor(Colors.Blue.Medium);
  24. page.Content()
  25. .PaddingVertical(1, Unit.Centimetre)
  26. .Column(x =>
  27. {
  28. x.Spacing(20);
  29. //x.Item().Text(Placeholders.LoremIpsum());
  30. //x.Item().Image(Placeholders.Image(200, 100));
  31. x.Item().Text(content);
  32. });
  33. page.Footer()
  34. .AlignCenter()
  35. .Text(x =>
  36. {
  37. x.Span("Page ");
  38. x.CurrentPageNumber();
  39. });
  40. });
  41. });
  42. }
  43. }
  44. }