[]
When working with an existing PDF file, a large amount of memory can be used, especially if it's a large file. Usually, you would have to load the entire document into memory, which can be pretty inefficient. DsPdf makes this process more resource-friendly by providing the GcPdfDocument.Load method. This method loads the various parts of the PDF as needed, rather than the entire file at once.
The stream passed to this method must remain open while working with the document since the document isn't loaded into memory right away. The stream is also only used for reading, thus the original file itself is not modified. To save the changes, you need to call the GcPdfDocument.Save method.
Refer to the following code sample to see a demonstration of the GcPdfDocument.Load method:
public int CreatePDF(Stream stream)
{
using var fs = File.OpenRead(Path.Combine("Resources", "PDFs", "HelloWorld.pdf"));
var doc = new GcPdfDocument();
doc.Load(fs);
// Add note to the (only) page in the doc:
var page = doc.Pages.Last;
Common.Util.AddNote(
"This text was added to the original \"Hello World\" PDF.",
page,
new RectangleF(72, 72 * 3, page.Size.Width - 72 * 2, 72));
// Done:
doc.Save(stream);
return doc.Pages.Count;
}
Limitations
When loading the PDF this way, you cannot modify the original file.