Example #1
0
 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));
     }
 }
Example #2
0
        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);
                    }
                }
            }
        }
Example #3
0
 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());
     }
 }
Example #4
0
 public static bool NeedsPassword(IPDFSource source)
 {
     using (PDFFileStream stream = new PDFFileStream(source)) {
         return(NeedsPassword(stream.Document));
     }
 }