Guest User

Untitled

a guest
Feb 16th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. using System.IO;
  2. using iTextSharp.text;
  3. using iTextSharp.text.pdf;
  4.  
  5. namespace PdfGenerator.Generator
  6. {
  7. public class Generator
  8. {
  9. public byte[] CreateFile(string name)
  10. {
  11. // Default
  12. if (string.IsNullOrEmpty(name)) name = "World";
  13.  
  14. // Document initiation
  15. Document document = new Document(PageSize.A4);
  16.  
  17. using (MemoryStream stream = new MemoryStream())
  18. {
  19. using (PdfWriter writer = PdfWriter.GetInstance(document, stream))
  20. {
  21. // Opening the document allow us to write content
  22. document.Open();
  23. // Add a simple phrase to the document
  24. document.Add(new Paragraph($"Hello {name}!"));
  25. // Close the document
  26. document.Close();
  27.  
  28. return stream.ToArray();
  29. }
  30. }
  31. }
  32. }
  33. }
Add Comment
Please, Sign In to add comment