public static int CountPages(IPDFSource source, string password = null) { using (PDFFileStream stream = new PDFFileStream(source)) { ValidatePassword(stream.Document, password); return(MuPDFNativeApi.Native.CountPages(stream.Document)); } }
public void Load(IPDFSource source, string password = null) { virtualPanel = this.FindChild <CustomVirtualizingPanel>(); scrollViewer = this.FindChild <ScrollViewer>(); virtualPanel.PageBounds = parent.PageBounds.Select(b => b.SizeIncludingOffset).ToArray(); imageProvider = new PDFImageProvider(source, parent.PageCount, new DisplaySettings(parent.GetPagePer(), parent.ViewType, parent.HMargin, parent.PageRotation), password: password); if (parent.Zoom == ZoomType.FIXED) { CreateNewItemsSource(); } else if (parent.Zoom == ZoomType.FIT_HEIGHT) { ZoomToHeight(); } else if (parent.Zoom == ZoomType.FIT_WIDTH) { ZoomToWidth(); } if (scrollViewer != null) { scrollViewer.Visibility = System.Windows.Visibility.Visible; scrollViewer.ScrollToTop(); } }
public PDFImageProvider(IPDFSource source, int total, DisplaySettings settings, bool preFetch = true, string password = null) { this.source = source; this.total = total; this.Settings = settings; this.preFetch = preFetch; this.password = password; }
public void Open(IPDFSource source, string password = null) { LoadPdf(source, password); if (PDFLoaded != null) { PDFLoaded(this, EventArgs.Empty); } }
public static Bitmap ExtractPage(IPDFSource source, int pageNumber, float zoomFactor = 1.0f, string password = null) { int pageNumberIndex = Math.Max(0, pageNumber - 1); using (PDFFileStream stream = new PDFFileStream(source)) { ValidatePassword(stream.Document, password); IntPtr ptr = IntPtr.Zero; try { ptr = MuPDFNativeApi.Native.LoadPage(stream.Document, pageNumberIndex); return(RenderPage(stream.Context, stream.Document, ptr, zoomFactor)); } finally { if (ptr != IntPtr.Zero) { MuPDFNativeApi.Native.FreePage(stream.Document, ptr); } } } }
public PDFFileStream(IPDFSource source) { if (source is FileSource) { FileSource fileSource = (FileSource)source; Context = MuPDFNativeApi.Native.NewContext(IntPtr.Zero, IntPtr.Zero, FZ_STORE_DEFAULT); Stream = MuPDFNativeApi.Native.OpenFile(Context, fileSource.Filename); Document = MuPDFNativeApi.Native.OpenDocumentStream(Context, PDF_EXTENSION, Stream); } else if (source is ByteSource) { ByteSource byteSource = (ByteSource)source; Context = MuPDFNativeApi.Native.NewContext(IntPtr.Zero, IntPtr.Zero, FZ_STORE_DEFAULT); GCHandle pinnedArray = GCHandle.Alloc(byteSource.Data, GCHandleType.Pinned); IntPtr ptr = pinnedArray.AddrOfPinnedObject(); Stream = MuPDFNativeApi.Native.OpenStream(Context, ptr, byteSource.Data.Length); Document = MuPDFNativeApi.Native.OpenDocumentStream(Context, PDF_EXTENSION, Stream); pinnedArray.Free(); } }
public static System.Windows.Size[] GetPageBounds(IPDFSource source, ImageRotation rotation = ImageRotation.NONE, string password = null) { using (PDFFileStream stream = new PDFFileStream(source)) { ValidatePassword(stream.Document, password); int pageSize = MuPDFNativeApi.Native.CountPages(stream.Document); return(Enumerable.Range(0, pageSize - 1) .Select(x => { IntPtr ptr = IntPtr.Zero; try { ptr = MuPDFNativeApi.Native.LoadPage(stream.Document, x); MuPDFLibrary.Interop.Rectangle bound = MuPDFNativeApi.Native.BoundPage(stream.Document, ptr); return SizeCallback(rotation)(bound.Width, bound.Height); } finally { if (ptr != IntPtr.Zero) { MuPDFNativeApi.Native.FreePage(stream.Document, ptr); } } }).ToArray()); } }
private void LoadPdf(IPDFSource source, string password = null) { pageBounds = CalcPageBounds(MuPDF.GetPageBounds(source, PageRotation), ViewType); PageCount = pageBounds.Length; pdf.Load(source); }
public static bool NeedsPassword(IPDFSource source) { using (PDFFileStream stream = new PDFFileStream(source)) { return(NeedsPassword(stream.Document)); } }