private Bitmap renPdfToBitmap(CACodecTools caTool, string pageFile, byte[] key, int pg, int dpi, float scal, int decodedPageIndex, Border border, bool isSinglePage)
        {
            System.Drawing.Color white = System.Drawing.Color.White;
            Bitmap aBitmap             = null;

            try
            {
                if (decodedPDFPages[decodedPageIndex] == null)
                {
                    decodedPDFPages[decodedPageIndex] = caTool.fileAESDecode(pageFile, key);
                }
            }
            catch (Exception ex)
            {
                decodedPDFPages[decodedPageIndex] = null;
                LogTool.Debug(ex);
            }
            try
            {
                PDFDoc pDFDoc = new PDFDoc();
                pDFDoc.Init("PVD20-M4IRG-QYZK9-MNJ2U-DFTK1-MAJ4L", "PDFX3$Henry$300604_Allnuts#");
                pDFDoc.OpenFromMemory(decodedPDFPages[decodedPageIndex], (uint)decodedPDFPages[decodedPageIndex].Length, 0);
                PXCV_Lib36.PXV_CommonRenderParameters aCommonRenderParams = prepareCommonRenderParameter(pDFDoc, dpi, pg, scal, 0, 0, border, isSinglePage);
                pDFDoc.DrawPageToDIBSection(IntPtr.Zero, pg, white, aCommonRenderParams, out aBitmap);
                pDFDoc.ReleasePageCachedData(pg, 1);
                pDFDoc.Delete();
                return(aBitmap);
            }
            catch (Exception ex2)
            {
                LogTool.Debug(ex2);
                return(aBitmap);
            }
        }
示例#2
0
        private Bitmap a(CACodecTools A_0, string A_1, byte[] A_2, int A_3, int A_4, float A_5, int A_6, Border A_7, bool A_8)
        {
            System.Drawing.Color white = System.Drawing.Color.White;
            Bitmap aBitmap             = null;

            try
            {
                if (decodedPDFPages[A_6] == null)
                {
                    decodedPDFPages[A_6] = A_0.fileAESDecode(A_1, A_2);
                }
            }
            catch (Exception ex)
            {
                decodedPDFPages[A_6] = null;
                throw ex;
            }
            try
            {
                PDFDoc pDFDoc = new PDFDoc();
                pDFDoc.Init("PVD20-M4IRG-QYZK9-MNJ2U-DFTK1-MAJ4L", "PDFX3$Henry$300604_Allnuts#");
                pDFDoc.OpenFromMemory(decodedPDFPages[A_6], (uint)decodedPDFPages[A_6].Length, 0);
                PXCV_Lib36.PXV_CommonRenderParameters aCommonRenderParams = a(pDFDoc, A_4, A_3, A_5, 0, 0, A_7, A_8);
                pDFDoc.DrawPageToDIBSection(IntPtr.Zero, A_3, white, aCommonRenderParams, out aBitmap);
                pDFDoc.ReleasePageCachedData(A_3, 1);
                pDFDoc.Delete();
                return(aBitmap);
            }
            catch (Exception ex2)
            {
                throw ex2;
            }
        }
示例#3
0
	public void DrawPageToDC(IntPtr hDC, int pn, PXCV_Lib36.PXV_CommonRenderParameters aCommonRenderParams)
	{
		if (m_bDisposed)
		{
			throw new ApplicationException("PDFDoc.DrawPage");
		}
		if (PXCV_Error.IS_DS_FAILED(PXCV_Lib36.PXCV_DrawPageToDC(m_Doc, pn, hDC, ref aCommonRenderParams)))
		{
			throw new ApplicationException("PDFDoc.DrawPageToDC.PXCV_DrawPageToDC");
		}
	}
示例#4
0
	public void DrawPageToDIBSection(IntPtr hBaseDC, int pn, Color aBkgColor, PXCV_Lib36.PXV_CommonRenderParameters aCommonRenderParams, out Bitmap aBitmap)
	{
		aBitmap = null;
		if (m_bDisposed)
		{
			throw new ApplicationException("PDFDoc.DrawPageToDIBSection");
		}
		IntPtr hBitmap = IntPtr.Zero;
		int backcolor = aBkgColor.ToArgb();
		if (PXCV_Error.IS_DS_FAILED(PXCV_Lib36.PXCV_DrawPageToDIBSection(m_Doc, pn, ref aCommonRenderParams, hBaseDC, backcolor, ref hBitmap, IntPtr.Zero, 0)))
		{
			throw new ApplicationException("PDFDoc.DrawPageToDIBSection.PXCV_DrawPageToDIBSection");
		}
		aBitmap = Image.FromHbitmap(hBitmap);
		DeleteObject(hBitmap);
	}
