Example #1
0
        public void CreateMeasurementGraphics_Default_ReturnsExpected()
        {
            var printerSettings = new PrinterSettings();

            using (Graphics graphic = printerSettings.CreateMeasurementGraphics())
            {
                Assert.NotNull(graphic);
                Assert.Equal(printerSettings.DefaultPageSettings.Bounds.X, graphic.VisibleClipBounds.X, 0);
                Assert.Equal(printerSettings.DefaultPageSettings.Bounds.Y, graphic.VisibleClipBounds.Y, 0);
                Assert.Equal(printerSettings.DefaultPageSettings.PrintableArea.Height, graphic.VisibleClipBounds.Height, 0);
                Assert.Equal(printerSettings.DefaultPageSettings.PrintableArea.Width, graphic.VisibleClipBounds.Width, 0);
            }
        }
    /// <summary>
    /// Add a new page to the document
    /// </summary>
    public void NewPage()
    {
        // Add a new page to the page collection and set it as the current page
        Bitmap bmp;

        using (Graphics g = PrinterSettings.CreateMeasurementGraphics()) {
            int w = (Int32)(CurrentPaperSize.Width * g.DpiX) - (Int32)(((DefaultPageSettings.Margins.Left + DefaultPageSettings.Margins.Right) / 100) * g.DpiX);
            int h = (Int32)(CurrentPaperSize.Height * g.DpiY) - (Int32)(((DefaultPageSettings.Margins.Top + DefaultPageSettings.Margins.Bottom) / 100) * g.DpiY);
            bmp = new Bitmap(w, h);
            bmp.SetResolution(g.DpiX, g.DpiY);
        }
        // reset X and Y positions
        Y = 0;
        X = 0;
        // Add new page to the collection
        Pages.Add(bmp);
        CurrentPage++;
    }
Example #3
0
        private void navBarItemPrintDirectly_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            try
            {
                using (XtraReportDemo report = new XtraReportDemo())
                {
                    ReportPrintTool printTool = new ReportPrintTool(report);

                    report.Margins.Left   = 0;                  //work
                    report.Margins.Right  = 0;                  //work
                    report.Margins.Top    = 200;                //not work
                    report.Margins.Bottom = 200;                //not work

                    PrinterSettings ps = new PrinterSettings(); //use PrinterName if the printer is not the default one
                    ////ps.PrinterName = ""; //Specify PrinterName
                    using (Graphics g = ps.CreateMeasurementGraphics(ps.DefaultPageSettings))
                    {
                        var margins = DevExpress.XtraPrinting.Native.DeviceCaps.GetMinMargins(g); //in default report units; do conversion with the help PSUnitConverter when needed
                    }

                    report.CreateDocument();
                    report.PrintingSystem.ShowMarginsWarning = false;

                    printTool.Print();
                }
            }
            catch (OutOfMemoryException catchOutOfMemoryException)
            {
            }
            catch (Exception catchException)
            {
            }
            finally
            {
            }
        }
Example #4
0
        public int LineasPagina(string tpdoc)
        {
            string pname;

            if (tpdoc.Equals("CCF") || tpdoc.Equals("FAC"))
            {
                pname = Config.Obtener.Prt_Doc;
            }
            else
            {
                pname = Config.Obtener.Prt_Tck;
            }

            PrinterSettings settings = new PrinterSettings();

            settings.PrinterName = pname;
            lnxpagina            = (int)(settings.DefaultPageSettings.Bounds.Height / printFont.GetHeight(settings.CreateMeasurementGraphics()));
            return(lnxpagina);
        }
