Exemplo n.º 1
0
        private static byte[] GetPageByDPIAsImage_LOCK(HDOCWrapper hdoc, int page, float dpi)
        {
            IntPtr HDC_HDC = SoraxDLL.GetDC(IntPtr.Zero);

            try
            {
                IntPtr hbitmap = SoraxDLL.SPD_GetPageBitmap(hdoc.HDOC, HDC_HDC, page, 0, dpi);
                Bitmap bitmap  = Image.FromHbitmap(hbitmap);
                SoraxDLL.DeleteObject(hbitmap);

                //using (FileStream fs = new FileStream(@"C:\temp\aax.png", FileMode.Create))
                //{
                //    bitmap.Save(fs, ImageFormat.Png);
                //}

                MemoryStream ms = new MemoryStream();
                bitmap.Save(ms, ImageFormat.Png);
                bitmap.Dispose();
                return(ms.ToArray());
            }
            catch (Exception ex)
            {
                throw new GenericException(ex, "Error while rasterising page {0} at {1}dpi of '{2}'", page, dpi, hdoc.filename);
            }
            finally
            {
                SoraxDLL.ReleaseDC(IntPtr.Zero, HDC_HDC);
            }
        }
Exemplo n.º 2
0
        // ------------------------------------------------------------------------------------------------------------------------

        public static int GetPageCount(string filename, string pdf_user_password, string pdf_owner_password)
        {
            using (HDOCWrapper hdoc = new HDOCWrapper(filename, pdf_user_password, pdf_owner_password))
            {
                return(SoraxDLL.SPD_GetPageCount(hdoc.HDOC));
            }
        }
Exemplo n.º 3
0
 public static byte[] GetPageByDPIAsImage(string filename, string pdf_user_password, string pdf_owner_password, int page, float dpi)
 {
     using (HDOCWrapper hdoc = new HDOCWrapper(filename, pdf_user_password, pdf_owner_password))
     {
         return(GetPageByDPIAsImage_LOCK(hdoc, page, dpi));
     }
 }
Exemplo n.º 4
0
        public static byte[] GetPageByHeightAsImage(string filename, string pdf_user_password, string pdf_owner_password, int page, double height)
        {
            float actual_dpi = 0;

            using (HDOCWrapper hdoc = new HDOCWrapper(filename, pdf_user_password, pdf_owner_password))
            {
                // We want the exact height...
                float         REFERENCE_DPI   = 600;
                SoraxDLL.Size size            = new SoraxDLL.Size();
                bool          result_get_size = SoraxDLL.SPD_GetPageSizeEx(hdoc.HDOC, page, REFERENCE_DPI, ref size);
                actual_dpi = (float)height * REFERENCE_DPI / size.Y;

                if (0 == size.Y)
                {
                    Logging.Warn("Sorax is telling us that the page is of zero height!");
                }

                return(GetPageByDPIAsImage_LOCK(hdoc, page, actual_dpi));
            }
        }