示例#5
0
        //將 PDF ren 成 Bitmap (改用Thread的方式ren)
        private Bitmap renPdfToBitmap(string pageFile, byte[] key, int pg, int dpi, float scal, int decodedPageIndex, Border border, bool isSinglePage)
        {
            //Mutex mLoad = new Mutex(requestInitialOwnership, "LoadMutex", out loadMutexWasCreated);
            //if (!(requestInitialOwnership & loadMutexWasCreated))
            //{
            //    mLoad.WaitOne();
            //}

            System.Drawing.Color bgColor = System.Drawing.Color.White; //背景白色
            Bitmap bmp = null;

            if (decodedPDFPages[decodedPageIndex] == null) //如果此頁已經解密過,就直接拿來ren,不用再重新解密一次
            {
                try
                {
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        FileStream sourceStream = new FileStream(pageFile, FileMode.Open);
                        sourceStream.CopyTo(memoryStream);
                        decodedPDFPages[decodedPageIndex] = memoryStream.ToArray();
                    }
                }
                catch
                {
                    return(bmp);
                }
            }

            try
            {   //TODO: 改成把PDF實體拉出來變global的
                PDFDoc pdfDoc = new PDFDoc();
                pdfDoc.Init("PVD20-M4IRG-QYZK9-MNJ2U-DFTK1-MAJ4L", "PDFX3$Henry$300604_Allnuts#");
                pdfDoc.OpenFromMemory(decodedPDFPages[decodedPageIndex], (uint)decodedPDFPages[decodedPageIndex].Length, 0);
                PXCV_Lib36.PXV_CommonRenderParameters commonRenderParam = prepareCommonRenderParameter(pdfDoc, dpi, pg, scal, 0, 0, border, isSinglePage);
                pdfDoc.DrawPageToDIBSection(IntPtr.Zero, pg, bgColor, commonRenderParam, out bmp);
                pdfDoc.ReleasePageCachedData(pg, (int)PXCV_Lib36.PXCV_ReleaseCachedDataFlags.pxvrcd_ReleaseDocumentImages);
                pdfDoc.Delete();
            }
            catch (Exception e)
            {
                //throw e;
                LogTool.Debug(e);
            }
            //bmp.Save("c:\\Temp\\test.bmp");
            return(bmp);
        }