Example #5
0
        /// <summary>
        /// Prints the report.
        /// </summary>
        /// <param name="printerName">Name of the printer.</param>
        /// <param name="reportPath">The report path.</param>
        /// <param name="tmpReportDetails">The TMP report details.</param>
        /// <returns>true if morethan 1 pages else false</returns>
        public bool PrintReport(string printerName, string reportPath, ReportDetails tmpReportDetails)
        {
            ////Added by Biju on 26-Nov-07 to fix the report printing format issue - START
            ////try
            ////{
            ////    string reportFilePath = Createpdf(tmpReportDetails.ReportFile, reportPath, tmpReportDetails);

            ////    RegistryPermission fread = new RegistryPermission(RegistryPermissionAccess.Read, @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\App Paths\AcroRd32.exe");
            ////    fread.AddPathList(RegistryPermissionAccess.Read | RegistryPermissionAccess.Write, @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\App Paths\AcroRd32.exe");
            ////    RegistryKey ourKey = Registry.LocalMachine;
            ////    ourKey = ourKey.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\AcroRd32.exe", true);
            ////    string acrobatreaderlocation = ourKey.GetValue("").ToString();
            ////    ourKey.Close();
            ////    ourKey = null;

            ////    PdfFilePrinter.AdobeReaderPath = acrobatreaderlocation;

            ////    PrintDocument printpdfdoc = new PrintDocument();

            ////    //Set the PDF Document and Printer Name (default printer name will be used).
            ////    PdfFilePrinter pdfprinter = new PdfFilePrinter(reportFilePath, printpdfdoc.PrinterSettings.PrinterName);

            ////    // Send the document to the printer and try to close acrobat after the time period.
            ////    //Added be Malliga on 23/6/2008 for issue 2651
            ////    this.getWaittime.GetCommentsConfigDetails.Clear();
            ////    this.getWaittime = GetConfigDetails("TS_WaitTime");
            ////    if (this.getWaittime.GetCommentsConfigDetails.Rows.Count > 0)
            ////    {
            ////        this.waittime = int.Parse(this.getWaittime.GetCommentsConfigDetails[0][this.getWaittime.GetCommentsConfigDetails.ConfigurationValueColumn.ColumnName].ToString());
            ////    }  //END

            ////    pdfprinter.Print(this.waittime);
            ////}
            ////catch (System.Exception sysexp)
            ////{
            ////    MessageBox.Show(sysexp.Message, "Some Error Occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
            ////}
            ////return true;

            ////Added by Biju on 26-Nov-07 to fix the report printing format issue - END
            ////Commented by Biju on 26-Nov-07 to fix the report printing format issue - START
            if (tmpReportDetails.OptionalReportParameter != null)
            {
                IDictionaryEnumerator en = tmpReportDetails.OptionalReportParameter.GetEnumerator();
                en.MoveNext();
                this.RenderedReport = this.RenderReport(reportPath, en.Key.ToString(), en.Value.ToString());
            }
            else
            {
                this.RenderedReport = this.RenderReport(reportPath, "", "");
            }

            // Wait for the report to completely render.
            if (this.numberOfPages < 1)
            {
                return(false);
            }
            else
            {
                PrinterSettings printerSettings = new PrinterSettings();

                printerSettings.PrinterName = printerName;

                printerSettings.MaximumPage = this.numberOfPages;
                printerSettings.MinimumPage = 1;
                printerSettings.PrintRange  = PrintRange.SomePages;
                printerSettings.FromPage    = 1;
                printerSettings.ToPage      = this.numberOfPages;

                PageSettings pageSetting = new PageSettings(printerSettings);
                if (WSHelper.ExecInfo != null)
                {
                    int width, height;
                    int.TryParse(Math.Floor(WSHelper.ExecInfo.ReportPageSettings.PaperSize.Width * 0.0393700787402 * 100).ToString(), out width);
                    int.TryParse(Math.Floor(WSHelper.ExecInfo.ReportPageSettings.PaperSize.Height * 0.0393700787402 * 100).ToString(), out height);
                    //printerSettings.DefaultPageSettings.PaperSize = new PaperSize("Custom Size", width, height);
                    pageSetting.PaperSize = new PaperSize("Custom Size", width, height);
                    int left, right, top, bottom, tempVar;
                    int.TryParse(Math.Floor(WSHelper.ExecInfo.ReportPageSettings.Margins.Left * 0.0393700787402 * 100).ToString(), out left);
                    int.TryParse(Math.Floor(WSHelper.ExecInfo.ReportPageSettings.Margins.Right * 0.0393700787402 * 100).ToString(), out right);
                    int.TryParse(Math.Floor(WSHelper.ExecInfo.ReportPageSettings.Margins.Top * 0.0393700787402 * 100).ToString(), out top);
                    int.TryParse(Math.Floor(WSHelper.ExecInfo.ReportPageSettings.Margins.Bottom * 0.0393700787402 * 100).ToString(), out bottom);

                    PrintDocument pd = new PrintDocument();

                    if (width > height)
                    {
                        printerSettings.DefaultPageSettings.Landscape = true;
                        //pd.DefaultPageSettings.Landscape = true;
                        pageSetting.Landscape = true;
                        tempVar = left;
                        left    = right;
                        right   = tempVar;

                        tempVar = top;
                        top     = bottom;
                        bottom  = tempVar;
                    }

                    printerSettings.DefaultPageSettings.Margins = new Margins(left, right, top, bottom);
                    pageSetting.Margins            = new Margins(left, right, top, bottom);
                    pd.DefaultPageSettings.Margins = new Margins(left, right, top, bottom);
                    printerSettings.CreateMeasurementGraphics(pageSetting, true);


                    //pd.DefaultPageSettings.Margins = new Margins(left, right, top, bottom);
                    this.currentPrintingPage = 1;
                    this.lastPrintingPage    = this.numberOfPages;
                    pd.PrinterSettings       = printerSettings;
                    pd.PrintPage            += new PrintPageEventHandler(this.PrintPage);
                    pd.Print();
                }
            }

            return(true);
            ////Commented by Biju on 26-Nov-07 to fix the report printing format issue - END
        }
        /**
         * printDocument -
         *
         * displays a print dialog in order to print the current document
         */
        public void printDocument()
        {
            // check for a null document
            if (document == null)
            {
                MessageBox.Show("A PDF must be open in order to print.", "Datalogics DotNETViewer");
                return;
            }

            // continuous page printing not supported
            if (PageDisplayMode == PageViewMode.continuousPage)
            {
                MessageBox.Show("Unable to Print in Continuous Page Mode", "Print Error", MessageBoxButtons.OK);
                return;
            }

            try
            {
                double docGreatestWidthInPrinterRezUnits = 0.0;
                double docGreatestWidthInInches          = 0.0;
                double docGreatestWidthInPDFUserUnits    = 0.0;

                double docHeightInInches          = 0.0;
                double docHeightInPrinterRezUnits = 0.0;
                double docHeightInPDFUserUnits    = 0.0;

                Graphics graphics;
                uint     resolutionX;
                uint     resolutionY;

                // DLADD wrl 6/24/08 -- Use DotNET shrinkToFit flag to handle scaling
                bool shrinkToFit = false;

                PrintDocument printDocument = new PrintDocument();

                // create the settings to use while printing
                PrinterSettings printerSettings = printDocument.PrinterSettings;
                printerSettings.MinimumPage = 1;
                printerSettings.MaximumPage = document.NumPages;
                printerSettings.PrintRange  = PrintRange.AllPages;
                printerSettings.FromPage    = 1;
                printerSettings.ToPage      = document.NumPages;

                // create a print dialog
                DotNETPrintDialog dpd = new DotNETPrintDialog();
                dpd.Document       = printDocument;
                dpd.AllowSelection = false;
                dpd.AllowSomePages = true;

                if (PageDisplayMode == PageViewMode.singlePage)
                {
                    dpd.AllowShrinkToFit = true;
                    dpd.ShrinkToFit      = true;
                }

                // display the print dialog if the user does not
                // click "OK" throw a new exception to cancel printing
                if (dpd.ShowDialog() != DialogResult.OK)
                {
                    throw new CancelPrinting();
                }

                shrinkToFit = dpd.ShrinkToFit;

                graphics    = printerSettings.CreateMeasurementGraphics();
                resolutionX = (uint)graphics.DpiX;
                resolutionY = (uint)graphics.DpiY;

                // grab some additional parameters if printing to a file
                if (printerSettings.PrintToFile)
                {
                    SaveFileDialog saveFileDialog = new SaveFileDialog();
                    saveFileDialog.DefaultExt = ".plt";
                    saveFileDialog.FileName   = "plot.plt";

                    if (saveFileDialog.ShowDialog() != DialogResult.OK)
                    {
                        throw new CancelPrinting();
                    }
                    else
                    {
                        printerSettings.PrintFileName = saveFileDialog.FileName;
                    }
                }

                // find the dimensions we need for printing
                docGreatestWidthInPDFUserUnits = 0;
                for (int i = 0; i < document.NumPages; ++i)
                {
                    using (Page page = document.GetPage(i)) docGreatestWidthInPDFUserUnits = Math.Max(docGreatestWidthInPDFUserUnits, page.CropBox.Width);
                }
                docHeightInPDFUserUnits = 0;
                for (int i = printerSettings.FromPage - 1; i <= printerSettings.ToPage - 1; ++i)
                {
                    using (Page page = document.GetPage(i)) docHeightInPDFUserUnits += page.CropBox.Height;
                }

                docGreatestWidthInInches = docGreatestWidthInPDFUserUnits / (double)GlobalConsts.pdfDPI;
                docHeightInInches        = docHeightInPDFUserUnits / (double)GlobalConsts.pdfDPI;

                docGreatestWidthInPrinterRezUnits = docGreatestWidthInInches * (double)resolutionX;
                docHeightInPrinterRezUnits        = docHeightInInches * (double)resolutionY;

                if (PageDisplayMode == PageViewMode.singlePage)
                {
#if HAS_DATALOGICS_PRINTING
                    Printer S_printer = new Printer(printerSettings.PrinterName);

                    if (S_printer.HardwareID == "isysij18")
                    {
                        // special workaround for iSys iTerra IJ1800
                        // use our special print controller to print via unmanaged code
                        PrintController pc = new DLPrinterPrintController(S_printer, printDocument.PrinterSettings, document.fileName);
                        printDocument.PrintController = new PrintControllerWithStatusDialog(pc);
                    }
                    else
                    {
                        S_printer.Dispose();
                    }
#endif

                    // User can control printing of OCGs
                    DrawParams drawParams = new DrawParams();

                    for (int j = 0; j < layersManager.ocgStates.Count; j++)
                    {
                        layersManager.ocgStates[j] = layersManager.layersInDocument[j].printLayer.Checked;
                    }

                    layersManager.docLayerContext.SetOCGStates(layersManager.docLayers, layersManager.ocgStates);
                    drawParams.OptionalContentContext = layersManager.docLayerContext;

                    // create the print controller
                    DotNETPrintController ppc = new DotNETPrintController(document, printDocument, drawParams, true, shrinkToFit);

                    // start the printing
                    ppc.Print();
                }
            }
            catch (CancelPrinting)
            {
                // Ignore, user cancelled printing
            }
        }