public PageRangeDocumentPaginator(
          DocumentPaginator paginator,
          PageRange pageRange)
        {
            _startIndex = pageRange.PageFrom - 1;
            _endIndex = pageRange.PageTo - 1;
            _paginator = paginator;

            // Adjust the _endIndex
            _endIndex = Math.Min(_endIndex, _paginator.PageCount - 1);
        }
Example #2
0
 public static Range <int> ToEto(this swc.PageRange range)
 {
     return(new Range <int>(range.PageFrom, range.PageTo));
 }
Example #3
0
 public static Range ToEto(this swc.PageRange range)
 {
     return(new Range(range.PageFrom, range.PageTo - range.PageFrom + 1));
 }
		public PdfDocumentPaginator(PdfDocument document, PageRange pageRange)
		{
			_doc = document;
			_pageCount = pageRange.PageTo - pageRange.PageFrom+1;
			_pageRange = pageRange;
		}
            ExtractPrintDataAndDevMode(
                IntPtr unmanagedBuffer, 
                out string printerName,
                out UInt32 flags,
                out PageRange pageRange,
                out IntPtr devModeHandle 
                )
            { 
                IntPtr devNamesHandle = IntPtr.Zero; 
                IntPtr pageRangePtr = IntPtr.Zero;
 
                //
                // Extract the devmode and devnames handles from the appropriate PRINTDLGEX structure
                //
                if (!Is64Bit()) 
                {
                    NativeMethods.PRINTDLGEX32 pdex = (NativeMethods.PRINTDLGEX32)Marshal.PtrToStructure( 
                        unmanagedBuffer, 
                        typeof(NativeMethods.PRINTDLGEX32));
                    devModeHandle = pdex.hDevMode; 
                    devNamesHandle = pdex.hDevNames;
                    flags = pdex.Flags;
                    pageRangePtr = pdex.lpPageRanges;
                } 
                else
                { 
                    NativeMethods.PRINTDLGEX64 pdex = (NativeMethods.PRINTDLGEX64)Marshal.PtrToStructure( 
                        unmanagedBuffer,
                        typeof(NativeMethods.PRINTDLGEX64)); 
                    devModeHandle = pdex.hDevMode;
                    devNamesHandle = pdex.hDevNames;
                    flags = pdex.Flags;
                    pageRangePtr = pdex.lpPageRanges; 
                }
 
                // 
                // Get a managed copy of the page ranges.  This only matters if the PD_PAGENUMS bit is
                // set in the flags. 
                //
                if (((flags & NativeMethods.PD_PAGENUMS) == NativeMethods.PD_PAGENUMS) &&
                     (pageRangePtr != IntPtr.Zero))
                { 
                    NativeMethods.PRINTPAGERANGE pageRangeStruct = (NativeMethods.PRINTPAGERANGE)Marshal.PtrToStructure(
                            pageRangePtr, 
                            typeof(NativeMethods.PRINTPAGERANGE)); 

                    pageRange = new PageRange((int)pageRangeStruct.nFromPage, (int)pageRangeStruct.nToPage); 
                }
                else
                {
                    pageRange = new PageRange(1); 
                }
 
                // 
                // Get a managed copy of the device name
                // 
                if (devNamesHandle != IntPtr.Zero)
                {
                    IntPtr pDevNames = IntPtr.Zero;
                    try 
                    {
                        pDevNames = UnsafeNativeMethods.GlobalLock(devNamesHandle); 
 
                        NativeMethods.DEVNAMES devNames = (NativeMethods.DEVNAMES)Marshal.PtrToStructure(
                            pDevNames, 
                            typeof(NativeMethods.DEVNAMES));
                        printerName = Marshal.PtrToStringAuto(
                            (IntPtr)((int)pDevNames + (devNames.wDeviceOffset * Marshal.SystemDefaultCharSize)));
                    } 
                    finally
                    { 
                        if (pDevNames != IntPtr.Zero) 
                        {
                            UnsafeNativeMethods.GlobalUnlock(devNamesHandle); 
                        }
                    }
                }
                else 
                {
                    printerName = string.Empty; 
                } 
            }
