} // func OpenPage /// <summary>Get size of this page.</summary> /// <param name="pageNumber">Page number, zero indexed.</param> /// <returns>Size of the page in page units.</returns> public Size GetPageSize(int pageNumber) { CheckPageNumber(pageNumber); lock (FPDF_LibraryLock) { if (FPDF_GetPageSizeByIndex(documentHandle.DangerousGetHandle(), pageNumber, out var width, out var height) == 0) { throw PdfReaderException.Create(pdfName); } return(new Size(width, height)); } } // func GetPageSize
} // proc SetPrintTextWithGDI #region -- Open --------------------------------------------------------------- /// <summary>Open a pdf-file</summary> /// <param name="fileName">Filename</param> /// <param name="password">Password of the pdf</param> /// <returns>Pdf document reader</returns> public static PdfReader Open(string fileName, SecureString password = null) { if (String.IsNullOrEmpty(fileName)) { throw new ArgumentNullException(nameof(fileName)); } lock (FPDF_LibraryLock) { var documentHandle = new PdfDocumentHandle(FPDF_LoadDocument(fileName, IntPtr.Zero)); if (documentHandle.IsInvalid) { throw PdfReaderException.Create(fileName); } return(new PdfReader(documentHandle, fileName, null)); } } // func Open
private PdfReader(PdfDocumentHandle documentHandle, string pdfName, IDisposable dispose) { this.documentHandle = documentHandle ?? throw new ArgumentNullException(nameof(documentHandle)); this.pdfName = pdfName ?? "unknown.pdf"; this.dispose = dispose; Properties = new PdfProperties(this); // read pdf version if (!FPDF_GetFileVersion(documentHandle.DangerousGetHandle(), out var tmp)) { throw PdfReaderException.Create(pdfName); } pdfVersion = new Version(tmp / 10, tmp % 10); // read page count pageCount = FPDF_GetPageCount(documentHandle.DangerousGetHandle()); if (pageCount < 0) { throw PdfReaderException.Create(pdfName); } } // ctor