예제 #1
0
        public PrintLayout(string w, string h, string left, string top, string right, string bottom)
        {
            var converter    = new LengthConverter();
            var width        = (double)converter.ConvertFromInvariantString(w);
            var height       = (double)converter.ConvertFromInvariantString(h);
            var marginLeft   = (double)converter.ConvertFromInvariantString(left);
            var marginTop    = (double)converter.ConvertFromInvariantString(top);
            var marginRight  = (double)converter.ConvertFromInvariantString(right);
            var marginBottom = (double)converter.ConvertFromInvariantString(bottom);

            this._Size   = new Size(width, height);
            this._Margin = new Thickness(marginLeft, marginTop, marginRight, marginBottom);
        }
예제 #2
0
        public PrintLayout(string w, string h, string left, string top, string right, string bottom)
        {
            var converter = new LengthConverter();
            var width = (double)converter.ConvertFromInvariantString(w);
            var height = (double)converter.ConvertFromInvariantString(h);
            var marginLeft = (double)converter.ConvertFromInvariantString(left);
            var marginTop = (double)converter.ConvertFromInvariantString(top);
            var marginRight = (double)converter.ConvertFromInvariantString(right);
            var marginBottom = (double)converter.ConvertFromInvariantString(bottom);
            this._Size = new Size(width, height);
            this._Margin = new Thickness(marginLeft, marginTop, marginRight, marginBottom);

        }
예제 #3
0
        /// <summary>
        /// Get the flow document from the rich text box for printing.
        /// </summary>
        /// <param name="printTicket">The current print ticket.</param>
        /// <returns>The flow document.</returns>
        private FlowDocument GetFlowDocumentForPrinting(PrintTicket printTicket)
        {
            //Create a FlowDocument that will contain text to be printed.
            FlowDocument flowDoc          = new FlowDocument();
            TextRange    flowDocTextRange = new TextRange(flowDoc.ContentStart, flowDoc.ContentEnd);
            TextRange    rtbTextRange;

            //Using RichTextBox to generate text in FlowDocument

            //case 1: Printing contents of Rich Text Box.
            if (_printCase == 0)
            {
                // Using current Rich textbox to generate text for Flow Document.
                rtbTextRange = new TextRange(_richTextBox.Document.ContentStart, _richTextBox.Document.ContentEnd);
            }
            //Printing contents of a plain text box
            else
            {
                //create a new Rich Text Box and transfer printable text from current Textbox to it.
                RichTextBox printRichTextBox = new RichTextBox();
                printRichTextBox.FontFamily = _font.FontFamily;
                printRichTextBox.FontSize   = _fontSize;
                printRichTextBox.FontWeight = _font.Weight;
                printRichTextBox.Foreground = _brush;

                // Create a new paragraph block containing the text from the TextBox and add it to
                // the RichTextBox's document.
                Paragraph newPara = new Paragraph();
                newPara.Inlines.Clear();
                newPara.Inlines.Add(new Run(_textContent));
                if (printRichTextBox.Document.Blocks.FirstBlock != null)
                {
                    printRichTextBox.Document.Blocks.InsertBefore(printRichTextBox.Document.Blocks.FirstBlock, newPara);
                }
                else
                {
                    printRichTextBox.Document.Blocks.Add(newPara);
                }


                rtbTextRange = new TextRange(printRichTextBox.Document.ContentStart, printRichTextBox.Document.ContentEnd);
            }

            //transfering contents of RichtextBox textrange to flowDocTextRange in XML format
            //flowDoc now contains text to be printed

            string _rangeXML = TextRange_GetXml(rtbTextRange);

            TextRange_SetXml(flowDocTextRange, _rangeXML);

            ////Set margins of the Flow Document to values set in Page SetUp dialog.
            ////convert inches to logical pixels
            // Win32 PageSetupDialog uses hundredths of inches.
            // Divide by 100 to start with inches.
            LengthConverter converter      = new LengthConverter();
            double          leftInPixels   = (double)converter.ConvertFromInvariantString((_leftMargin / 100).ToString() + " in");
            double          rightInPixels  = (double)converter.ConvertFromInvariantString((_rightMargin / 100).ToString() + " in");
            double          topInPixels    = (double)converter.ConvertFromInvariantString((_topMargin / 100).ToString() + " in");
            double          bottomInPixels = (double)converter.ConvertFromInvariantString((_bottomMargin / 100).ToString() + " in");

            System.Windows.Thickness pagethickness = new Thickness(leftInPixels, topInPixels, rightInPixels, bottomInPixels);
            flowDoc.PagePadding = pagethickness;

            double maxColumnWidth;

            if (printTicket.PageMediaSize != null &&
                printTicket.PageMediaSize.Width != null)
            {
                maxColumnWidth = printTicket.PageMediaSize.Width.Value - leftInPixels - rightInPixels;
            }
            else
            {
                // fallback to Letter size if PrintTicket doesn't specify the media width
                maxColumnWidth = 816 - leftInPixels - rightInPixels;
            }

            flowDoc.ColumnWidth   = maxColumnWidth;     //ensures we get only one column
            flowDoc.FlowDirection = FlowDirectionSettings;
            return(flowDoc);
        }
예제 #4
0
 public static double ToPixels(string value)
 {
     return((double)LengthConverter.ConvertFromInvariantString(value));
 }
예제 #5
0
        private void PageInitialize()
        {
            if (printorientation == PrintingOrientation.Portrait)
            {
                FlowDocument doc = docs.Document;
                doc.PageHeight = PrintLayout.A4.Size.Height;
                doc.PageWidth = PrintLayout.A4.Size.Width;
                //doc.PagePadding = PrintLayout.A4.Margin;
                doc.ColumnGap = 0.0d;
                doc.ColumnWidth = PrintLayout.A4.ColumnWidth;
            }
            else
            {
                LengthConverter converter = new LengthConverter();

                FlowDocument doc = docs.Document;
                doc.PageHeight = PrintLayout.A4Landscape.Size.Height;
                //doc.PageWidth = PrintLayout.A4Landscape.Size.Width;
                doc.PageWidth = (double)converter.ConvertFromInvariantString(docs.Width.ToString());
                //doc.PagePadding = PrintLayout.A4.Margin;
                doc.ColumnGap = 0.0d;
                doc.ColumnWidth = PrintLayout.A4Landscape.ColumnWidth;
            }
        }