Beispiel #1
0
        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;
            }
        }
Beispiel #2
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();
            }
        }