Exemplo n.º 1
0
        private void SingleDocument_Click(object sender, EventArgs e)
        {
            C1PrintDocument doc = new C1PrintDocument();

            // ensure document can be cancelled:
            doc.DoEvents = true;

            // load into preview:
            this._pview.Document = doc;

            ProgressForm pf = new ProgressForm();

            pf.Show();

            // Build the document:
            try
            {
                FilesPrinter fp = new FilesPrinter();
                fp.MakeMultiDocument(doc, tbDir.Text, tbMask.Text, pf);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            // Reset cancel state of the progress form:
            pf.DialogResult = System.Windows.Forms.DialogResult.None;

            // Set up event handlers for better UI:
            this.FormClosing += (ss, ee) =>
            {
                if (doc.BusyState == BusyStateEnum.Generating)
                {
                    doc.Cancel = true;
                }
            };

            doc.LongOperation += (ss, ee) =>
            {
                pf.SetProgress(string.Format("Generating C1MultiDocument, {0:P} complete...", ee.Complete), (float)ee.Complete);
                if (pf.Cancelled && doc.BusyState == BusyStateEnum.Generating)
                {
                    doc.Cancel = true;
                }
            };

            doc.DocumentEnded += (ss, ee) =>
            {
                pf.Hide();
                this.Activate();
            };

            // Generate the document:
            doc.Generate();
        }
Exemplo n.º 2
0
 // re-generates the document keeping the current preview position
 private void RegenerateDocument(C1PrintDocument doc)
 {
     // NOTE the use of C1PreviewPane.LayoutSection - it will prevent flickering
     // and make redisplay smoother.
     using (new C1PreviewPane.LayoutSection(c1PrintPreviewControl1.PreviewPane, HistorySavedActionsEnum.None))
     {
         PointF pos = c1PrintPreviewControl1.PreviewPane.PreviewScrollPosition;
         doc.Generate();
         c1PrintPreviewControl1.PreviewPane.PreviewScrollPosition = pos;
     }
 }
Exemplo n.º 3
0
        static void MakeReport()
        {
            // report definition must be in the current directory:
            string dir = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
            // use C1PrintDocument to generate the report:
            C1PrintDocument doc = new C1PrintDocument();

            doc.ImportC1Report(Path.Combine(dir, @"CommonTasks.xml"), @"01: Alternating Background (Greenbar report)");
            doc.Generate();
            doc.Export(Path.Combine(dir, "OutputFromSampleExternalExe.PDF"), new OutputRange(new int[] { 1, 2 }), false);
        }
Exemplo n.º 4
0
        private void GenerateDoc(C1PrintDocument doc)
        {
            doc.Style.Font = new Font("Verdana", 18);


            RenderText rt = new RenderText();

            rt.Text = "New style property:\rUnit Style.CharSpacing { get; set; }\rAllows to define character spacing in text. (The default is zero.)";
            rt.Style.Borders.All    = new LineDef("1mm", Color.Red);
            rt.Style.Spacing.Bottom = "10mm";
            doc.Body.Children.Add(rt);


            Unit cs = "2mm";

            doc.Body.Children.Add(new RenderText("CharSpacing: " + cs.ToString()));
            rt = new RenderText();
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < 30; i++)
            {
                sb.Append(string.Format("Fragment{0} ", i));
            }
            sb.Remove(sb.Length - 1, 1);
            rt.Text = sb.ToString();
            rt.Style.Borders.All = LineDef.Default;
            rt.Style.BackColor   = Color.LawnGreen;
            rt.Style.CharSpacing = cs;
            doc.Body.Children.Add(rt);


            cs = "-2pt";
            doc.Body.Children.Add(new RenderText("CharSpacing: " + cs.ToString()));
            rt = new RenderText();
            sb = new StringBuilder();
            for (int i = 0; i < 30; i++)
            {
                sb.Append(string.Format("Fragment{0} ", i));
            }
            sb.Remove(sb.Length - 1, 1);
            rt.Text = sb.ToString();
            rt.Style.Borders.All = LineDef.Default;
            rt.Style.BackColor   = Color.LawnGreen;
            rt.Style.CharSpacing = cs;
            doc.Body.Children.Add(rt);

            doc.Generate();
        }