Example #6
0
 /// <summary>Tests whether a <see cref="T:System.Windows.Controls.PageRange" /> is equal to this <see cref="T:System.Windows.Controls.PageRange" />. </summary>
 /// <param name="pageRange">The <see cref="T:System.Windows.Controls.PageRange" /> tested.</param>
 /// <returns>
 ///     <see langword="true" /> if the two <see cref="T:System.Windows.Controls.PageRange" /> objects are equal; otherwise, <see langword="false" />.</returns>
 // Token: 0x060052D7 RID: 21207 RVA: 0x00171308 File Offset: 0x0016F508
 public bool Equals(PageRange pageRange)
 {
     return(pageRange.PageFrom == this.PageFrom && pageRange.PageTo == this.PageTo);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="DocumentPaginatorEx" /> class.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="printableArea">The printable area size.</param>
        /// <param name="range">The print page range.</param>
        public DocumentPaginatorEx(FlowDocument document, Size printableArea, PageRange range)
        {
            // Clone the source document's content into a new FlowDocument.
            // This is because the pagination for the printer needs to be
            // done differently than the pagination for the displayed page.
            // We print the copy, rather that the original FlowDocument.
            var stream = new MemoryStream();
            var source = new TextRange(document.ContentStart, document.ContentEnd);
            source.Save(stream, DataFormats.Xaml);
            var documentCopy = new FlowDocument();
            var dest = new TextRange(documentCopy.ContentStart, documentCopy.ContentEnd);
            dest.Load(stream, DataFormats.Xaml);

            // Ready to go on the copy of the document
            var paginatorSource = documentCopy as IDocumentPaginatorSource;
            _flowDocumentPaginator = paginatorSource.DocumentPaginator;
            CurrentPage = 0;

            TotalPrintableArea = printableArea;
            var height = printableArea.Height;
            var width = printableArea.Width;

            var docEx = document as FlowDocumentEx;
            if (docEx != null)
            {
                width -= (docEx.PrintMargin.Left + docEx.PrintMargin.Right);
                height -= (docEx.PrintMargin.Top + docEx.PrintMargin.Bottom);
                DocumentPrintMargin = docEx.PrintMargin;
                OriginalPrintMargin = docEx.PrintMargin;

                Watermark = docEx.PrintWatermark;
                if (Watermark != null)
                {
                    Watermark.Resources = document.Resources;
                    Watermark.DataContext = document.DataContext;
                    Watermark.Measure(printableArea);
                    Watermark.Arrange(new Rect(0,0, Watermark.DesiredSize.Width, Watermark.DesiredSize.Height));
                }

                Header = docEx.PageHeader;
                if (Header != null)
                {
                    Header.Resources = document.Resources;
                    Header.DataContext = document.DataContext;
                    Header.Width = width;
                    Header.Measure(new Size(width, double.PositiveInfinity));
                    Header.Height = Header.DesiredSize.Height; // These two lines attempt to fix the size as desired and make sure it is properly measured at that
                    Header.Measure(new Size(width, Header.DesiredSize.Height));
                    Header.Arrange(new Rect(0,0, Header.DesiredSize.Width, Header.DesiredSize.Height));
                    height -= Header.DesiredSize.Height;
                    DocumentPrintMargin = new Thickness(DocumentPrintMargin.Left, DocumentPrintMargin.Top + Header.DesiredSize.Height, DocumentPrintMargin.Right, DocumentPrintMargin.Bottom);
                }

                Footer = docEx.PageFooter;
                if (Footer != null)
                {
                    Footer.Resources = document.Resources;
                    Footer.DataContext = document.DataContext;
                    Footer.Width = width;
                    Footer.Measure(new Size(width, double.PositiveInfinity));
                    Footer.Height = Footer.DesiredSize.Height; // These two lines attempt to fix the size as desired and make sure it is properly measured at that
                    Footer.Measure(new Size(width, Footer.DesiredSize.Height));
                    Footer.Arrange(new Rect(0, 0, Footer.DesiredSize.Width, Footer.DesiredSize.Height));
                    height -= Footer.DesiredSize.Height;
                    DocumentPrintMargin = new Thickness(DocumentPrintMargin.Left, DocumentPrintMargin.Top, DocumentPrintMargin.Right, DocumentPrintMargin.Bottom + Footer.DesiredSize.Height);
                }
            }
            else
                DocumentPrintMargin = new Thickness();

            _flowDocumentPaginator.PageSize = new Size(width, height);
            _flowDocumentPaginator.ComputePageCount();
            TotalPages = _flowDocumentPaginator.PageCount;

            Range = range;
        }
Example #8
0
 Equals(
     PageRange pageRange
     )
 {
     return (pageRange.PageFrom == this.PageFrom) && (pageRange.PageTo == this.PageTo);
 }
Example #9
0
 Equals(
     PageRange pageRange
     )
 {
     return((pageRange.PageFrom == this.PageFrom) && (pageRange.PageTo == this.PageTo));
 }
			/// <summary>
			/// Get various settings
			/// </summary>
			/// <param name="nativeBuffer"></param>
			/// <param name="printerName"></param>
			/// <param name="flags"></param>
			/// <param name="pageRange"></param>
			/// <param name="dModeHnd"></param>
			void GetSettings(IntPtr nativeBuffer, out string printerName, out uint flags, out PageRange pageRange, out IntPtr dModeHnd)
			{
				IntPtr dNames = IntPtr.Zero;
				IntPtr pRanges = IntPtr.Zero;

				if (Is64Bits())
				{
					NativeMethods.PRINTDLGEX64 dlg = (NativeMethods.PRINTDLGEX64)Marshal.PtrToStructure(nativeBuffer, typeof(NativeMethods.PRINTDLGEX64));
					dModeHnd = dlg.hDevMode;
					dNames = dlg.hDevNames;
					flags = dlg.Flags;
					pRanges = dlg.lpPageRanges;
				}
				else
				{
					NativeMethods.PRINTDLGEX32 dlg = (NativeMethods.PRINTDLGEX32)Marshal.PtrToStructure(nativeBuffer, typeof(NativeMethods.PRINTDLGEX32));
					dModeHnd = dlg.hDevMode;
					dNames = dlg.hDevNames;
					flags = dlg.Flags;
					pRanges = dlg.lpPageRanges;
				}

				if (((flags & 2) == 2) && (pRanges != IntPtr.Zero))
				{
					NativeMethods.PRINTPAGERANGE printRange = (NativeMethods.PRINTPAGERANGE)Marshal.PtrToStructure(pRanges, typeof(NativeMethods.PRINTPAGERANGE));
					pageRange = new PageRange((int)printRange.nFromPage, (int)printRange.nToPage);
				}
				else
				{
					pageRange = new PageRange(1);
				}

				if (dNames != IntPtr.Zero)
				{
					IntPtr ptrDevNames = IntPtr.Zero;
					try
					{
						ptrDevNames = NativeMethods.GlobalLock(dNames);
						NativeMethods.DEVNAMES devnames = (NativeMethods.DEVNAMES)Marshal.PtrToStructure(ptrDevNames, typeof(NativeMethods.DEVNAMES));
						printerName = Marshal.PtrToStringAuto(
							(IntPtr)(((long)ptrDevNames) + (devnames.wDeviceOffset * Marshal.SystemDefaultCharSize))
							);
					}
					finally
					{
						if (ptrDevNames != IntPtr.Zero)
							NativeMethods.GlobalUnlock(dNames);
					}
				}
				else
				{
					printerName = string.Empty;
				}
			}
		/// <summary>
		/// Show Dialog to allow user to adjust printer/settings
		/// </summary>
		/// <param name="hwnd">Window owner</param>
		/// <returns>True is user was ready to print</returns>
		public bool ShowDialog(IntPtr hwnd)
		{
			NativePrintDialog dlg = new NativePrintDialog()
			{
				PrintTicket = mPrintTicket,
				PrintQueue = mPrintQueue,
				MinPage = MinPage,
				MaxPage = MaxPage,
				PageRangeEnabled = UserPageRangeEnabled,
				PageRange = new PageRange(Math.Max(1, mPageRange.PageFrom), mPageRange.PageTo),
				PageRangeSelection = mPageRangeSelection
			};

			uint result = dlg.ShowDialog(hwnd);
			if (result == 1 || result == 2)
			{
				mPrintQueue = dlg.PrintQueue;
				mPrintTicket = dlg.PrintTicket;
				mPageRange = dlg.PageRange;
				mPageRangeSelection = dlg.PageRangeSelection;
			}

			return (result == 1);
		}