HelloWorld.cs
  1. //
  2. // This code is part of Document Solutions for PDF demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using GrapeCity.Documents.Pdf;
  9. using GrapeCity.Documents.Text;
  10.  
  11. namespace DsPdfWeb.Demos
  12. {
  13. // One of the simplest ways to create a "Hello, World!" PDF with DsPdf.
  14. public class HelloWorld
  15. {
  16. public int CreatePDF(Stream stream)
  17. {
  18. // Create a new PDF document:
  19. var doc = new GcPdfDocument();
  20. // Add a page, get its graphics:
  21. var g = doc.NewPage().Graphics;
  22. // Draw a string on the page.
  23. // Notes:
  24. // - For simplicity, here we are using a standard PDF font
  25. // (the 14 standard fonts' metrics are built into DsPdf and are always available);
  26. // - DsPdf coordinates start at top left corner of a page, using 72 dpi by default:
  27. g.DrawString("Hello, World!",
  28. new TextFormat() { Font = StandardFonts.Times, FontSize = 12 },
  29. new PointF(72, 72));
  30. // Save the PDF:
  31. doc.Save(stream);
  32. return doc.Pages.Count;
  33. }
  34. }
  35. }
  36.