Exemplo n.º 5
0
        private void GenerateDoc(C1PrintDocument doc)
        {
            doc.Style.Font = new Font("Verdana", 18);

            RenderText rt = new RenderText();

            rt.Text = "New style property:\rfloat Style.CharWidth { get; set; }\rAllows to define the width of text characters, it is define a percent of width relative to normal width i.e. 100 - normal width (default), 200 - 2times wider.";
            rt.Style.Borders.All    = new LineDef("1mm", Color.Red);
            rt.Style.Spacing.Bottom = "10mm";
            doc.Body.Children.Add(rt);


            float cw = 200;

            doc.Body.Children.Add(new RenderText("CharWidth: " + cw.ToString()));
            rt = new RenderText();
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < 30; i++)
            {
                sb.Append(string.Format("Fragment{0} ", i));
            }
            sb.Remove(sb.Length - 1, 1);
            rt.Text = sb.ToString();
            rt.Style.Borders.All = LineDef.Default;
            rt.Style.BackColor   = Color.LawnGreen;
            rt.Style.CharWidth   = cw;
            doc.Body.Children.Add(rt);


            cw = 50;
            doc.Body.Children.Add(new RenderText("CharWidth: " + cw.ToString()));
            rt = new RenderText();
            sb = new StringBuilder();
            for (int i = 0; i < 30; i++)
            {
                sb.Append(string.Format("Fragment{0} ", i));
            }
            sb.Remove(sb.Length - 1, 1);
            rt.Text = sb.ToString();
            rt.Style.Borders.All = LineDef.Default;
            rt.Style.BackColor   = Color.LawnGreen;
            rt.Style.CharWidth   = cw;
            doc.Body.Children.Add(rt);

            doc.Generate();
        }
Exemplo n.º 6
0
        private void GenerateDoc(C1PrintDocument doc)
        {
            doc.Style.Font = new Font("Verdana", 18);

            RenderText rt = new RenderText();

            rt.Text = "New mode of horizontal text alignment: AlignHorzEnum.JustifyChars.\rSpaces added between all chars rather than only between words as is the case with AlignHorzEnum.Justify.";
            rt.Style.Borders.All    = new LineDef("1mm", Color.Red);
            rt.Style.Spacing.Bottom = "10mm";
            doc.Body.Children.Add(rt);

            doc.Body.Children.Add(new RenderText("AlignHorzEnum.JustifyChars:"));
            rt = new RenderText();
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < 30; i++)
            {
                sb.Append(string.Format("Fragment{0} ", i));
            }
            sb.Remove(sb.Length - 1, 1);
            rt.Text = sb.ToString();
            rt.Style.Borders.All   = LineDef.Default;
            rt.Style.BackColor     = Color.LawnGreen;
            rt.Style.TextAlignHorz = AlignHorzEnum.JustifyChars;
            doc.Body.Children.Add(rt);


            doc.Body.Children.Add(new RenderText("AlignHorzEnum.Justify:"));
            rt = new RenderText();
            sb = new StringBuilder();
            for (int i = 0; i < 30; i++)
            {
                sb.Append(string.Format("Fragment{0} ", i));
            }
            sb.Remove(sb.Length - 1, 1);
            rt.Text = sb.ToString();
            rt.Style.Borders.All   = LineDef.Default;
            rt.Style.BackColor     = Color.LawnGreen;
            rt.Style.TextAlignHorz = AlignHorzEnum.Justify;
            doc.Body.Children.Add(rt);


            doc.Generate();
        }
Exemplo n.º 7
0
        private void MakeDoc1(C1PrintDocument doc)
        {
            // create the title of document
            RenderParagraph rp = new RenderParagraph();

            rp.Content.AddText("You can get coordinates and sizes of individual characters in a text block using the ");
            rp.Content.AddText("GetCharRect()", Color.Blue);
            rp.Content.AddText(" method of RenderText and RenderParagraph classes.\r\n");
            rp.Content.AddText("In the following example each character has a red rectangle drawn around it.");
            rp.Style.Font           = new Font("Verdana", 15);
            rp.Style.Spacing.Bottom = "3mm";
            rp.Style.Borders.Bottom = LineDef.DefaultBold;
            rp.Style.TextAlignHorz  = AlignHorzEnum.Justify;
            doc.Body.Children.Add(rp);

            rp            = new RenderParagraph();
            rp.Style.Font = new Font("Arial", 36);
            rp.Content.Add(new ParagraphText("Normal text", TextPositionEnum.Normal));
            rp.Content.Add(new ParagraphText("Super script text\r\n", TextPositionEnum.Superscript));
            rp.Content.Add(new ParagraphText("Sub script text\r\n", TextPositionEnum.Subscript));
            rp.Content.Add(new ParagraphText("Normal text. ", TextPositionEnum.Normal));
            rp.Content.Add(new ParagraphText("Sub script. ", TextPositionEnum.Subscript));
            rp.Content.Add(new ParagraphText("Super script. ", TextPositionEnum.Superscript));
            rp.Content.Add(new ParagraphText("Normal text.\r\n"));
            rp.Content.Add(new ParagraphText("Normal text Normal text Normal text Normal text Normal text Normal text Normal text Normal text."));
            doc.Body.Children.Add(rp);

            // To use the GetCharRect method, we must first generate
            // the document so that character positions are calculated.
            // The generation will be later repeated with drawing
            // red rectangles around the individual characters.
            doc.Generate();

            int textLength = rp.TextLength;
            // Fragments contain info about the rendered objects:
            // get the first fragment of rp object
            RenderParagraphFragment rpf = (RenderParagraphFragment)rp.Fragments[0];

            // go over all characters in the text
            for (int i = 0; i < textLength; ++i)
            {
                // get the coordinates of character,
                // they will be returned in C1PrintDocument.ResolvedUnit units
                RectangleD charRect = rpf.GetCharRect(i);

                // make a rectangle around the char
                RenderRectangle r = new RenderRectangle();
                // specify all coordinates of rectangle
                r.X      = new Unit(rpf.Bounds.Left + charRect.Left, doc.ResolvedUnit);
                r.Y      = new Unit(rpf.Bounds.Top + charRect.Top, doc.ResolvedUnit);
                r.Width  = new Unit(charRect.Width, doc.ResolvedUnit);
                r.Height = new Unit(charRect.Height, doc.ResolvedUnit);
                // set shape (rectangle) coordinates, they are specified
                // relative to object
                r.Rectangle.X      = 0;
                r.Rectangle.Y      = 0;
                r.Rectangle.Width  = r.Width;
                r.Rectangle.Height = r.Height;
                r.Style.ShapeLine  = new LineDef("1pt", Color.Red);
                // add the rectangle to the object
                doc.Body.Children.Add(r);
            }
        }
