“
10 Common Tasks with Spire.PDFViewer and How to Implement Them
Spire.PDFViewer is a .NET control for loading, viewing, printing and exporting PDF documents. Below are 10 common tasks developers perform with Spire.PDFViewer, each with a short explanation and a concise C# example you can drop into a Windows Forms app using the PdfDocumentViewer control (references: Spire.PdfViewer.Forms.dll and Spire.Pdf.dll).
1. Load a PDF (file, stream, byte[])
- Purpose: Open PDF from disk, memory stream, or byte array.
- Key method: LoadFromFile, LoadFromStream, LoadFromBytes
- Example (file):
csharp
pdfDocumentViewer1.LoadFromFile(@“C:\\Docs\\sample.pdf”);
- Example (stream):
csharp
using (var fs = File.OpenRead(@“C:\\Docs\\sample.pdf”)) pdfDocumentViewer1.LoadFromStream(fs);
- Example (bytes):
csharp
byte[] data = File.ReadAllBytes(“sample.pdf”); pdfDocumentViewer1.LoadFromBytes(data);
2. Navigate pages (next, previous, go to page)
- Purpose: Programmatic paging and reading current page number.
- API: CurrentPageNumber, PageCount, GoToPage “`csharp // Next page if (pdfDocumentViewer1.CurrentPageNumber < pdfDocumentViewer1.PageCount) pdfDocumentViewer1.GoToPage(pdfDocumentViewer1.CurrentPageNumber + 1);
// Previous page if (pdfDocumentViewer1.CurrentPageNumber > 1) pdfDocumentViewer1.GoToPage(pdfDocumentViewer1.CurrentPageNumber – 1);
// Go to specific page pdfDocument
“
Leave a Reply