Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.IO;
- using iTextSharp.text;
- using iTextSharp.text.pdf;
- namespace PdfGenerator.Generator
- {
- public class Generator
- {
- public byte[] CreateFile(string name)
- {
- // Default
- if (string.IsNullOrEmpty(name)) name = "World";
- // Document initiation
- Document document = new Document(PageSize.A4);
- using (MemoryStream stream = new MemoryStream())
- {
- using (PdfWriter writer = PdfWriter.GetInstance(document, stream))
- {
- // Opening the document allow us to write content
- document.Open();
- // Add a simple phrase to the document
- document.Add(new Paragraph($"Hello {name}!"));
- // Close the document
- document.Close();
- return stream.ToArray();
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment