Exemple #1
0
        public override void doPrintSetup(IPageLayout2 pPageLayout)
        {
            CSpatialSubs oSpatialSubs = new CSpatialSubs();

            //short shPageForm = 0;  // see ms-help://ESRI.EDNv9.2/esricarto/html/esriPageFormID.htm for IPrinter::FormID constants
            int iPageFormID = 0;   // see http://msdn.microsoft.com/en-us/library/ms776398(VS.85).aspx for IPaper::FormID constants
            //double dblPageWidth = 0;
            //double dblPageHeight = 0;

            IMxApplication pMxApp = (IMxApplication)this.App;
            IMxDocument    pMxDoc = (IMxDocument)this.App.Document;

            IPrinter pPrinter = pMxApp.Printer;
            IPaper   pPaper   = pPrinter.Paper;

            try
            {
                pMxDoc.PageLayout.Page.Orientation = 1;
                pPaper.Orientation = 1;

                switch (this.MapSize)
                {
                case "34 x 44":
                    //shPageForm = 5; // esriPageFormID.esriPageFormE;

                    base.XFactor = 4;
                    base.YFactor = 4;

                    if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
                    {
                        iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "34 x 44");
                    }
                    else
                    {
                        iPageFormID = 26;
                    }

                    break;

                case "17 x 22":
                    //shPageForm = 3; // esriPageFormID.esriPageFormC;

                    base.XFactor = 2;
                    base.YFactor = 2;

                    if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
                    {
                        iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "17 x 22");
                    }
                    else
                    {
                        iPageFormID = 24;
                    }

                    break;

                case "11 x 17":
                    //shPageForm = 2; // esriPageFormID.esriPageFormTabloid;

                    base.XFactor = 1.3;      //1.2941
                    base.YFactor = 1.5455;   //1.5455

                    if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
                    {
                        iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "11 x 17");
                    }
                    else
                    {
                        iPageFormID = 17;
                    }

                    break;

                case "8.5 x 11":
                    //shPageForm = 0; // esriPageFormID.esriPageFormLetter;

                    base.XFactor = 1;
                    base.YFactor = 1;

                    if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
                    {
                        iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "8.5 x 11 ");
                    }
                    else
                    {
                        iPageFormID = 1;
                    }
                    break;
                }

                pPaper.PrinterName = base.PrinterName;
                pPaper.FormID      = (short)iPageFormID;

                double dblWidth  = 0;
                double dblHeight = 0;
                pPaper.QueryPaperSize(out dblWidth, out dblHeight);

                pMxDoc.PageLayout.Page.PutCustomSize(dblWidth, dblHeight);
                pMxDoc.PageLayout.Page.FormID = (esriPageFormID)Enum.Parse(typeof(esriPageFormID), iPageFormID.ToString());


                pMxDoc.ActiveView.PrinterChanged(pPrinter);



                //////----------------------------------------------------------------------------
                //////Set the layout page size and orientation.
                //////----------------------------------------------------------------------------
                //pPage = pMxDoc.PageLayout.Page;
                //pPage.Orientation = 1;
                //pPage.FormID = (esriPageFormID)Enum.Parse(typeof(esriPageFormID), iPageFormID.ToString());

                ////----------------------------------------------------------------------------
                ////Set the printer paper size and orientation.
                ////----------------------------------------------------------------------------
                //pPrinter = pMxApp.Printer;
                //pPrinter.Paper.PrinterName = base.PrinterName;
                //pPrinter.Paper.FormID = shPageForm;
                //pPrinter.Paper.Orientation = 1;

                ////----------------------------------------------------------------------------
                //// deal with the paper
                ////----------------------------------------------------------------------------
                //pPaper = pMxApp.Paper;
                //pPaper.Orientation = 1;
                //pPaper.FormID = (short)iPageFormID;
                //pPaper.PrinterName = base.PrinterName;


                //pMxDoc.ActiveView.PrinterChanged(pPrinter);

                ////////----------------------------------------------------------------------------
                ////////Set the layout page size and orientation.
                ////////----------------------------------------------------------------------------
                ////pPage = pMxDoc.PageLayout.Page;
                ////pPage.Orientation = 1;
                ////pPage.FormID = esriPageFormID.esriPageFormCUSTOM;
                ////pPage.PutCustomSize(dblPageWidth + .1, dblPageHeight + .1);
                ////pPage.PrinterChanged(pPrinter);

                ////double dblWidth = 0; double dblHeight = 0;
                ////pPaper.QueryPaperSize(out dblWidth, out dblHeight);

                ////pPage.PutCustomSize(dblWidth, dblHeight);   //(dblWidth, dblHeight);
                ////pPage.FormID = esriPageFormID.esriPageFormCUSTOM;
                ////pPage.PrinterChanged(pPrinter);

                ////pPage.PutCustomSize(dblWidth, dblHeight);
                ////pPage.PageToPrinterMapping = esriPageToPrinterMapping.esriPageMappingTile;

                //pMxApp.Printer = pPrinter;
                ////pMxDoc.PageLayout = (IPageLayout)pPage;
                //pMxDoc.PageLayout.Page.PutCustomSize(dblPageWidth - 1.8, dblPageHeight - 1.8);
                //pMxDoc.PageLayout.Page.FormID = esriPageFormID.esriPageFormSameAsPrinter;
                //pMxDoc.ActiveView.PrinterChanged(pPrinter);

                //pActiveView = (IActiveView)pMxDoc.ActiveView;
                //pActiveView.Refresh();

                //pMxApp.Printer.Paper.PrinterName = base.PrinterName;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Errors: CPortraitLayout:doPrintSetup()\r\n" + ex.Message, "Errors occurred", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
            finally
            {
                pMxDoc   = null;
                pPrinter = null;
                pPaper   = null;
                oSpatialSubs.Dispose();
            }
        }
        public override void doPrintSetup(IPageLayout2 pPageLayout)
        {
            //IMxApplication pMxApp = (IMxApplication)this.App;
            //IMxDocument pMxDoc = (IMxDocument)this.App.Document;
            //ESRI.ArcGIS.esriSystem.IEnumNamedID pEnumNamedID = (ESRI.ArcGIS.esriSystem.IEnumNamedID)pMxApp.Printer.Paper.Forms;

            //IPrinter pPrinter = null;
            //IPaper pPaper = null;
            //IPage pPage = null;
            //IActiveView pActiveView = null;

            //short shPageForm = 0;  // see ms-help://ESRI.EDNv9.2/esricarto/html/esriPaperFormID.htm for IPrinter::FormID constants

            CSpatialSubs   oSpatialSubs = new CSpatialSubs();
            IMxApplication pMxApp       = (IMxApplication)ArcMap.ThisApplication;
            IMxDocument    pMxDoc       = (IMxDocument)ArcMap.Document;
            esriPageFormID pFormID      = esriPageFormID.esriPageFormLetter;

            IPrinter pPrinter = pMxApp.Printer;
            IPaper   pPaper   = pPrinter.Paper;

            int iPageFormID = 0;   // see http://msdn.microsoft.com/en-us/library/ms776398(VS.85).aspx for IPaper::FormID constants

            try
            {
                pMxDoc.PageLayout.Page.Orientation = 2;
                pPaper.Orientation = 2;

                switch (base.MapSize)
                {
                case "34 x 44":     //34 x 44
                    if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
                    {
                        iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "34 x 44");
                    }
                    else
                    {
                        iPageFormID = 26;
                    }
                    pFormID      = esriPageFormID.esriPageFormE;
                    base.XFactor = 4;
                    base.YFactor = 4;
                    break;

                case "17 x 22":     // 17 x 22
                    if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
                    {
                        iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "17 x 22");
                    }
                    else
                    {
                        iPageFormID = 24;
                    }
                    pFormID      = esriPageFormID.esriPageFormD;
                    base.XFactor = 2;
                    base.YFactor = 2;
                    break;

                case "11 x 17":     // 11 x 22
                    if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
                    {
                        iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "11 x 17");
                    }
                    else
                    {
                        iPageFormID = 17;
                    }
                    pFormID      = esriPageFormID.esriPageFormLegal;
                    base.XFactor = 1.5455;       //1.5455;
                    base.YFactor = 1.2941;       //1.2941;
                    break;

                case "8.5 x 11":     // 8.5 x 11
                    if (pPrinter.DriverName.ToUpper().Contains("DESIGNJET"))
                    {
                        iPageFormID = oSpatialSubs.getPaperFormID(pPaper, "8.5 x 11");
                    }
                    else
                    {
                        iPageFormID = 1;
                    }
                    pFormID      = esriPageFormID.esriPageFormLetter;
                    base.XFactor = 1;
                    base.YFactor = 1;
                    break;
                }

                pPaper.PrinterName = base.PrinterName;
                pPaper.FormID      = (short)iPageFormID;

                double dblWidth  = 0;
                double dblHeight = 0;
                pPaper.QueryPaperSize(out dblWidth, out dblHeight);

                pMxDoc.PageLayout.Page.PutCustomSize(dblWidth, dblHeight);
                //pMxDoc.PageLayout.Page.FormID = (esriPageFormID)Enum.Parse(typeof(esriPageFormID), iPageFormID.ToString());

                pMxDoc.PageLayout.Page.FormID = pFormID;

                IPage pPage = pMxDoc.PageLayout.Page;
                pPage.Orientation = 2;
                pPage.FormID      = esriPageFormID.esriPageFormSameAsPrinter;

                pMxDoc.ActiveView.PrinterChanged(pPrinter);
                pMxDoc.ActiveView.Refresh();


                ////----------------------------------------------------------------------------
                ////Set the printer paper size and orientation.
                ////----------------------------------------------------------------------------
                //pPrinter = pMxApp.Printer;
                //pPrinter.Paper.PrinterName = base.PrinterName;
                //pPrinter.Paper.FormID = shPageForm;
                //pPrinter.Paper.Orientation = 2;

                //pPaper = pMxApp.Paper;
                //pPaper.Orientation = 2;
                //pPaper.FormID = (short)iPaperFormID;

                //pPaper.PrinterName = base.PrinterName;

                //pMxDoc.ActiveView.PrinterChanged(pPrinter);

                ////----------------------------------------------------------------------------
                ////Set the layout page size and orientation.
                ////----------------------------------------------------------------------------
                //pPage = pMxDoc.PageLayout.Page;
                //pPage.Orientation = 1;

                //double dblWidth = 0; double dblHeight = 0;
                //pPaper.QueryPaperSize(out dblWidth, out dblHeight);

                //pPage.PutCustomSize(dblWidth, dblHeight);

                ////pPage.FormID = esriPaperFormID.esriPageFormSameAsPrinter; // (esriPaperFormID)Enum.Parse(typeof(esriPaperFormID), shPageForm.ToString());
                ////pPage.PageToPrinterMapping = esriPageToPrinterMapping.esriPageMappingScale;

                //pPage.PrinterChanged(pPrinter);

                //pMxApp.Printer = pPrinter;
                ////pMxDoc.PageLayout = (IPageLayout)pPage.;

                //pActiveView = (IActiveView)pMxDoc.ActiveView;
                //pActiveView.Refresh();
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Errors: CLandscapeLayout:doPrintSetup()\r\n" + ex.Message, "Errors occurred", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
            finally
            {
                pMxDoc   = null;
                pPrinter = null;
                pPaper   = null;
            }
        }
Exemple #3
0
        private void printDocument_0_PrintPage(object sender, PrintPageEventArgs e)
        {
            short       dpiX;
            IEnvelope   envelopeClass;
            short       num;
            double      xMin;
            double      yMin;
            double      xMax;
            double      yMax;
            tagRECT     deviceFrame = new tagRECT();
            IEnvelope   visibleBounds;
            IntPtr      hdc;
            WKSEnvelope wKSEnvelope;
            WKSEnvelope wKSEnvelope1;

            if (this._context.ActiveView is IPageLayout)
            {
                IPageLayout2 activeView = this._context.ActiveView as IPageLayout2;
                dpiX          = (short)e.Graphics.DpiX;
                envelopeClass = new EnvelopeClass();
                IPage page = activeView.Page;
                activeView.Page.PrinterPageCount(activeView.Printer, 0, out num);
                CmdPrintPreview short0 = this;
                short0.short_0 = (short)(short0.short_0 + 1);
                IPrinter printer = activeView.Printer;
                page.GetDeviceBounds(printer, this.short_0, 0, dpiX, envelopeClass);
                envelopeClass.QueryCoords(out xMin, out yMin, out xMax, out yMax);
                deviceFrame.bottom = (int)yMax;
                deviceFrame.left   = (int)xMin;
                deviceFrame.top    = (int)yMin;
                deviceFrame.right  = (int)xMax;
                visibleBounds      = new EnvelopeClass();
                page.GetPageBounds(printer, this.short_0, 0, visibleBounds);
                hdc = e.Graphics.GetHdc();
                (activeView as IActiveView).Output(hdc.ToInt32(), dpiX, ref deviceFrame, visibleBounds, this.itrackCancel_0);
                e.Graphics.ReleaseHdc(hdc);
                if (this.short_0 >= num)
                {
                    e.HasMorePages = false;
                    this.short_0   = 0;
                }
                else
                {
                    e.HasMorePages = true;
                }
            }
            else if (this._context.ActiveView is IMap)
            {
                dpiX          = (short)e.Graphics.DpiX;
                envelopeClass = new EnvelopeClass();
                deviceFrame   = this._context.ActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame();
                IEnvelope clipEnvelope = this._context.ActiveView.ScreenDisplay.ClipEnvelope;
                visibleBounds = this._context.ActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds;
                visibleBounds.QueryCoords(out xMin, out yMin, out xMax, out yMax);
                hdc = e.Graphics.GetHdc();
                IPrinter      emfPrinterClass = new EmfPrinterClass();
                PrintDocument printDocument   = new PrintDocument();
                IPaper        paperClass      = new PaperClass()
                {
                    PrinterName = printDocument.PrinterSettings.PrinterName
                };
                emfPrinterClass.Paper = paperClass;
                emfPrinterClass.PrintableBounds.QueryWKSCoords(out wKSEnvelope);
                emfPrinterClass.PrintableBounds.QueryWKSCoords(out wKSEnvelope1);
                xMin               = wKSEnvelope1.XMin * (double)dpiX;
                xMax               = wKSEnvelope1.XMax * (double)dpiX;
                yMin               = wKSEnvelope1.YMin * (double)dpiX;
                yMax               = wKSEnvelope1.YMax * (double)dpiX;
                deviceFrame.left   = (int)Math.Round(xMin);
                deviceFrame.top    = (int)Math.Round(yMin);
                deviceFrame.right  = (int)Math.Round(xMax);
                deviceFrame.bottom = (int)Math.Round(yMax);
                try
                {
                    this._context.ActiveView.Output(hdc.ToInt32(), dpiX, ref deviceFrame, null, this.itrackCancel_0);
                }
                catch
                {
                }
                e.Graphics.ReleaseHdc(hdc);
            }
        }