public void StartPage()
        {
            if (PrinterSettings.InstalledPrinters.Count == 0)
            {
                Assert.Ignore("The test depends on printer being available.");
            }

            using (Form f = new Form())
            {
                PrintPreviewControl p = new PrintPreviewControl();
                f.Controls.Add(p);
                f.Show();

                Assert.AreEqual(0, p.StartPage);
                Assert.AreEqual(1, p.Rows);
                Assert.AreEqual(1, p.Columns);
                p.StartPage = 4;
                Assert.AreEqual(4, p.StartPage);

                PrintDocument document    = new PrintDocument();
                int           page_number = 0;
                int           page_count  = 1;
                document.BeginPrint += (sender, e) => page_number = 0;
                document.PrintPage  += (sender, e) => e.HasMorePages = ++page_number < page_count;

                p.Document = document;
                p.Refresh();
                Assert.AreEqual(0, p.StartPage);

                page_count = 8;
                p.InvalidatePreview();
                p.Refresh();
                Assert.AreEqual(4, p.StartPage);
            }
        }
        // ページ設定ボタンハンドラ
        private void SettingPrintPreviewDialog_toolStripButtonPageSetupClick(object sender, EventArgs e)
        {
            if (Document == null)
            {
                return;
            }

            PageSetupDialog.EnableMetric = true;
            PageSetupDialog.Document     = Document;
            PrintDialog.PrinterSettings  = Document.PrinterSettings;
            if (PageSetupDialog.ShowDialog() == DialogResult.OK)
            {
                Document.PrinterSettings            = (PrinterSettings)PageSetupDialog.PrinterSettings.Clone();
                Document.PrinterSettings.PrintRange = PrintRange.AllPages;
                PrintPreviewControl.InvalidatePreview();
            }
        }
        // 印刷ボタンハンドラ
        private void SettingPrintPreviewDialog_toolStripButtonPrintClick(object sender, EventArgs e)
        {
            if (Document == null)
            {
                return;
            }

            if (Document.PrinterSettings == null)
            {
                Document.PrinterSettings = new PrinterSettings();
            }
            PrintDialog.PrinterSettings = Document.PrinterSettings;
            PrintDialog.Document        = Document;
            PrintDialog.PrinterSettings = Document.PrinterSettings;
            if (PrintDialog.ShowDialog() == DialogResult.OK)
            {
                Document.Print();
                Document.PrinterSettings.PrintRange = PrintRange.AllPages;
                PrintPreviewControl.InvalidatePreview();
            }
        }
Exemplo n.º 4
0
        public void printpage(bool printed)
        {
            document.Sections.Clear();



            section = document.AddSection();

            SizeF sf = new SizeF();

            for (int i = 0; i < mReportApp.mPagelist.Count; i++)
            {
                if (mReportApp.mPagelist[i].Name == mReportApp.pagesize)
                {
                    sf = mReportApp.mPagelist[i].size;
                }
            }

            section.PageSetup.PageSize       = sf;
            section.PageSetup.Margins.Top    = mReportApp.Margins;
            section.PageSetup.Margins.Bottom = mReportApp.Margins / 2;
            section.PageSetup.Margins.Left   = mReportApp.Margins;
            section.PageSetup.Margins.Right  = mReportApp.Margins;

            if (mReportApp.Landscape == true)
            {
                section.PageSetup.Orientation = PageOrientation.Landscape;
            }
            else
            {
                section.PageSetup.Orientation = PageOrientation.Portrait;
            }



            HeaderFooter header = section.HeadersFooters.Header;
            HeaderFooter footer = section.HeadersFooters.Footer;


            Paragraph headerParagraph = header.AddParagraph();


            if (mReportApp.headerposition == 0)
            {
                headerParagraph.Format.HorizontalAlignment
                    = Spire.Doc.Documents.HorizontalAlignment.Left;
            }
            else if (mReportApp.headerposition == 1)
            {
                headerParagraph.Format.HorizontalAlignment
                    = Spire.Doc.Documents.HorizontalAlignment.Center;
            }
            else if (mReportApp.headerposition == 2)
            {
                headerParagraph.Format.HorizontalAlignment
                    = Spire.Doc.Documents.HorizontalAlignment.Right;
            }



            headerParagraph.Format.Borders.Bottom.BorderType
                = Spire.Doc.Documents.BorderStyle.Single;
            headerParagraph.Format.Borders.Bottom.Space = 0.05F;

            mReportApp.ChangeReportValue();

            for (int i = 0; i < mReportApp.mreportheader.Count; i++)
            {
                if (mReportApp.mreportheader[i].kind == 0)
                {
                    string s = "";
                    s = s.PadLeft(Convert.ToInt16(mReportApp.mreportheader[i].mspace), Convert.ToChar(" "));
                    if (mReportApp.mreportheader[i].showcaption == false)
                    {
                        s = s + mReportApp.mreportheader[i].txtresult;
                    }
                    else
                    {
                        s = s + mReportApp.mreportheader[i].Name + ":" + mReportApp.mreportheader[i].txtresult;
                    }



                    TextRange text = headerParagraph.AppendText(s);
                    text.CharacterFormat.FontName = mReportApp.mreportheader[i].font.Name;
                    text.CharacterFormat.FontSize = mReportApp.mreportheader[i].font.Size;
                    text.CharacterFormat.Italic   = mReportApp.mreportheader[i].font.Italic;
                    text.CharacterFormat.Bold     = mReportApp.mreportheader[i].font.Bold;
                }
                if (mReportApp.mreportheader[i].kind == 2)
                {
                    if (mReportApp.mreportheader[i].filename.Trim() == "")
                    {
                    }
                    else
                    {
                        string s = "";
                        s = s.PadLeft(Convert.ToInt16(mReportApp.mreportheader[i].mspace), Convert.ToChar(" "));

                        TextRange text = headerParagraph.AppendText(s);
                        text.CharacterFormat.FontName = mReportApp.mreportheader[i].font.Name;
                        text.CharacterFormat.FontSize = mReportApp.mreportheader[i].font.Size;
                        text.CharacterFormat.Italic   = mReportApp.mreportheader[i].font.Italic;
                        text.CharacterFormat.Bold     = mReportApp.mreportheader[i].font.Bold;

                        DocPicture headerPicture
                            = headerParagraph.AppendPicture(Image.FromFile(System.Windows.Forms.Application.StartupPath + "\\AppleLabJ\\bmp\\" + mReportApp.mreportheader[i].filename));

                        headerPicture.HorizontalAlignment = ShapeHorizontalAlignment.Left;
                    }
                }

                if (mReportApp.mreportheader[i].kind == 1)
                {
                    string s = "";
                    s = s.PadLeft(Convert.ToInt16(mReportApp.mreportheader[i].mspace), Convert.ToChar(" "));
                    s = s + mReportApp.mreportheader[i].txtresult;
                    TextRange text = headerParagraph.AppendText(s);
                    text.CharacterFormat.FontName = mReportApp.mreportheader[i].font.Name;
                    text.CharacterFormat.FontSize = mReportApp.mreportheader[i].font.Size;
                    text.CharacterFormat.Italic   = mReportApp.mreportheader[i].font.Italic;
                    text.CharacterFormat.Bold     = mReportApp.mreportheader[i].font.Bold;
                }
            }



            for (int i = 0; i < mReportApp.mreportbody.Count; i++)
            {
                Paragraph paragraph = section.AddParagraph();

                if (mReportApp.mreportbody[i].align == 0)
                {
                    paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left;
                }
                else if (mReportApp.mreportbody[i].align == 1)
                {
                    paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
                }
                else if (mReportApp.mreportbody[i].align == 2)
                {
                    paragraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right;
                }

                for (int j = 0; j < mReportApp.mreportbody[i].vspace; j++)
                {
                    paragraph.AppendBreak(BreakType.LineBreak);
                }

                if (mReportApp.mreportbody[i].kind == 0)
                {
                    string s = "";
                    s = s.PadLeft(Convert.ToInt16(mReportApp.mreportbody[i].mspace), Convert.ToChar(" "));
                    if (mReportApp.mreportbody[i].showcaption == false)
                    {
                        s = s + mReportApp.mreportbody[i].txtresult;
                    }
                    else
                    {
                        s = s + mReportApp.mreportbody[i].Name + ":" + mReportApp.mreportbody[i].txtresult;
                    }
                    TextRange text = paragraph.AppendText(s);
                    text.CharacterFormat.FontName = mReportApp.mreportbody[i].font.Name;
                    text.CharacterFormat.FontSize = mReportApp.mreportbody[i].font.Size;
                    text.CharacterFormat.Italic   = mReportApp.mreportbody[i].font.Italic;
                    text.CharacterFormat.Bold     = mReportApp.mreportbody[i].font.Bold;
                }

                if (mReportApp.mreportbody[i].kind == 3)
                {
                    string s = "";
                    s = s.PadLeft(Convert.ToInt16(mReportApp.mreportbody[i].mspace), Convert.ToChar(" "));
                    if (mReportApp.mreportbody[i].showcaption == false)
                    {
                    }
                    else
                    {
                        s = s + mReportApp.mreportbody[i].Name + ":";
                    }
                    TextRange text = paragraph.AppendText(s);
                    text.CharacterFormat.FontName = mReportApp.mreportbody[i].font.Name;
                    text.CharacterFormat.FontSize = mReportApp.mreportbody[i].font.Size;
                    text.CharacterFormat.Italic   = mReportApp.mreportbody[i].font.Italic;
                    text.CharacterFormat.Bold     = mReportApp.mreportbody[i].font.Bold;

                    if (mReportApp.mreportbody[i].Name == "曲线图1")
                    {
                        InsertImage(section, 1);
                    }

                    if (mReportApp.mreportbody[i].Name == "曲线图2")
                    {
                        InsertImage(section, 2);
                    }
                }

                if (mReportApp.mreportbody[i].kind == 4)
                {
                    string s = "";
                    s = s.PadLeft(Convert.ToInt16(mReportApp.mreportbody[i].mspace), Convert.ToChar(" "));
                    if (mReportApp.mreportbody[i].showcaption == false)
                    {
                    }
                    else
                    {
                        s = s + mReportApp.mreportbody[i].Name + ":";
                    }
                    TextRange text = paragraph.AppendText(s);
                    text.CharacterFormat.FontName = mReportApp.mreportbody[i].font.Name;
                    text.CharacterFormat.FontSize = mReportApp.mreportbody[i].font.Size;
                    text.CharacterFormat.Italic   = mReportApp.mreportbody[i].font.Italic;
                    text.CharacterFormat.Bold     = mReportApp.mreportbody[i].font.Bold;

                    if (mReportApp.mreportbody[i].Name == "结果表格1")
                    {
                        addTable(section, 1);
                    }

                    if (mReportApp.mreportbody[i].Name == "结果表格2")
                    {
                        addTable(section, 2);
                    }
                }
            }



            Paragraph footerParagraph = footer.AddParagraph();

            footerParagraph.Format.Borders.Bottom.BorderType
                = Spire.Doc.Documents.BorderStyle.Single;

            Paragraph FParagraph = footer.AddParagraph();



            for (int i = 0; i < mReportApp.mreportfooter.Count; i++)
            {
                if (mReportApp.mreportfooter[i].kind == 0)
                {
                    string s = "";
                    s = s.PadLeft(Convert.ToInt16(mReportApp.mreportfooter[i].mspace), Convert.ToChar(" "));
                    if (mReportApp.mreportfooter[i].showcaption == false)
                    {
                        s = s + mReportApp.mreportfooter[i].txtresult;
                    }
                    else
                    {
                        s = s + mReportApp.mreportfooter[i].Name + ":" + mReportApp.mreportfooter[i].txtresult;
                    }



                    TextRange text = FParagraph.AppendText(s);
                    text.CharacterFormat.FontName = mReportApp.mreportfooter[i].font.Name;
                    text.CharacterFormat.FontSize = mReportApp.mreportfooter[i].font.Size;
                    text.CharacterFormat.Italic   = mReportApp.mreportfooter[i].font.Italic;
                    text.CharacterFormat.Bold     = mReportApp.mreportfooter[i].font.Bold;
                }
                if (mReportApp.mreportfooter[i].kind == 2)
                {
                    if (mReportApp.mreportfooter[i].filename.Trim() == "")
                    {
                    }
                    else
                    {
                        string s = "";
                        s = s.PadLeft(Convert.ToInt16(mReportApp.mreportfooter[i].mspace), Convert.ToChar(" "));

                        TextRange text = footerParagraph.AppendText(s);
                        text.CharacterFormat.FontName = mReportApp.mreportfooter[i].font.Name;
                        text.CharacterFormat.FontSize = mReportApp.mreportfooter[i].font.Size;
                        text.CharacterFormat.Italic   = mReportApp.mreportfooter[i].font.Italic;
                        text.CharacterFormat.Bold     = mReportApp.mreportfooter[i].font.Bold;

                        DocPicture footerPicture
                            = FParagraph.AppendPicture(Image.FromFile(System.Windows.Forms.Application.StartupPath + "\\AppleLabJ\\bmp\\" + mReportApp.mreportfooter[i].filename));

                        footerPicture.HorizontalAlignment = ShapeHorizontalAlignment.Left;
                    }
                }

                if (mReportApp.mreportfooter[i].kind == 1)
                {
                    string s = "";
                    s = s.PadLeft(Convert.ToInt16(mReportApp.mreportfooter[i].mspace), Convert.ToChar(" "));
                    s = s + mReportApp.mreportfooter[i].txtresult;
                    TextRange text = FParagraph.AppendText(s);
                    text.CharacterFormat.FontName = mReportApp.mreportfooter[i].font.Name;
                    text.CharacterFormat.FontSize = mReportApp.mreportfooter[i].font.Size;
                    text.CharacterFormat.Italic   = mReportApp.mreportfooter[i].font.Italic;
                    text.CharacterFormat.Bold     = mReportApp.mreportfooter[i].font.Bold;
                }
            }



            FParagraph.AppendText("    ");
            FParagraph.AppendField("page number", FieldType.FieldPage);
            FParagraph.AppendText(" of ");
            FParagraph.AppendField("number of pages", FieldType.FieldNumPages);


            if (mReportApp.footerposition == 0)
            {
                FParagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Left;
            }
            else if (mReportApp.footerposition == 1)
            {
                FParagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
            }
            else if (mReportApp.footerposition == 2)
            {
                FParagraph.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Right;
            }



            //Set Footer Paragrah Format



            FParagraph.Format.Borders.Top.BorderType = Spire.Doc.Documents.BorderStyle.Hairline;

            FParagraph.Format.Borders.Top.Space = 0.01f;


            FParagraph.Format.Borders.Color = Color.Black;



            dialog.AllowCurrentPage = true;
            dialog.AllowSomePages   = true;
            dialog.UseEXDialog      = true;



            dialog.PrinterSettings.DefaultPageSettings.Landscape = mReportApp.Landscape;



            document.PrintDialog = dialog;



            if (printed == false)
            {
                if (UserControl报告常规1 == null)
                {
                    PrintPreviewControl m1 = new PrintPreviewControl();
                    m1.Document = document.PrintDocument;
                    m1.InvalidatePreview();
                }
                else
                {
                    UserControl报告常规1.printPreviewControl1.Document = document.PrintDocument;


                    UserControl报告常规1.printPreviewControl1.InvalidatePreview();
                }
            }
            else
            {
                document.PrintDialog = dialog;


                document.PrintDocument.Print();
            }
        }