示例#6
0
        //將 PDF ren 成 Bitmap (改用Thread的方式ren)
        private Bitmap renPdfToBitmap(CACodecTools caTool, string pageFile, byte[] key, int pg, int dpi, float scal, int decodedPageIndex, Border border, bool isSinglePage)
        {
            System.Drawing.Color bgColor = System.Drawing.Color.White; //背景白色
            Bitmap bmp = null;

            try
            {
                if (this.decodedPDFPages[decodedPageIndex] == null) //如果此頁已經解密過,就直接拿來ren,不用再重新解密一次
                {
                    this.decodedPDFPages[decodedPageIndex] = caTool.fileAESDecode(pageFile, key);
                }
            }
            catch (Exception e)
            {
                //TODO: 萬一檔案解析失敗, 判定為壞檔, 重新下載
                this.decodedPDFPages[decodedPageIndex] = null;
                LogTool.Debug(e);
                //throw e;
            }

            try
            {   //TODO: 改成把PDF實體拉出來變global的
                PDFDoc pdfDoc = new PDFDoc();
                pdfDoc.Init("PVD20-M4IRG-QYZK9-MNJ2U-DFTK1-MAJ4L", "PDFX3$Henry$300604_Allnuts#");
                pdfDoc.OpenFromMemory(this.decodedPDFPages[decodedPageIndex], (uint)decodedPDFPages[decodedPageIndex].Length, 0);
                PXCV_Lib36.PXV_CommonRenderParameters commonRenderParam = prepareCommonRenderParameter(pdfDoc, dpi, pg, scal, 0, 0, border, isSinglePage);
                pdfDoc.DrawPageToDIBSection(IntPtr.Zero, pg, bgColor, commonRenderParam, out bmp);
                pdfDoc.ReleasePageCachedData(pg, (int)PXCV_Lib36.PXCV_ReleaseCachedDataFlags.pxvrcd_ReleaseDocumentImages);
                pdfDoc.Delete();
            }
            catch (Exception e)
            {
                LogTool.Debug(e);
                //throw e;
            }
            //bmp.Save("c:\\Temp\\test.bmp");
            return(bmp);
        }
        private Bitmap renPdfToBitmap(string pageFile, byte[] key, int pg, int dpi, float scal, int decodedPageIndex, Border border, bool isSinglePage)
        {
            System.Drawing.Color white = System.Drawing.Color.White;
            Bitmap aBitmap             = null;

            if (decodedPDFPages[decodedPageIndex] == null)
            {
                try
                {
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        FileStream fileStream = new FileStream(pageFile, FileMode.Open);
                        fileStream.CopyTo(memoryStream);
                        decodedPDFPages[decodedPageIndex] = memoryStream.ToArray();
                    }
                }
                catch
                {
                    return(aBitmap);
                }
            }
            try
            {
                PDFDoc pDFDoc = new PDFDoc();
                pDFDoc.Init("PVD20-M4IRG-QYZK9-MNJ2U-DFTK1-MAJ4L", "PDFX3$Henry$300604_Allnuts#");
                pDFDoc.OpenFromMemory(decodedPDFPages[decodedPageIndex], (uint)decodedPDFPages[decodedPageIndex].Length, 0);
                PXCV_Lib36.PXV_CommonRenderParameters aCommonRenderParams = prepareCommonRenderParameter(pDFDoc, dpi, pg, scal, 0, 0, border, isSinglePage);
                pDFDoc.DrawPageToDIBSection(IntPtr.Zero, pg, white, aCommonRenderParams, out aBitmap);
                pDFDoc.ReleasePageCachedData(pg, 1);
                pDFDoc.Delete();
                return(aBitmap);
            }
            catch (Exception ex)
            {
                LogTool.Debug(ex);
                return(aBitmap);
            }
        }