Exemplo n.º 8
0
        /*private RenderObject CreateItem(string caption, Style style)
         * {
         *  RenderArea result = new RenderArea();
         *  result.Style.Padding.All = "1mm";
         *
         *  RenderText rt = new RenderText();
         *  rt.Text = caption;
         *  rt.Style.AmbientParent = style;
         *  result.Children.Add(rt);
         *
         *  RenderInputText rit = new RenderInputText();
         *  rit.Style.AmbientParent = style;
         *  rit.Width = "parent.width";
         *  result.Children.Add(rit);
         *
         *  return result;
         * }*/

        private void GenerateDoc(C1PrintDocument doc)
        {
            doc.Clear();
            RenderTable       ph      = new RenderTable(doc);
            RenderInputButton rbPrior = new RenderInputButton(doc, "<<");

            rbPrior.InputActions.Add(
                UserActionEnum.Click,
                new ActionHandlerLink(new C1LinkTargetPage(PageJumpTypeEnum.Previous)));
            RenderInputButton rbNext = new RenderInputButton(doc, ">>");

            rbNext.X = "parent.Width - width";
            rbNext.InputActions.Add(
                UserActionEnum.Click,
                new ActionHandlerLink(new C1LinkTargetPage(PageJumpTypeEnum.Next)));
            ph.Cells[0, 0].Area.Children.Add(rbPrior);
            ph.Cells[0, 1].Area.Children.Add(rbNext);
            ph.Style.Borders.Bottom = new LineDef("1pt", Color.Black);
            ph.Style.Spacing.Bottom = "5mm";

            doc.PageLayout.PageHeader = ph;

            doc.PageLayout.PageFooter = new RenderText(doc, "Page [PageNo] of [PageCount]", AlignHorzEnum.Right);

            // create styles
            _captionStyle                = doc.Style.Children.Add();
            _captionStyle.Font           = new Font("Tahoma", 16, FontStyle.Bold);
            _captionStyle.BackColor      = Color.FromArgb(208, 237, 253);
            _captionStyle.Spacing.Bottom = "5mm";

            _fieldCaptionStyle      = doc.Style.Children.Add();
            _fieldCaptionStyle.Font = new Font("Tahoma", 13);

            _requiredCharStyle           = doc.Style.Children.Add();
            _requiredCharStyle.Parents   = _fieldCaptionStyle;
            _requiredCharStyle.TextColor = Color.Red;

            _passwordInfoStyle              = doc.Style.Children.Add();
            _passwordInfoStyle.Parents      = _fieldCaptionStyle;
            _passwordInfoStyle.TextPosition = TextPositionEnum.Subscript;

            _textFieldStyle      = doc.Style.Children.Add();
            _textFieldStyle.Font = new Font("Tahoma", 12, FontStyle.Bold);

            // Personal information
            doc.Body.Children.Add(new RenderText(doc, "Personal information", _captionStyle, _captionStyle));
            // create RenderTable containing the form's fields
            RenderTable rt = new RenderTable(doc);

            rt.CellStyle.Padding.All    = "0.5mm";
            rt.Cells[0, 0].RenderObject = CreateFieldCaption(doc, "First name:", true, false);
            rt.Cells[1, 0].RenderObject = CreateTextField(doc, "FirstName", Color.Black, false);

            rt.Cells[0, 1].RenderObject = CreateFieldCaption(doc, "Last name:", true, false);
            rt.Cells[1, 1].RenderObject = CreateTextField(doc, "LastName", Color.Black, false);

            rt.Cells[2, 0].RenderObject = CreateFieldCaption(doc, "Email Address:", true, false);
            rt.Cells[3, 0].RenderObject = CreateTextField(doc, "EmailAddress", Color.Blue, false);

            rt.Cells[2, 1].RenderObject = CreateFieldCaption(doc, "Retype Email Address:", true, false);
            rt.Cells[3, 1].RenderObject = CreateTextField(doc, "RetypeEmailAddress", Color.Blue, false);

            rt.Cells[4, 0].RenderObject = CreateFieldCaption(doc, "Password:"******"Password", Color.Black, true);

            rt.Cells[4, 1].RenderObject = CreateFieldCaption(doc, "Retype Password:"******"RetypePassword", Color.Black, true);

            rt.Cells[6, 0].RenderObject = CreateFieldCaption(doc, "City:", false, false);
            rt.Cells[7, 0].RenderObject = CreateTextField(doc, "City", Color.Black, false);

            rt.Cells[6, 1].RenderObject = CreateFieldCaption(doc, "State:", false, false);
            rt.Cells[7, 1].RenderObject = CreateTextField(doc, "State", Color.Black, false);

            // add the "Select" button
            RenderArea        ra = new RenderArea(doc);
            RenderInputButton rb = new RenderInputButton(doc, "Select...");

            rb.Name = "Select";
            rb.X    = "parent.Width - width";
            ra.Children.Add(rb);
            rt.Cells[8, 1].RenderObject = ra;

            // Work status field
            rt.Cells[9, 0].RenderObject = CreateFieldCaption(doc, "Work status:", true, false);
            rt.Cells[9, 0].SpanCols     = 2;

            rt.Cells[10, 0].RenderObject = new RenderInputRadioButton(doc, "StatusCitizen", "I am a citizen");
            ((RenderInputRadioButton)rt.Cells[10, 0].RenderObject).Checked = true;
            rt.Cells[10, 1].RenderObject = new RenderInputRadioButton(doc, "StatusAny", "I am authorized to work for any employer");
            rt.Cells[11, 0].RenderObject = new RenderInputRadioButton(doc, "StatusCurrent", "I am authorized to work for my current employer");
            rt.Cells[11, 1].RenderObject = new RenderInputRadioButton(doc, "StatusSeeking", "I am seeking authorization");
            rt.Style.Spacing.Bottom      = "5mm";
            doc.Body.Children.Add(rt);

            //
            doc.Body.Children.Add(new RenderText(doc, "Interests", _captionStyle, _captionStyle));

            rt = new RenderTable(doc);
            rt.Cells[0, 0].RenderObject = new RenderInputCheckBox(doc, "Accounting");
            rt.Cells[0, 1].RenderObject = new RenderInputCheckBox(doc, "General Business");
            rt.Cells[0, 2].RenderObject = new RenderInputCheckBox(doc, "Pharmaceutical");
            rt.Cells[1, 0].RenderObject = new RenderInputCheckBox(doc, "Admin & Clerical");
            rt.Cells[1, 1].RenderObject = new RenderInputCheckBox(doc, "General Labor");
            rt.Cells[1, 2].RenderObject = new RenderInputCheckBox(doc, "Professional Services");
            rt.Cells[2, 0].RenderObject = new RenderInputCheckBox(doc, "Automotive");
            rt.Cells[2, 1].RenderObject = new RenderInputCheckBox(doc, "Government");
            rt.Cells[2, 2].RenderObject = new RenderInputCheckBox(doc, "QA - Quality Control");
            rt.Cells[2, 0].RenderObject = new RenderInputCheckBox(doc, "Biotech");
            rt.Cells[2, 1].RenderObject = new RenderInputCheckBox(doc, "Information Technology");
            rt.Cells[2, 2].RenderObject = new RenderInputCheckBox(doc, "Warehouse");
            rt.BreakAfter = BreakEnum.Page;
            doc.Body.Children.Add(rt);


            doc.Body.Children.Add(new RenderText(doc, "Desired Position", _captionStyle, _captionStyle));
            doc.Body.Children.Add(new RenderText(doc, "Describe your desired position by completing as many of the following questions as possible.\n\nPlease indicate the wage you are seeking."));

            rt = new RenderTable(doc);
            rt.Cells[0, 0].RenderObject = new RenderInputCheckBox(doc, "Full-time");
            rt.Cells[0, 1].RenderObject = new RenderInputCheckBox(doc, "Part-time");
            rt.Cells[0, 2].RenderObject = new RenderInputCheckBox(doc, "Intern");
            rt.Cells[1, 0].RenderObject = new RenderInputCheckBox(doc, "Seasonal");
            rt.Cells[1, 1].RenderObject = new RenderInputCheckBox(doc, "Temporary");
            rt.Style.Spacing.Bottom     = "5mm";
            doc.Body.Children.Add(rt);

            doc.Body.Children.Add(new RenderText(doc, "How many miles are you willing to commute to work?"));
            RenderInputComboBox rc = new RenderInputComboBox(
                doc,
                "-- Select Distance --",
                "1 mile",
                "5 miles",
                "10 miles",
                "25 miles",
                "50 miles",
                "100 miles");

            rc.Text                 = rc.Items[0].Text;
            rc.Style.Parents        = _textFieldStyle;
            rc.Style.Spacing.Bottom = "5mm";
            doc.Body.Children.Add(rc);

            doc.Body.Children.Add(new RenderText(doc, "How often are you willing to travel for work?"));
            rc = new RenderInputComboBox(
                doc,
                "Negligible",
                "Up to 25%",
                "Up to 50%",
                "Road Warrior");
            rc.DropDownStyle = ComboBoxStyle.DropDownList;
            rc.Text          = rc.Items[0].Text;
            doc.Body.Children.Add(rc);

            // Save button
            rb = new RenderInputButton(doc, "Save...");
            rb.AcceptButton = true;
            rb.InputActions.Add(
                UserActionEnum.Click,
                new ActionHandlerFileSave());
            doc.Body.Children.Add(rb);

            rb = new RenderInputButton(doc, "Save as PDF...");
            rb.InputActions.Add(
                UserActionEnum.Click,
                new ActionHandlerFileSave(null, ExportProviders.PdfExportProvider));
            doc.Body.Children.Add(rb);


            doc.Generate();
        }
