MinimalApiExamples.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Diagnostics;
  2. using NUnit.Framework;
  3. using QuestPDF.Fluent;
  4. using QuestPDF.Helpers;
  5. using QuestPDF.Infrastructure;
  6. namespace QuestPDF.Examples
  7. {
  8. public class MinimalApiExamples
  9. {
  10. [Test]
  11. public void MinimalApi()
  12. {
  13. Document
  14. .Create(container =>
  15. {
  16. container.Page(page =>
  17. {
  18. page.Size(PageSizes.A4);
  19. page.Margin(2, Unit.Centimetre);
  20. page.PageColor(Colors.White);
  21. page.DefaultTextStyle(x => x.FontSize(20));
  22. page.Header()
  23. .Text("Hello PDF!")
  24. .SemiBold().FontSize(36).FontColor(Colors.Blue.Medium);
  25. page.Content()
  26. .PaddingVertical(1, Unit.Centimetre)
  27. .Column(x =>
  28. {
  29. x.Spacing(20);
  30. x.Item().Text(Placeholders.LoremIpsum());
  31. x.Item().Image(Placeholders.Image(200, 100));
  32. });
  33. page.Footer()
  34. .AlignCenter()
  35. .Text(x =>
  36. {
  37. x.Span("Page ");
  38. x.CurrentPageNumber();
  39. });
  40. });
  41. })
  42. .GeneratePdf("hello.pdf");
  43. Process.Start("explorer.exe", "hello.pdf");
  44. }
  45. }
  46. }