ExceptionDocument.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using QuestPDF.Drawing;
  2. using QuestPDF.Fluent;
  3. using QuestPDF.Helpers;
  4. using QuestPDF.Infrastructure;
  5. namespace QuestPDF.Previewer;
  6. public class ExceptionDocument : IDocument
  7. {
  8. private Exception Exception { get; }
  9. public ExceptionDocument(Exception exception)
  10. {
  11. Exception = exception;
  12. }
  13. public DocumentMetadata GetMetadata()
  14. {
  15. return DocumentMetadata.Default;
  16. }
  17. public void Compose(IDocumentContainer document)
  18. {
  19. document.Page(page =>
  20. {
  21. page.Size(PageSizes.A4);
  22. page.Margin(1, Unit.Inch);
  23. page.PageColor(Colors.Red.Lighten4);
  24. page.DefaultTextStyle(x => x.FontSize(16));
  25. page.Header()
  26. .BorderBottom(2)
  27. .BorderColor(Colors.Red.Medium)
  28. .PaddingBottom(5)
  29. .Text("Ooops! Something went wrong...").FontSize(28).FontColor(Colors.Red.Medium).Bold();
  30. page.Content().PaddingVertical(20).Column(column =>
  31. {
  32. var currentException = Exception;
  33. while (currentException != null)
  34. {
  35. column.Item().Text(currentException.GetType().Name).FontSize(20).SemiBold();
  36. column.Item().Text(currentException.Message).FontSize(14);
  37. column.Item().PaddingTop(10).Text(currentException.StackTrace).FontSize(10).Light();
  38. currentException = currentException.InnerException;
  39. if (currentException != null)
  40. column.Item().PaddingVertical(15).LineHorizontal(2).LineColor(Colors.Red.Medium);
  41. }
  42. });
  43. });
  44. }
  45. }