Exemplo n.º 9
0
        private void MakeDoc1(C1PrintDocument doc)
        {
            // setup a page header with links to first|prev|next|last pages:
            RenderTable rtnav = new RenderTable();

            // suppress different display of visited hyperlinks for page navigator:
            rtnav.Style.VisitedHyperlinkAttrs = rtnav.Style.HyperlinkAttrs;
            // space things out
            rtnav.Style.Spacing.Bottom = "5mm";
            // add navigator links
            rtnav.Cells[0, 0].Text = "First page";
            rtnav.Cells[0, 0].RenderObject.Hyperlink = new C1Hyperlink(
                new C1LinkTargetPage(PageJumpTypeEnum.First), "Go to first page");
            rtnav.Cells[0, 1].Text = "Previous page";
            rtnav.Cells[0, 1].RenderObject.Hyperlink = new C1Hyperlink(
                new C1LinkTargetPage(PageJumpTypeEnum.Previous), "Go to previous page");
            rtnav.Cells[0, 2].Text = "Next page";
            rtnav.Cells[0, 2].RenderObject.Hyperlink = new C1Hyperlink(
                new C1LinkTargetPage(PageJumpTypeEnum.Next), "Go to next page");
            rtnav.Cells[0, 3].Text = "Last page";
            rtnav.Cells[0, 3].RenderObject.Hyperlink = new C1Hyperlink(
                new C1LinkTargetPage(PageJumpTypeEnum.Last), "Go to last page");
            doc.PageLayout.PageHeader = rtnav;

            // make the body of the document

            // make an anchor
            RenderText rt1 = new RenderText("This is text with anchor1.");

            // the name ("anchor1") will be used to jump to this link:
            rt1.Anchors.Add(new C1Anchor("anchor1"));
            rt1.Hyperlink = new C1Hyperlink(new C1LinkTargetPage(PageJumpTypeEnum.Last),
                                            "Go to the last page of the document");
            doc.Body.Children.Add(rt1);

            //--------------------------------------------------------------------
            // make an external document to jump to:
            C1PrintDocument doc2   = new C1PrintDocument();
            RenderText      doc2rt = new RenderText("This is Document 2.");

            doc2rt.Style.Spacing.All = "3mm";
            doc2rt.Style.Font        = new Font("Arial", 14);
            // anchor names must be unique within the document but not across documents
            doc2rt.Anchors.Add(new C1Anchor("anchor1"));
            doc2.Body.Children.Add(doc2rt);
            // make a button in the new document to go back
            RenderInputButton doc2btn = new RenderInputButton("Go back...");

            doc2btn.Width  = "3cm";
            doc2btn.Height = "1cm";
            doc2btn.InputActions.Add(UserActionEnum.Click, new ActionHandlerHistoryPrev());
            doc2.Body.Children.Add(doc2btn);
            doc2.Generate();
            // save the document in our run dir:
            string doc2path = Application.StartupPath + @"\doc2.c1d";

            doc2.Save(doc2path);
            //--------------------------------------------------------------------

            // add a link to open doc2:
            RenderText rt2 = new RenderText("Click here to open Document 2.");

            rt2.Hyperlink = new C1Hyperlink(
                new C1LinkTargetExternalAnchor(doc2path, "anchor1"));
            doc.Body.Children.Add(rt2);

            // add filler
            for (int i = 0; i < 500; ++i)
            {
                doc.Body.Children.Add(new RenderText(string.Format("... filler {0} ...", i)));
            }

            // add hyperlink to anchor1
            RenderText rt3 = new RenderText("Click here to go to anchor1.");

            rt3.Hyperlink = new C1Hyperlink(new C1LinkTargetAnchor("anchor1"),
                                            "This is status text when the mouse hovers over link to anchor1");
            doc.Body.Children.Add(rt3);

            // to jump to a render object, an anchor is really not needed:
            RenderText rt4 = new RenderText("Click here to go to the middle of document.");

            rt4.Hyperlink            = new C1Hyperlink(doc.Body.Children[doc.Body.Children.Count / 2]);
            rt4.Hyperlink.StatusText = "Go to the approximate middle of the document";
            doc.Body.Children.Add(rt4);

            // add image with hyperlink to a URL
            RenderImage ri1 = new RenderImage(global::Hyperlinks.Properties.Resources.google);

            ri1.Hyperlink = new C1Hyperlink(new C1LinkTargetFile("http://www.google.com"),
                                            "Go googling...");
            doc.Body.Children.Add(ri1);
        }
