Helpers.cs 596 B

12345678910111213141516171819202122
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using QuestPDF.Fluent;
  5. using QuestPDF.Infrastructure;
  6. namespace QuestPDF.Examples.Engine
  7. {
  8. public static class Helpers
  9. {
  10. public static void GeneratePdfAndOpen(this Document document, string? fileName = null)
  11. {
  12. fileName ??= $"{Guid.NewGuid():D}.pdf";
  13. var filePath = Path.GetTempPath() + fileName;
  14. var documentData = document.GeneratePdf();
  15. File.WriteAllBytes(filePath, documentData);
  16. Process.Start("explorer", filePath);
  17. }
  18. }
  19. }