private void Rotate(PdfRotation rotate) { int page = pdfViewer1.Renderer.Page; pdfViewer1.Document.RotatePage(page, rotate); pdfViewer1.Renderer.ReloadDocument(); }
/// <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); } }
public static void FPDFPage_SetRotation(IntPtr page, PdfRotation rotation) { lock (LockString) { Imports.FPDFPage_SetRotation(page, (int)rotation); } }
public void RotatePage(int pageNumber, PdfRotation rotation) { using (var pageData = new PageData(_document, _form, pageNumber)) { NativeMethods.FPDFPage_SetRotation(pageData.Page, rotation); } }
public void Rotate(PdfRotation rotation) { _rotation = rotation; if (pdfViewer.Document != null) { pdfViewer.Renderer.Rotation = _rotation; } }
/// <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); }
private void ButtonRotateLeft_Click(object sender, EventArgs e) { rotation--; if (rotation < PdfRotation.Rotate0) { rotation = PdfRotation.Rotate270; } pdfPanel1.Rotate(rotation); pdfPanel2.Rotate(rotation); }
private void ButtonRotateRight_Click(object sender, EventArgs e) { rotation++; if (rotation > PdfRotation.Rotate270) { rotation = PdfRotation.Rotate0; } pdfPanel1.Rotate(rotation); pdfPanel2.Rotate(rotation); }
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; }
/// <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)); }
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; }
/// <summary> /// Rotate the PDF document left. /// </summary> public void RotateLeft() { Rotation = (PdfRotation)(((int)Rotation + 3) % 4); }
/// <summary> /// Rotate the PDF document right. /// </summary> public void RotateRight() { Rotation = (PdfRotation)(((int)Rotation + 1) % 4); }
public void RotatePage(int pageNumber, PdfRotation rotation) { _document.RotatePage(TranslatePage(pageNumber), rotation); }
/// <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); }
/// <summary> /// Rotates the page. /// </summary> /// <param name="rotation">Specify the rotation.</param> public void RotatePage(PdfRotation rotation) => NativeMethods.FPDFPage_SetRotation(Page, rotation);
/// <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)); }
/// <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)); }
/// <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(); }
/// <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); }
public void RotatePage(int pageNumber, PdfRotation rotation) { _file.RotatePage(pageNumber, rotation); _pageSizes[pageNumber] = _file.GetPDFDocInfo(pageNumber); }
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)); }
/// <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); }
public void RotatePage(int pageNumber, PdfRotation rotation) { NativeMethods.FPDFPage_SetRotation(GetPageData(pageNumber).Page, rotation); }
public Image Render(int page, int width, int height, float dpiX, float dpiY, PdfRotation rotate, PdfRenderFlags flags) { throw new NotImplementedException(); }
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)); }
public void RotatePage(int page, PdfRotation rotation) { throw new NotImplementedException(); }