/// <summary> /// Initializes a new instance of the XPdfForm class from the specified path to an external PDF document. /// Although PDFsharp internally caches XPdfForm objects it is recommended to reuse XPdfForm objects /// in your code and change the PageNumber property if more than one page is needed form the external /// document. Furthermore, because XPdfForm can occupy very much memory, it is recommended to /// dispose XPdfForm objects if not needed anymore. /// </summary> internal XPdfForm(string path) { int pageNumber; path = ExtractPageNumber(path, out pageNumber); #if !NETFX_CORE && !PORTABLE path = Path.GetFullPath(path); if (!File.Exists(path)) { throw new FileNotFoundException(PSSR.FileNotFound(path)); } #endif if (PdfReader.TestPdfFile(path) == 0) { throw new ArgumentException("The specified file has no valid PDF file header.", "path"); } _path = path; if (pageNumber != 0) { PageNumber = pageNumber; } }
// Useful stuff here: http://stackoverflow.com/questions/350027/setting-wpf-image-source-in-code XImage(string path) { path = Path.GetFullPath(path); if (!File.Exists(path)) { throw new FileNotFoundException(PSSR.FileNotFound(path)); } //throw new FileNotFoundException(PSSR.FileNotFound(path), path); _path = path; //FileStream file = new FileStream(filename, FileMode.Open); //BitsLength = (int)file.Length; //Bits = new byte[BitsLength]; //file.Read(Bits, 0, BitsLength); //file.Close(); try { Lock.EnterGdiPlus(); _gdiImage = Image.FromFile(path); } finally { Lock.ExitGdiPlus(); } #if true_ float vres = image.VerticalResolution; float hres = image.HorizontalResolution; SizeF size = image.PhysicalDimension; int flags = image.Flags; Size sz = image.Size; GraphicsUnit units = GraphicsUnit.Millimeter; RectangleF rect = image.GetBounds(ref units); int width = image.Width; #endif Initialize(); }
// Useful stuff here: http://stackoverflow.com/questions/350027/setting-wpf-image-source-in-code XImage(string path) { #if !NETFX_CORE && !UWP path = Path.GetFullPath(path); if (!File.Exists(path)) { throw new FileNotFoundException(PSSR.FileNotFound(path)); } //throw new FileNotFoundException(PSSR.FileNotFound(path), path); #endif _path = path; //FileStream file = new FileStream(filename, FileMode.Open); //BitsLength = (int)file.Length; //Bits = new byte[BitsLength]; //file.Read(Bits, 0, BitsLength); //file.Close(); #if CORE_WITH_GDI || GDI try { Lock.EnterGdiPlus(); _gdiImage = Image.FromFile(path); } finally { Lock.ExitGdiPlus(); } #endif #if WPF && !SILVERLIGHT //BitmapSource.Create() // BUG: BitmapImage locks the file //_wpfImage = new BitmapImage(new Uri(path)); // AGHACK // Suggested change from forum to prevent locking. _wpfImage = BitmapFromUri(new Uri(path)); #endif #if WPF && SILVERLIGHT //BitmapSource.Create() // BUG: BitmapImage locks the file //_wpfImage = new BitmapImage(new Uri(path)); // AGHACK //Debug-Break.Break(); #endif #if true_ float vres = image.VerticalResolution; float hres = image.HorizontalResolution; SizeF size = image.PhysicalDimension; int flags = image.Flags; Size sz = image.Size; GraphicsUnit units = GraphicsUnit.Millimeter; RectangleF rect = image.GetBounds(ref units); int width = image.Width; #endif Initialize(); }
/// <summary> /// Initializes a new instance of the XPdfForm class from the specified path to an external PDF document. /// Although PDFsharp internally caches XPdfForm objects it is recommended to reuse XPdfForm objects /// in your code and change the PageNumber property if more than one page is needed form the external /// document. Furthermore, because XPdfForm can occupy very much memory, it is recommended to /// dispose XPdfForm objects if not needed anymore. /// </summary> internal XPdfForm(string path) { int pageNumber; path = ExtractPageNumber(path, out pageNumber); path = Path.GetFullPath(path); if (!File.Exists(path)) throw new FileNotFoundException(PSSR.FileNotFound(path), path); if (PdfReader.TestPdfFile(path) == 0) throw new ArgumentException("The specified file has no valid PDF file header.", "path"); this.path = path; if (pageNumber != 0) PageNumber = pageNumber; }
XImage(string path) { path = Path.GetFullPath(path); if (!File.Exists(path)) { throw new FileNotFoundException(PSSR.FileNotFound(path), path); } this.path = path; //FileStream file = new FileStream(filename, FileMode.Open); //BitsLength = (int)file.Length; //Bits = new byte[BitsLength]; //file.Read(Bits, 0, BitsLength); //file.Close(); #if GDI this.gdiImage = Image.FromFile(path); #endif #if WPF && !SILVERLIGHT //BitmapSource.Create() // BUG: BitmapImage locks the file this.wpfImage = new BitmapImage(new Uri(path)); // AGHACK #endif #if __IOS__ this.iosImage = UIImage.FromFile(path); #endif #if false float vres = this.image.VerticalResolution; float hres = this.image.HorizontalResolution; SizeF size = this.image.PhysicalDimension; int flags = this.image.Flags; Size sz = this.image.Size; GraphicsUnit units = GraphicsUnit.Millimeter; RectangleF rect = this.image.GetBounds(ref units); int width = this.image.Width; #endif Initialize(); }
/// <summary> /// Initializes a new instance of the XPdfForm class from the specified path to an external PDF document. /// Although PDFsharp internally caches XPdfForm objects it is recommended to reuse XPdfForm objects /// in your code and change the PageNumber property if more than one page is needed form the external /// document. Furthermore, because XPdfForm can occupy very much memory, it is recommended to /// dispose XPdfForm objects if not needed anymore. /// </summary> internal XPdfForm(string path, PdfReadAccuracy accuracy) { int pageNumber; path = ExtractPageNumber(path, out pageNumber); path = Path.GetFullPath(path); if (!File.Exists(path)) { throw new FileNotFoundException(PSSR.FileNotFound(path)); } if (PdfReader.TestPdfFile(path) == 0) { throw new ArgumentException("The specified file has no valid PDF file header.", "path"); } _path = path; _pathReadAccuracy = accuracy; if (pageNumber != 0) { PageNumber = pageNumber; } }