Esempio n. 1
0
        private XRect GetActual(PrintPageEventArgs e)
        {
            if (_printerInteractionMode == PrinterInteractionMode.None)
            {
                return(new XRect());
            }

            var printableArea = e.PageSettings.PrintableArea;

            var l = printableArea.Left;
            var t = printableArea.Top;
            var r = e.PageBounds.Width - printableArea.Width - l;
            var b = e.PageBounds.Height - printableArea.Height - t;

            if (printableArea.Width < printableArea.Height)
            {
                l = printableArea.Top;
                t = printableArea.Left;
                r = e.PageBounds.Width - printableArea.Height - l;
                b = e.PageBounds.Height - printableArea.Width - t;
            }

            if (b < 0 || r < 0)
            {
                return(new XRect());
            }

            var sz2 = new UnitRectangle((l / 96) + "inch", (t / 96) + "inch", (r / 96) + "inch", (b / 96) + "inch");
            var actualPaperMargin = sz2.ToXRect();

            return(actualPaperMargin);
        }
Esempio n. 2
0
        public void Section_with_a_margin()
        {
            //Arrange
            var margin = new UnitRectangle {
                Top = UnitValue.Parse("1cm"), Left = UnitValue.Parse("2px"), Bottom = UnitValue.Parse("30mm"), Right = UnitValue.Parse("4cm")
            };
            var section = new Section
            {
                Margin = margin
            };
            var template = new Template(section);
            var xml      = template.ToXml();

            //Act
            var otherTemplate = Template.Load(xml);

            //Assert
            Assert.AreEqual(xml.OuterXml, otherTemplate.ToXml().OuterXml);
            Assert.AreEqual(margin.Left, otherTemplate.SectionList.First().Margin.Left);
            Assert.AreEqual(margin.Top, otherTemplate.SectionList.First().Margin.Top);
            Assert.AreEqual(margin.Right, otherTemplate.SectionList.First().Margin.Right);
            Assert.AreEqual(margin.Bottom, otherTemplate.SectionList.First().Margin.Bottom);
            Assert.AreEqual(margin.Width, otherTemplate.SectionList.First().Margin.Width);
            Assert.AreEqual(margin.Height, otherTemplate.SectionList.First().Margin.Height);
            Assert.AreEqual(margin, otherTemplate.SectionList.First().Margin);
        }
