diff --git a/QuestPDF.Examples/MinimalApiExamples.cs b/QuestPDF.Examples/MinimalApiExamples.cs new file mode 100644 index 0000000..ecea44e --- /dev/null +++ b/QuestPDF.Examples/MinimalApiExamples.cs @@ -0,0 +1,31 @@ +using System.Diagnostics; +using NUnit.Framework; +using QuestPDF.Examples.Engine; +using QuestPDF.Fluent; +using QuestPDF.Helpers; +using QuestPDF.Infrastructure; +using ShimSkiaSharp; +using SKTypeface = SkiaSharp.SKTypeface; + +namespace QuestPDF.Examples +{ + public class MinimalApiExamples + { + [Test] + public void MinimalApi() + { + Document + .Create(container => + { + container.Page(page => + { + page.Margin(2, Unit.Centimetre); + page.Content().Text("Hello PDF!"); + }); + }) + .GeneratePdf("hello.pdf"); + + Process.Start("explorer.exe", "hello.pdf"); + } + } +} \ No newline at end of file diff --git a/QuestPDF/Fluent/MinimalApi.cs b/QuestPDF/Fluent/MinimalApi.cs new file mode 100644 index 0000000..a37110d --- /dev/null +++ b/QuestPDF/Fluent/MinimalApi.cs @@ -0,0 +1,35 @@ +using System; +using QuestPDF.Drawing; +using QuestPDF.Infrastructure; + +namespace QuestPDF.Fluent +{ + public class Document : IDocument + { + private Action ContentSource { get; } + private DocumentMetadata Metadata { get; set; } = DocumentMetadata.Default; + + private Document(Action contentSource) + { + ContentSource = contentSource; + } + + public static Document Create(Action handler) + { + return new Document(handler); + } + + public Document WithMetadata(DocumentMetadata metadata) + { + Metadata = metadata ?? Metadata; + return this; + } + + #region IDocument + + public DocumentMetadata GetMetadata() => Metadata; + public void Compose(IDocumentContainer container) => ContentSource(container); + + #endregion + } +} \ No newline at end of file