Ejemplo n.º 1
0
        private void Rotate(PdfRotation rotate)
        {
            int page = pdfViewer1.Renderer.Page;

            pdfViewer1.Document.RotatePage(page, rotate);
            pdfViewer1.Renderer.ReloadDocument();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Opens a document using a .NET Stream. Allows opening huge
        /// PDFs without loading them into memory first.
        /// </summary>
        /// <param name="input">The input Stream. Don't dispose prior to closing the pdf.</param>
        /// <param name="password">Password, if the PDF is protected. Can be null.</param>
        /// <param name="streamPtr">Retrieves an IntPtr to the COM object for the Stream. The caller must release this with Marshal.Release prior to Disposing the Stream.</param>
        /// <returns>An IntPtr to the FPDF_DOCUMENT object.</returns>
        //public IntPtr FPDF_LoadCustomDocument(Stream input, string password, int id)
        //{
        //    var getBlock = Marshal.GetFunctionPointerForDelegate(_getBlockDelegate);

        //    var access = new FPDF_FILEACCESS
        //    {
        //        m_FileLen = (uint)input.Length,
        //        m_GetBlock = getBlock,
        //        m_Param = (IntPtr)id
        //    };

        //    lock (_Lock)
        //    {
        //        return this.FPDF_LoadCustomDocument(access, password);
        //    }
        //}

        //public FPDF_ERR FPDF_GetLastError()
        //{
        //    lock (_Lock)
        //    {
        //        return (FPDF_ERR)this.FPDF_GetLastError();
        //    }
        //}

        public void FPDFPage_SetRotation(IntPtr page, PdfRotation rotation)
        {
            lock (_Lock)
            {
                this.FPDFPage_SetRotation(page, rotation);
            }
        }
Ejemplo n.º 3
0
 public static void FPDFPage_SetRotation(IntPtr page, PdfRotation rotation)
 {
     lock (LockString)
     {
         Imports.FPDFPage_SetRotation(page, (int)rotation);
     }
 }
Ejemplo n.º 4
0
 public void RotatePage(int pageNumber, PdfRotation rotation)
 {
     using (var pageData = new PageData(_document, _form, pageNumber))
     {
         NativeMethods.FPDFPage_SetRotation(pageData.Page, rotation);
     }
 }
Ejemplo n.º 5
0
        public void Rotate(PdfRotation rotation)
        {
            _rotation = rotation;

            if (pdfViewer.Document != null)
            {
                pdfViewer.Renderer.Rotation = _rotation;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Renders a page of the PDF document to an image.
        /// </summary>
        /// <param name="page">Number of the page to render.</param>
        /// <param name="width">Width of the rendered image.</param>
        /// <param name="height">Height of the rendered image.</param>
        /// <param name="dpiX">Horizontal DPI.</param>
        /// <param name="dpiY">Vertical DPI.</param>
        /// <param name="rotate">Rotation.</param>
        /// <param name="flags">Flags used to influence the rendering.</param>
        /// <param name="drawFormFields">Draw form fields.</param>
        /// <returns>The rendered image.</returns>
        public Image Render(int page, int width, int height, float dpiX, float dpiY, PdfRotation rotate, PdfRenderFlags flags, bool drawFormFields)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            if ((flags & PdfRenderFlags.CorrectFromDpi) != 0)
            {
                width  = width * (int)dpiX / 72;
                height = height * (int)dpiY / 72;
            }

            var bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            bitmap.SetResolution(dpiX, dpiY);

            var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, bitmap.PixelFormat);

            try
            {
                var handle = NativeMethods.FPDFBitmap_CreateEx(width, height, 4, data.Scan0, width * 4);

                try
                {
                    uint background = (flags & PdfRenderFlags.Transparent) == 0 ? 0xFFFFFFFF : 0x00FFFFFF;

                    NativeMethods.FPDFBitmap_FillRect(handle, 0, 0, width, height, background);

                    bool success = _file.RenderPDFPageToBitmap(
                        page,
                        handle,
                        (int)dpiX, (int)dpiY,
                        0, 0, width, height,
                        (int)rotate,
                        FlagsToFPDFFlags(flags),
                        //(flags & PdfRenderFlags.Annotations) != 0
                        drawFormFields
                        );

                    if (!success)
                    {
                        throw new Win32Exception();
                    }
                }
                finally
                {
                    NativeMethods.FPDFBitmap_Destroy(handle);
                }
            }
            finally
            {
                bitmap.UnlockBits(data);
            }

            return(bitmap);
        }
Ejemplo n.º 7
0
        private void ButtonRotateLeft_Click(object sender, EventArgs e)
        {
            rotation--;
            if (rotation < PdfRotation.Rotate0)
            {
                rotation = PdfRotation.Rotate270;
            }

            pdfPanel1.Rotate(rotation);
            pdfPanel2.Rotate(rotation);
        }
Ejemplo n.º 8
0
        private void ButtonRotateRight_Click(object sender, EventArgs e)
        {
            rotation++;
            if (rotation > PdfRotation.Rotate270)
            {
                rotation = PdfRotation.Rotate0;
            }

            pdfPanel1.Rotate(rotation);
            pdfPanel2.Rotate(rotation);
        }
Ejemplo n.º 9
0
        private void Rotate(PdfRotation rotate)
        {
            // PdfRenderer does not support changes to the loaded document,
            // so we fake it by reloading the document into the renderer.

            int page = pdfViewer1.Renderer.Page;
            var document = pdfViewer1.Document;
            pdfViewer1.Document = null;
            document.RotatePage(page, rotate);
            pdfViewer1.Document = document;
            pdfViewer1.Renderer.Page = page;
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Renders the page.
 /// </summary>
 /// <param name="width">
 /// The full width of the rendered image in px.
 /// If 0, width will be calculated from height using the correct apsect ratio.
 /// Height and width can not be both set to zero.
 /// </param>
 /// <param name="height">
 /// The full wiheightth of the rendered image in px .
 /// If 0, height will be calculated from height using the correct apsect ratio.
 /// Height and width can not be both set to zero.
 /// </param>
 /// <param name="rotate">Specify rotation.</param>
 /// <param name="flags">Specify flags.</param>
 /// <returns>Image from the page.</returns>
 public Image Render(int width, int height, PdfRotation rotate, PdfRenderFlags flags)
 {
     if (height == 0 && width != 0)
     {
         height = (int)((float)width * (Height / Width));
     }
     else if (height != 0 && width == 0)
     {
         width = (int)((float)height * (int)(Width / Height));
     }
     else if (height == 0 && width == 0)
     {
         throw new ArgumentException();
     }
     return(Render(width, height, 0, 0, width, height, 0, 0, rotate, flags));
 }
Ejemplo n.º 11
0
        public FormMain()
        {
            InitializeComponent();
            comboBoxDiffType.SelectedIndex = 0;
            radioButtonText.Checked        = true;

            pdfPanel1.toolStripButtonNextPage.ToolTipText = "Next Page / Ctrl + RIGHT_ARROW";
            pdfPanel1.toolStripButtonPrevPage.ToolTipText = "Prev Page / Ctrl + LEFT_ARROW";
            pdfPanel2.toolStripButtonNextPage.ToolTipText = "Next Page / Alt + RIGHT_ARROW";
            pdfPanel2.toolStripButtonPrevPage.ToolTipText = "Prev Page / Alt + LEFT_ARROW";

            zoom     = 1.0;
            zoomIn   = false;
            zoomOut  = false;
            rotation = PdfRotation.Rotate0;
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Rotate the PDF document left.
 /// </summary>
 public void RotateLeft()
 {
     Rotation = (PdfRotation)(((int)Rotation + 3) % 4);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Rotate the PDF document right.
 /// </summary>
 public void RotateRight()
 {
     Rotation = (PdfRotation)(((int)Rotation + 1) % 4);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Rotate the PDF document left.
 /// </summary>
 public void RotateLeft()
 {
     Rotation = (PdfRotation)(((int)Rotation + 3) % 4);
 }
Ejemplo n.º 15
0
 public void RotatePage(int pageNumber, PdfRotation rotation)
 {
     _document.RotatePage(TranslatePage(pageNumber), rotation);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Rotate the page.
 /// </summary>
 /// <param name="page">The page to rotate.</param>
 /// <param name="rotation">How to rotate the page.</param>
 public void RotatePage(int page, PdfRotation rotation)
 {
     _file.RotatePage(page, rotation);
     _pageSizes[page] = _file.GetPDFDocInfo(page);
     PageSizes        = new ReadOnlyCollection <SizeF>(_pageSizes);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Rotates the page.
 /// </summary>
 /// <param name="rotation">Specify the rotation.</param>
 public void RotatePage(PdfRotation rotation) => NativeMethods.FPDFPage_SetRotation(Page, rotation);
Ejemplo n.º 18
0
 /// <summary>
 /// Renders the page.
 /// </summary>
 /// <param name="width">
 /// The full width of the rendered image in px.
 /// If 0, width will be calculated from height using the correct apsect ratio.
 /// Height and width can not be both set to zero.
 /// </param>
 /// <param name="height">
 /// The full wiheightth of the rendered image in px.
 /// If 0, height will be calculated from height using the correct apsect ratio.
 /// Height and width can not be both set to zero.
 /// </param>
 /// <param name="clipX">X value of the start point of the clipping area</param>
 /// <param name="clipY">Y value of the start point of the clipping area</param>
 /// <param name="clipWidth">Width of the clip area</param>
 /// <param name="clipHeight">Height of the clip area</param>
 /// <param name="rotate">Specify rotation.</param>
 /// <param name="flags">Specify flags.</param>
 /// <returns>Image from the page.</returns>
 public Image Render(int width, int height, int clipX, int clipY, int clipWidth, int clipHeight, PdfRotation rotate, PdfRenderFlags flags)
 {
     return(Render(width, height, clipX, clipY, clipWidth, clipHeight, 0, 0, rotate, flags));
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Renders the page.
 /// </summary>
 /// <param name="width">
 /// The full width of the rendered image in px or percentage (if dpiX and dpiY are specified).
 /// If 0, width will be calculated from height using the correct apsect ratio.
 /// Height and width can not be both set to zero.
 /// </param>
 /// <param name="height">
 /// The full wiheightth of the rendered image in px or percentage (if dpiX and dpiY are specified).
 /// If 0, height will be calculated from height using the correct apsect ratio.
 /// Height and width can not be both set to zero.
 /// </param>
 /// <param name="dpiX">DPI to render page. If set, width and height will accept percentage.</param>
 /// <param name="dpiY">DPI to render page. If set, width and height will accept percentage.</param>
 /// <param name="rotate">Specify rotation.</param>
 /// <param name="flags">Specify flags.</param>
 /// <returns>Image from the page.</returns>
 public Image Render(int width, int height, float dpiX, float dpiY, PdfRotation rotate, PdfRenderFlags flags)
 {
     return(Render(width, height, 0, 0, width, height, dpiX, dpiY, rotate, flags));
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Renders the page.
        /// </summary>
        /// <param name="width">
        /// The full width of the rendered image in px or percentage (if dpiX and dpiY are specified).
        /// If 0, width will be calculated from height using the correct apsect ratio.
        /// Height and width can not be both set to zero.
        /// </param>
        /// <param name="height">
        /// The full wiheightth of the rendered image in px or percentage (if dpiX and dpiY are specified).
        /// If 0, height will be calculated from height using the correct apsect ratio.
        /// Height and width can not be both set to zero.
        /// </param>
        /// <param name="clipX">X value of the start point of the clipping area</param>
        /// <param name="clipY">Y value of the start point of the clipping area</param>
        /// <param name="clipWidth">Width of the clip area</param>
        /// <param name="clipHeight">Height of the clip area</param>
        /// <param name="dpiX">DPI to render page. If set, width and height will accept percentage.</param>
        /// <param name="dpiY">DPI to render page. If set, width and height will accept percentage.</param>
        /// <param name="rotate">Specify rotation.</param>
        /// <param name="flags">Specify flags.</param>
        /// <returns>Image from the page.</returns>
        public Image Render(int width, int height, int clipX, int clipY, int clipWidth, int clipHeight, float dpiX, float dpiY, PdfRotation rotate, PdfRenderFlags flags)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(PdfPage));
            }

            if (height == 0 && width != 0)
            {
                height = width * (int)(Height / Width);
            }
            else if (height != 0 && width == 0)
            {
                width = height * (int)(Width / Height);
            }
            else if (height == 0 && width == 0)
            {
                throw new ArgumentException();
            }

            if (dpiX != 0 && dpiY != 0)
            {
                clipWidth  = (int)(clipWidth / 100f * width / 100f * Width * 0.013888888888889 * dpiX);
                clipHeight = (int)(clipHeight / 100f * height / 100f * Height * 0.013888888888889 * dpiY);
                width      = (int)(width / 100f * Width * 0.013888888888889 * dpiX);
                height     = (int)(height / 100f * Height * 0.013888888888889 * dpiY);
            }

            var bitmap = new Bitmap(clipWidth, clipHeight, PixelFormat.Format32bppArgb);

            var data = bitmap.LockBits(new Rectangle(0, 0, clipWidth, clipHeight), ImageLockMode.ReadWrite, bitmap.PixelFormat);

            try
            {
                var handle = NativeMethods.FPDFBitmap_CreateEx(clipWidth, clipHeight, 4, data.Scan0, clipWidth * 4);

                try
                {
                    uint background = (flags & PdfRenderFlags.Transparent) == 0 ? 0xFFFFFFFF : 0x00FFFFFF;

                    NativeMethods.FPDFBitmap_FillRect(handle, 0, 0, clipWidth, clipHeight, background);

                    bool success = RenderPDFPageToBitmap(
                        handle,
                        (int)dpiX, (int)dpiY, -clipX, -clipY, width, height,
                        (int)rotate,
                        FlagsToFPDFFlags(flags),
                        (flags & PdfRenderFlags.Annotations) != 0
                        );

                    if (!success)
                    {
                        throw new Exception();
                    }
                }
                finally
                {
                    NativeMethods.FPDFBitmap_Destroy(handle);
                }
            }
            finally
            {
                bitmap.UnlockBits(data);
            }

            return(bitmap);
        }
 public void RotatePage(int page, PdfRotation rotate)
 {
     Rotate = rotate;
     OnPagesDisplayModeChanged();
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Rotate the PDF document right.
 /// </summary>
 public void RotateRight()
 {
     Rotation = (PdfRotation)(((int)Rotation + 1) % 4);
 }
 public static void FPDFPage_SetRotation(IntPtr page, PdfRotation rotation)
 {
     lock (LockString)
     {
         Imports.FPDFPage_SetRotation(page, (int)rotation);
     }
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Rotate the page.
 /// </summary>
 /// <param name="page">The page to rotate.</param>
 /// <param name="rotation">How to rotate the page.</param>
 public void RotatePage(int page, PdfRotation rotation)
 {
     _file.RotatePage(page, rotation);
     _pageSizes[page] = _file.GetPDFDocInfo(page);
 }
Ejemplo n.º 25
0
 public void RotatePage(int pageNumber, PdfRotation rotation)
 {
     _file.RotatePage(pageNumber, rotation);
     _pageSizes[pageNumber] = _file.GetPDFDocInfo(pageNumber);
 }
Ejemplo n.º 26
0
        public RawRenderData Render(int page, int width, int height, float dpiX, float dpiY, PdfRotation rotate, PdfRenderFlags flags)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            if ((flags & PdfRenderFlags.CorrectFromDpi) != 0)
            {
                width  = width * (int)dpiX / 72;
                height = height * (int)dpiY / 72;
            }

            var byteArray = new byte[4 * width * height];

            var gcHandle = GCHandle.Alloc(byteArray, GCHandleType.Pinned);

            try
            {
                var handle = NativeMethods.FPDFBitmap_CreateEx(width, height, 4, gcHandle.AddrOfPinnedObject(), width * 4);

                try
                {
                    uint background = (flags & PdfRenderFlags.Transparent) == 0 ? 0xFFFFFFFF : 0x00FFFFFF;

                    NativeMethods.FPDFBitmap_FillRect(handle, 0, 0, width, height, background);

                    bool success = _file.RenderPDFPageToBitmap(
                        page,
                        handle,
                        0, 0, width, height,
                        (int)rotate,
                        _flagsToFPDFFlags(flags),
                        (flags & PdfRenderFlags.Annotations) != 0
                        );

                    if (!success)
                    {
                        throw new Win32Exception();
                    }
                }
                finally
                {
                    NativeMethods.FPDFBitmap_Destroy(handle);
                }
            }
            finally
            {
                gcHandle.Free();
            }

            return(new RawRenderData(byteArray, width, height));
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Renders a page of the PDF document to an image.
        /// </summary>
        /// <param name="page">Number of the page to render.</param>
        /// <param name="width">Width of the rendered image.</param>
        /// <param name="height">Height of the rendered image.</param>
        /// <param name="dpiX">Horizontal DPI.</param>
        /// <param name="dpiY">Vertical DPI.</param>
        /// <param name="rotate">Rotation.</param>
        /// <param name="flags">Flags used to influence the rendering.</param>
        /// <param name="renderFormFill">Render form fills.</param>
        /// <returns>The rendered image.</returns>
        public SKBitmap Render(int page, int width, int height, float dpiX, float dpiY, PdfRotation rotate, PdfRenderFlags flags, bool renderFormFill)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            if ((flags & PdfRenderFlags.CorrectFromDpi) != 0)
            {
                width  = width * (int)dpiX / 72;
                height = height * (int)dpiY / 72;
            }

            var bitmap = new SKBitmap(width, height);
            var handle = NativeMethods.FPDFBitmap_CreateEx(width, height, 4, bitmap.GetPixels(), width * 4);

            try
            {
                uint background = (flags & PdfRenderFlags.Transparent) == 0 ? 0xFFFFFFFF : 0x00FFFFFF;

                NativeMethods.FPDFBitmap_FillRect(handle, 0, 0, width, height, background);

                bool success = _file !.RenderPDFPageToBitmap(
                    page,
                    handle,
                    0, 0, width, height,
                    (int)rotate,
                    FlagsToFPDFFlags(flags),
                    renderFormFill
                    );

                if (!success)
                {
                    throw new Win32Exception();
                }
            }
            finally
            {
                NativeMethods.FPDFBitmap_Destroy(handle);
            }

            return(bitmap);
        }
Ejemplo n.º 28
0
 public void RotatePage(int pageNumber, PdfRotation rotation)
 {
     NativeMethods.FPDFPage_SetRotation(GetPageData(pageNumber).Page, rotation);
 }
Ejemplo n.º 29
0
 public Image Render(int page, int width, int height, float dpiX, float dpiY, PdfRotation rotate, PdfRenderFlags flags)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 30
0
 public Image Render(int page, int width, int height, float dpiX, float dpiY, PdfRotation rotate, PdfRenderFlags flags)
 {
     return(_document.Render(page, width, height, dpiX, dpiY, rotate, flags));
 }
Ejemplo n.º 31
0
 public void RotatePage(int page, PdfRotation rotation)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 32
0
 public void RotatePage(int pageNumber, PdfRotation rotation)
 {
     _file.RotatePage(pageNumber, rotation);
     _pageSizes[pageNumber] = _file.GetPDFDocInfo(pageNumber);
 }
Ejemplo n.º 33
0
        private void Rotate(PdfRotation rotate)
        {
            // PdfRenderer does not support changes to the loaded document,
            // so we fake it by reloading the document into the renderer.

            int page = pdfViewer1.Renderer.Page;
            var document = pdfViewer1.Document;
            pdfViewer1.Document = null;
            document.RotatePage(page, rotate);
            pdfViewer1.Document = document;
            pdfViewer1.Renderer.Page = page;
        }