Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4323654
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:01:49+00:00 2026-05-21T09:01:49+00:00

I have a FlowDocument that varies in height due to an ItemsControl in a

  • 0

I have a FlowDocument that varies in height due to an ItemsControl in a BlockUIContainer. In some cases, the ItemsControl extends beyond the page height. Is there a way to scale the FlowDocument to fit a page (8.5″ X 11″) right before printing if needed?

As of right now, the FlowDocument is named ‘doc’ and the method for printing I am using is:

private void Print_Click(object sender, RoutedEventArgs e)
    {

        PrintDialog pd = new PrintDialog();
        doc.PageHeight = pd.PrintableAreaHeight;
        doc.PageWidth = pd.PrintableAreaWidth;
        doc.ColumnGap = 0;
        doc.ColumnWidth = pd.PrintableAreaWidth;
        IDocumentPaginatorSource dps = doc;
        pd.PrintDocument(dps.DocumentPaginator, "Sheet");
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:01:50+00:00Added an answer on May 21, 2026 at 9:01 am

    I know it’s a bit late, but here is the solution I came up with.

    First, we create a wrapper that will generate the document pages for us. Each page will have a scale transformation applied to it before returning it.

    public class FittedDocumentPaginator : DocumentPaginator
    {
        public DocumentPaginator Base { get; private set; }
        public double Scale { get; private set; }
        private readonly ScaleTransform _sTransform;
    
        public FittedDocumentPaginator( DocumentPaginator baseDp, double scale )
        {
            if ( baseDp == null )
                throw new ArgumentNullException( "baseDp" );
    
            Base = baseDp;
            Scale = scale;
            _sTransform = new ScaleTransform( scale, scale );
        }
    
        public override DocumentPage GetPage( int pageNumber )
        {
            var page = Base.GetPage( pageNumber );
            ( (ContainerVisual)page.Visual ).Transform = _sTransform;
    
            return page;
        }
    
        public override bool IsPageCountValid
        {
            get { return Base.IsPageCountValid; }
        }
    
        public override int PageCount
        {
            get { return Base.PageCount; }
        }
    
        public override Size PageSize
        {
            get { return Base.PageSize; }
            set { Base.PageSize = value; }
        }
    
        public override IDocumentPaginatorSource Source
        {
            get { return Base.Source; }
        }
    }
    

    Using it is fairly simple:

        private void PrintDocument( PrintDialog pd, FlowDocument document, double scale, string title )
        {
            DocumentPaginator dp = ( (IDocumentPaginatorSource)document ).DocumentPaginator;
            FittedDocumentPaginator fdp = new FittedDocumentPaginator( dp, scale );
    
            pd.PrintDocument( fdp, title );
        }
    

    If you’re interested, here is how we determined the scale. In our case, the document was extended past the page width, but it can easily be modified to accommodate the page height.

        private void Print( FlowDocument document, string title, double documentWidth )
        {
            var pd = new PrintDialog();
    
            if ( pd.ShowDialog() == true )
            {
                // Set the printing margins.
                Thickness pageMargins = document.PagePadding;
                document.PagePadding = new Thickness( 15.0 );
    
                // In our case, the document's width is NaN so we have to navigate the visual tree to get the ActualWidth, which is represented by 'documentWidth'.
                double scale = documentWidth / pd.PrintableAreaWidth;
    
                if ( scale < 1.0 )
                {
                    // The report fits on the page just fine. Don't scale.
                    scale = 1.0;
                }
    
                double invScale = 1 / scale;
    
                document.PageHeight = pd.PrintableAreaHeight * scale;
                document.PageWidth = pd.PrintableAreaWidth * scale;
    
                DocumentPaginator dp = ( (IDocumentPaginatorSource)document ).DocumentPaginator;
                FittedDocumentPaginator fdp = new FittedDocumentPaginator( dp, invScale );
    
                pd.PrintDocument( fdp, title );
    
                // Restore the original values so the GUI isn't altered.
                document.PageHeight = Double.NaN;
                document.PageWidth = Double.NaN;
                document.PagePadding = pageMargins;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data that I want to present in a FlowDocument . This
Is there any way to embed a custom control into the flowdocument and have
Question How do you print a FlowDocument that have BlockUIContainer ? How can I
I have a FlowDocument that contains lists with a header: Header 1 - Item
Here is my scenario: I have a document, currently a FlowDocument, that I would
I have a FlowDocument that is defined in XAML like this; <FlowDocumentScrollViewer> <FlowDocument> <Paragraph>
I have a flowdocument in WPF that looks like this: <FlowDocument xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml> <Paragraph
I have a FlowDocument that I want to convert to an XPS Document and
I'm using the RichTextBox to display some readonly text that I have to markup
I have a RichTextBox displaying a FlowDocument that is large (>10k lines). I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.