Esempio n. 3
0
 protected AreaElement()
 {
     _relativeAlignment = new UnitRectangle();
 }
        private Template GetTemplate()
        {
            var frontPageSection = new Section {
                Name = "Cover"
            };

            frontPageSection.Pane.ElementList.Add(new Text {
                Value = "{Title}", Top = "10cm", Font = new Font {
                    Size = 22
                }, TextAlignment = TextBase.Alignment.Center
            });

            var marginRectangle = new UnitRectangle {
                Left = "3cm", Top = "1cm", Bottom = "1cm", Right = "1cm"
            };
            var indexSection = new Section {
                Name = "Index", Margin = marginRectangle, Header = { Height = "2cm" }, Footer = { Height = "2cm" }
            };

            indexSection.Header.ElementList.Add(new Text {
                Value = "{Title}"
            });
            indexSection.Header.ElementList.Add(new Line {
                Top = "50%", Height = "0%"
            });
            indexSection.Footer.ElementList.Add(new Text {
                Value = "Page {PageNumber} of {TotalPages}"
            });
            indexSection.Footer.ElementList.Add(new Line {
                Top = "0%", Height = "0%"
            });

            var contentSection = new Section {
                Name = "Content", Margin = marginRectangle, Footer = indexSection.Footer, Header = indexSection.Header
            };
            var contentReferencePoint = new ReferencePoint {
                Stack = ReferencePoint.StackMethod.Vertical
            };

            contentSection.Pane.ElementList.Add(contentReferencePoint);
            contentReferencePoint.ElementList.Add(new Text {
                Font = new Font {
                    Size = 18
                }, Value = "Brief"
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Value = "The purpose of Tharga Reporter is really not to create documents like this. The main purpose is to easily create documents like invoices, delivery notes, orders, forms or other types of reports that contains much variable data. Creating the manual this way even made me find some strange bugs that I would have never found just creating invoices as I have done many times before. The code have actually been used for over five years in production. The reason for me to put the source on github is so that others can use it too, and modify it if required."
            });
            contentReferencePoint.ElementList.Add(new Text {
                Value = Environment.NewLine
            });

            contentReferencePoint.ElementList.Add(new Text {
                Font = new Font {
                    Size = 18
                }, Value = "Document Structure"
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Value = "A document is structured by creating several 'sections'. Each section can have different layout with margins, pane, header and footer. The pane is where the main content will be. The content of the header and footer can be specified once withing the section, or between sections if desired."
            });
            contentReferencePoint.ElementList.Add(new Text {
                Value = Environment.NewLine
            });

            contentReferencePoint.ElementList.Add(new Text {
                Font = new Font {
                    Size = 18
                }, Value = "Types of elements"
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Value = "There are several different types of elements that can be printed. There are Text, TextBox, Line, Rectangle, Image, Table and BarCode."
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Font = new Font {
                    Bold = true
                }, Value = "- Text"
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Value = "Text should be used for simple short text that is to appear on all pages in the document. This could be titles or descriptions. Text does not flow over multiple pages."
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Font = new Font {
                    Bold = true
                }, Value = "- TextBox"
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Value = "TextBox should be used for text that is to flow within a specified area. If the text does not fit within the area a new page will be created on the next page where the text will continue. If there are more text boxes on the samedocument, they will all flow individually and independent of eachother."
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Font = new Font {
                    Bold = true
                }, Value = "- Line"
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Value = "A line can be drawn between two points of the document. It will appear the same on all pages within the section. The thickness and color of the line can be set as requested."
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Font = new Font {
                    Bold = true
                }, Value = "- Rectangle"
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Value = "Rectangles will be drawn the same on all pages within the section, the border color and thickness can be set as well as the background."
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Font = new Font {
                    Bold = true
                }, Value = "- Image"
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Value = "An image can be loaded from disk or URL and rendered into the document. Images will appear the same on all pages within the section."
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Font = new Font {
                    Bold = true
                }, Value = "- Table"
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Value = "Tables are the most complex object to be rendered. The layout can be set in many different ways. Columns can be added and data from a data document placed into the cells. Tables will flow over several pages. It is also possible to hide columns using different directives depending on the data."
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Font = new Font {
                    Bold = true
                }, Value = "- BarCode"
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Value = "Barcodes of type 'Code39' can be rendered onto the document. They will be the same on all pages of the document within the section."
            });
            contentReferencePoint.ElementList.Add(new Text {
                Value = Environment.NewLine
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Value = "All elements have got the properties Top, Left, Name, IsBackground and Visibility."
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Value = "- Top - The location in 'Unit value' from the top where the element is to be placed. This is calculated from the top of the parent wher the element is added, it could be directly on a pane or on a reference point. Default is zero."
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Value = "- Left - The location in 'Unit value' from the left where the element is to be placed. Default is zero."
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Value = "- Name - Used for debuging and easy to read serialization."
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Value = "- IsBackground - If true, the element is only rendered if background objects are requested. When printing on pre, printed documents logotypes and addresses should not appear, but they should appear when creating a PDF, in that case they can be marked as background objects."
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Value = "- Visibility - This property can be set to specify on what pages the element should be visible. Perhaps it should only appear on the first or the last page of the document. The sum of an invoice might only be required on the last page and the address on the first page, for instance."
            });
            contentReferencePoint.ElementList.Add(new Text {
                Value = Environment.NewLine
            });

            contentReferencePoint.ElementList.Add(new Text {
                Font = new Font {
                    Size = 18
                }, Value = "Placeholder"
            });
            contentReferencePoint.ElementList.Add(new TextBox {
                Value = "There is one entity called reference point. This can be placed on a page and all types of elements can be linked to it. When the reference point is moved all elements are moved together with it. The referencepoint does not have a size, it is just like a point on the document, however elements like text and textboxes can be stacked vertically from a reference point. This is done when no top is specified and the reference point is set to 'Stack = ReferencePoint.StackMethod.Vertical'."
            });
            contentReferencePoint.ElementList.Add(new Text {
                Value = Environment.NewLine
            });

            var template = new Template(frontPageSection);

            //template.SectionList.Add(indexSection);
            template.SectionList.Add(contentSection);
            return(template);
        }