private void CalcSize(IntPtr currentPage, double dpiX, double dpiY, RectangleF printableArea, bool isLandscape, out double width, out double height, out double x, out double y) { x = y = 0; width = Pdfium.FPDF_GetPageWidth(currentPage) / 72 * dpiX; height = Pdfium.FPDF_GetPageHeight(currentPage) / 72 * dpiY; if (_useDP) { return; } //Calculate the size of the printable area in pixels var fitSize = new SizeF( (float)dpiX * printableArea.Width / 100.0f, (float)dpiY * printableArea.Height / 100.0f ); var pageSize = new SizeF( (float)width, (float)height ); var rot = Pdfium.FPDFPage_GetRotation(currentPage); bool isRotated = (rot == PageRotate.Rotate270 || rot == PageRotate.Rotate90) || (width > height); if (AutoRotate && isRotated) { fitSize = new SizeF(fitSize.Height, fitSize.Width); } else if (!AutoRotate && isLandscape) { fitSize = new SizeF(fitSize.Height, fitSize.Width); } switch (PrintSizeMode) { case PrintSizeMode.Fit: var sz = GetRenderSize(pageSize, fitSize); width = sz.Width; height = sz.Height; break; case PrintSizeMode.CustomScale: width *= (double)Scale / 100.0; height *= (double)Scale / 100.0; break; case PrintSizeMode.ActualSize: default: break; } if (AutoCenter) { x = (fitSize.Width - width) / 2; y = (fitSize.Height - height) / 2; } }
private PageRotate CalcRotation(IntPtr currentPage, bool isLandscape, ref double width, ref double height) { var rot = Pdfium.FPDFPage_GetRotation(currentPage); bool isRotated = (rot == PageRotate.Rotate270 || rot == PageRotate.Rotate90) || (width > height); if (AutoRotate && isRotated != isLandscape) { double tmp = width; width = height; height = tmp; return(rot == PageRotate.Rotate270 ? PageRotate.Rotate90 : PageRotate.Rotate270); } return(PageRotate.Normal); }
/// <summary> /// Raises the System.Drawing.Printing.PrintDocument.QueryPageSettings event. It /// is called immediately before each System.Drawing.Printing.PrintDocument.PrintPage event. /// </summary> /// <param name="e">A System.Drawing.Printing.QueryPageSettingsEventArgs that contains the event data.</param> protected override void OnQueryPageSettings(QueryPageSettingsEventArgs e) { if (AutoRotate) { IntPtr currentPage = Pdfium.FPDF_StartLoadPage(_docForPrint, _pageForPrint); if (currentPage == IntPtr.Zero) { e.Cancel = true; return; } double width = Pdfium.FPDF_GetPageWidth(currentPage); double height = Pdfium.FPDF_GetPageHeight(currentPage); var rotation = Pdfium.FPDFPage_GetRotation(currentPage); bool isRotated = (/*rotation == PageRotate.Rotate270 || rotation == PageRotate.Rotate90 ||*/ width > height); e.PageSettings.Landscape = isRotated; if (currentPage != IntPtr.Zero) { Pdfium.FPDF_ClosePage(currentPage); } } base.OnQueryPageSettings(e); }