Example #1
0
        /// <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);
        }