示例#8
0
        //產生 PDF 元產所需的參數 (改用Thread的方式ren)
        private PXCV_Lib36.PXV_CommonRenderParameters prepareCommonRenderParameter(PDFDoc pdfDoc, int dpi, int pageNumber, float zoom, int offsetX, int offsetY, Border border, bool isSinglePage)
        {
            IntPtr p1 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PXCV_Helper.RECT)));
            IntPtr p2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PXCV_Helper.RECT)));

            System.Drawing.Point m_Offset   = new System.Drawing.Point(offsetX, offsetY);
            System.Drawing.Size  aPageSize  = System.Drawing.Size.Empty;
            PXCV_Helper.RECT     aWholePage = new PXCV_Helper.RECT();
            PXCV_Helper.RECT     aDrawRect  = new PXCV_Helper.RECT();
            PXCV_Lib36.PXV_CommonRenderParameters commonRenderParam = new PXCV_Lib36.PXV_CommonRenderParameters();
            PageDimension aPageDim;

            pdfDoc.GetPageDimensions(pageNumber, out aPageDim.w, out aPageDim.h);

            //Border bd = border; //可視範圍
            double borderHeight = (border.ActualHeight / (double)96) * dpi;
            double borderWidth  = (border.ActualWidth / (double)96) * dpi;

            if (zoomStep == 0)
            {
                //PDF原尺吋
                aPageSize.Width  = (int)((aPageDim.w / 72.0 * dpi) * zoom);
                aPageSize.Height = (int)((aPageDim.h / 72.0 * dpi) * zoom);

                double borderRatio      = borderWidth / borderHeight;
                double renderImageRatio = 0;

                if (isSinglePage)
                {
                    renderImageRatio = (double)aPageSize.Width / (double)aPageSize.Height;
                }
                else
                {
                    renderImageRatio = (double)(aPageSize.Width * 2) / (double)aPageSize.Height;
                }

                if (aPageSize.Width < borderWidth && aPageSize.Height < borderHeight)
                {   //PDF原尺吋就比canvas還小 --> 貼齊canvas
                    double newPageW, newPageH;
                    if (renderImageRatio > borderRatio)
                    {   //寬先頂到
                        newPageW  = borderWidth / 2;
                        baseScale = newPageW / (double)aPageSize.Width;
                        newPageH  = Math.Round(baseScale * (double)aPageSize.Height, 2);
                    }
                    else
                    {   //高先頂到
                        newPageH  = borderHeight;
                        baseScale = newPageH / (double)aPageSize.Height;
                        newPageW  = Math.Round(baseScale * (double)aPageSize.Width, 2);
                    }

                    aPageSize.Width  = (int)newPageW;
                    aPageSize.Height = (int)newPageH;
                }
                else
                {   //PDF有一邊比canvas還大
                    double newPageW, newPageH;
                    if (renderImageRatio > borderRatio)
                    {   //寬先頂到
                        newPageW  = borderWidth / 2;
                        baseScale = newPageW / (double)aPageSize.Width;
                        newPageH  = Math.Round(baseScale * (double)aPageSize.Height, 2);
                    }
                    else
                    {   //高先頂到
                        newPageH  = borderHeight;
                        baseScale = newPageH / (double)aPageSize.Height;
                        newPageW  = Math.Round(baseScale * (double)aPageSize.Width, 2);
                    }

                    aPageSize.Width  = (int)newPageW;
                    aPageSize.Height = (int)newPageH;
                }
            }
            else
            {
                //PDF原尺吋
                aPageSize.Width  = (int)((aPageDim.w / 72.0 * dpi) * zoom * baseScale);
                aPageSize.Height = (int)((aPageDim.h / 72.0 * dpi) * zoom * baseScale);
            }

            //Region rgn1 = new Region(new System.Drawing.Rectangle(-m_Offset.X, -m_Offset.Y, aPageSize.Width, aPageSize.Height));
            //rgn1.Complement(new System.Drawing.Rectangle(0, 0, (int)borderWidth, (int)borderHeight));
            //rgn1.Complement(new System.Drawing.Rectangle(0, 0, aPageSize.Width, aPageSize.Height));
            aWholePage.left   = -m_Offset.X;
            aWholePage.top    = -m_Offset.Y;
            aWholePage.right  = aWholePage.left + aPageSize.Width;
            aWholePage.bottom = aWholePage.top + aPageSize.Height;

            //計算要ren的範圍
            //TODO: 改成部分ren,目前是全ren
            aDrawRect.left = 0;
            aDrawRect.top  = 0;
            if (zoomStep == 0)
            {
                if (aPageSize.Width < borderWidth)
                {
                    aDrawRect.right = aPageSize.Width;
                }
                else
                {
                    aDrawRect.right = (int)borderWidth;
                }
                if (aPageSize.Height < borderHeight)
                {
                    aDrawRect.bottom = aPageSize.Height;
                }
                else
                {
                    aDrawRect.bottom = (int)borderHeight;
                }
            }
            else
            {
                aDrawRect.right  = aPageSize.Width;
                aDrawRect.bottom = aPageSize.Height;
            }

            //aDrawRect.right = aPageSize.Width;
            //aDrawRect.bottom = aPageSize.Height;
            Marshal.StructureToPtr(aWholePage, p1, false);
            Marshal.StructureToPtr(aDrawRect, p2, false);
            commonRenderParam.WholePageRect = p1;
            commonRenderParam.DrawRect      = p2;
            commonRenderParam.RenderTarget  = PXCV_Lib36.PXCV_RenderMode.pxvrm_Viewing;
            commonRenderParam.Flags         = 0;
            //System.Drawing.Rectangle rc = new System.Drawing.Rectangle(0, 0, aControlSize.Width, aControlSize.Height);
            //System.Drawing.Rectangle rc = new System.Drawing.Rectangle(0, 0, aPageSize.Width, aPageSize.Height);
            //rc.Intersect(new System.Drawing.Rectangle(-m_Offset.X, -m_Offset.Y, aPageSize.Width, aPageSize.Height));
            //e.DrawRectangle(System.Windows.Media.Brushes.White, null, new Rect(new System.Windows.Size(rc.Width, rc.Height)));
            //aGraphics.FillRectangle(System.Drawing.Brushes.White, rc);
            //aGraphics.FillRegion(System.Drawing.Brushes.Gray, rgn1);
            //rgn1.Dispose();



            return(commonRenderParam);
        }
        private PXCV_Lib36.PXV_CommonRenderParameters prepareCommonRenderParameter(PDFDoc pdfDoc, int dpi, int pageNumber, float zoom, int offsetX, int offsetY, Border border, bool isSinglePage)
        {
            IntPtr intPtr  = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PXCV_Helper.RECT)));
            IntPtr intPtr2 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PXCV_Helper.RECT)));
            Point  point   = new Point(offsetX, offsetY);
            Size   empty   = Size.Empty;

            PXCV_Helper.RECT rECT  = default(PXCV_Helper.RECT);
            PXCV_Helper.RECT rECT2 = default(PXCV_Helper.RECT);
            PXCV_Lib36.PXV_CommonRenderParameters result = default(PXCV_Lib36.PXV_CommonRenderParameters);
            PageDimension pageDimension = default(PageDimension);

            pdfDoc.GetPageDimensions(pageNumber, out pageDimension.w, out pageDimension.h);
            double num  = border.ActualHeight / 96.0 * (double)dpi;
            double num2 = border.ActualWidth / 96.0 * (double)dpi;

            if (zoomStep == 0)
            {
                empty.Width  = (int)(pageDimension.w / 72.0 * (double)dpi * (double)zoom);
                empty.Height = (int)(pageDimension.h / 72.0 * (double)dpi * (double)zoom);
                double num3 = num2 / num;
                double num4 = 0.0;
                num4 = ((!isSinglePage) ? ((double)(empty.Width * 2) / (double)empty.Height) : ((double)empty.Width / (double)empty.Height));
                if ((double)empty.Width < num2 && (double)empty.Height < num)
                {
                    double num5;
                    double num6;
                    if (num4 > num3)
                    {
                        num5      = num2 / 2.0;
                        baseScale = num5 / (double)empty.Width;
                        num6      = Math.Round(baseScale * (double)empty.Height, 2);
                    }
                    else
                    {
                        num6      = num;
                        baseScale = num6 / (double)empty.Height;
                        num5      = Math.Round(baseScale * (double)empty.Width, 2);
                    }
                    empty.Width  = (int)num5;
                    empty.Height = (int)num6;
                }
                else
                {
                    double num7;
                    double num8;
                    if (num4 > num3)
                    {
                        num7      = num2 / 2.0;
                        baseScale = num7 / (double)empty.Width;
                        num8      = Math.Round(baseScale * (double)empty.Height, 2);
                    }
                    else
                    {
                        num8      = num;
                        baseScale = num8 / (double)empty.Height;
                        num7      = Math.Round(baseScale * (double)empty.Width, 2);
                    }
                    empty.Width  = (int)num7;
                    empty.Height = (int)num8;
                }
            }
            else
            {
                empty.Width  = (int)(pageDimension.w / 72.0 * (double)dpi * (double)zoom * baseScale);
                empty.Height = (int)(pageDimension.h / 72.0 * (double)dpi * (double)zoom * baseScale);
            }
            rECT.left   = -point.X;
            rECT.top    = -point.Y;
            rECT.right  = rECT.left + empty.Width;
            rECT.bottom = rECT.top + empty.Height;
            rECT2.left  = 0;
            rECT2.top   = 0;
            if (zoomStep == 0)
            {
                if ((double)empty.Width < num2)
                {
                    rECT2.right = empty.Width;
                }
                else
                {
                    rECT2.right = (int)num2;
                }
                if ((double)empty.Height < num)
                {
                    rECT2.bottom = empty.Height;
                }
                else
                {
                    rECT2.bottom = (int)num;
                }
            }
            else
            {
                rECT2.right  = empty.Width;
                rECT2.bottom = empty.Height;
            }
            Marshal.StructureToPtr((object)rECT, intPtr, false);
            Marshal.StructureToPtr((object)rECT2, intPtr2, false);
            result.WholePageRect = intPtr;
            result.DrawRect      = intPtr2;
            result.RenderTarget  = PXCV_Lib36.PXCV_RenderMode.pxvrm_Viewing;
            result.Flags         = 0;
            return(result);
        }