ClonePage.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. // This example shows how to duplicate a page of a PDF using the PageCollection.ClonePage() method.
  14. public class ClonePage
  15. {
  16. public int CreatePDF(Stream stream)
  17. {
  18. var doc = new GcPdfDocument();
  19. using var fs = File.OpenRead(Path.Combine("Resources", "PDFs", "Wetlands.pdf"));
  20. doc.Load(fs);
  21. // Clone the first page of the PDF, insert it into the beginning of the document:
  22. doc.Pages.ClonePage(0, 0, true, true);
  23.  
  24. // Save the PDF:
  25. doc.Save(stream);
  26. return doc.Pages.Count;
  27. }
  28. }
  29. }
  30.