Exemplo n.º 10
0
        private void CreateDoc(C1PrintDocument doc)
        {
            doc.Clear();

            doc.PageLayout.PageSettings.Landscape = true;

            Style codeStyle = doc.Style.Children.Add();

            codeStyle.Font = new Font("Courier New", 12);
            Style captionStyle = doc.Style.Children.Add();

            captionStyle.Font = new Font("Tahoma", 18, FontStyle.Bold);

            RenderParagraph rp = new RenderParagraph();

            rp.Style.Borders.All = new LineDef("1mm", Color.Blue);
            rp.Style.BackColor   = Color.LightBlue;
            rp.Style.Font        = new Font("Tahoma", 16);
            rp.Content.Add(new ParagraphText("This sample demostrates using of HyperlinkPageNo tag\r\r", captionStyle));
            rp.Content.Add(new ParagraphText("It returns number of page that hyperlink points. For example:\r\r"));
            rp.Content.Add(new ParagraphText("rt = new RenderText();\r", codeStyle));
            rp.Content.Add(new ParagraphText("rt.Text = \"(C1LinkTargetDocumentLocation) Goto page: [HyperlinkPageNo]\";\r", codeStyle));
            rp.Content.Add(new ParagraphText("rt.Hyperlink = new C1Hyperlink(new C1LinkTargetDocumentLocation(rt2));\r", codeStyle));
            rp.Content.Add(new ParagraphText("rt.Style.Borders.All = LineDef.Default;\r", codeStyle));
            rp.Content.Add(new ParagraphText("doc.Body.Children.Add(rt);", codeStyle));
            rp.Content.Add(new ParagraphText("\r\rTag HyperlinkPageNo will be replaced with number of page where object rt2 is.\r"));
            rp.Content.Add(new ParagraphText("It must be taken into consideration that when the document is being resolved, it is not always possible to evaluate HyperlinkPageNo (e.g. if it references an object that has not been resolved yet). "));
            rp.Content.Add(new ParagraphText("In such cases, if the object contains many HyperlinkPageNo tags and has auto width and/or height, the calculated size may differ from the correct size as instead of actual page numbers, the string \"XXX\" is used for size calculation.\r"));
            rp.Content.Add(new ParagraphText("To minimize such errors::\r"));
            rp.Content.Add(new ParagraphText("- use absolute sizes for such objets;\r"));
            rp.Content.Add(new ParagraphText("- place hyperlinks after the objects they reference.\r\r"));
            rp.Content.Add(new ParagraphText("In this sample, the document contains two RenderParagraph objects, each of which has HyperlinkPageNo tags. "));
            rp.Content.Add(new ParagraphText("The first paragraph is placed before the table, and hence its size is slightly bigger. The other paragraph follows the table and hence its size is exactly right."));
            doc.Body.Children.Add(rp);

            doc.Style.Font = new Font("Tahoma", 16);

            // generate siple table (3 x 100)
            RenderTable rt = new RenderTable();

            for (int r = 0; r < 100; r++)
            {
                for (int c = 0; c < 3; c++)
                {
                    rt.Cells[r, c].Text = string.Format("Cell {0}:{1}", r, c);
                }
            }
            rt.Style.GridLines.All = LineDef.DefaultBold;

            // generate RenderParagraph with hyperlinks
            rp = new RenderParagraph();
            rp.Style.Borders.All = new LineDef("1mm", Color.Red);
            rp.Style.Spacing.All = "5mm";
            rp.Style.Padding.All = "1mm";
            rp.RepeatBordersVert = true;
            rp.Content.Add(new ParagraphText("Content:\r\r", new Font("Verdana", 20)));
            for (int r = 0; r < rt.Rows.Count; r++)
            {
                ParagraphText pt = new ParagraphText(string.Format("Row{0} ([HyperlinkPageNo])", r));
                pt.Hyperlink = new C1Hyperlink(new C1LinkTargetDocumentLocation(rt.Cells[r, 0]));
                rp.Content.Add(pt);
                if (r < rt.Rows.Count - 1)
                {
                    rp.Content.Add(new ParagraphText(", "));
                }
            }
            // add paragraph into document BEFORE table
            doc.Body.Children.Add(rp);
            // add table
            doc.Body.Children.Add(rt);

            // add paragraph into document AFTER table
            RenderParagraph rp2 = (RenderParagraph)rp.Clone();

            doc.Body.Children.Add(rp2);

            doc.Generate();
        }