PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

DefaultPageSetup Bug
http://forum.pdfsharp.com/viewtopic.php?f=3&t=1784
Page 1 of 1

Author:  sofoklis24 [ Wed Sep 14, 2011 9:29 am ]
Post subject:  DefaultPageSetup Bug

Hi,

I think the Document.DefaultPageSetup is not implemented properly for running it on a concurrent application where more than one reports needs to be generated at the same time.
In this scenario if you have a report that takes say 2 minutes and in that period you run a seconde report with a different PageSetup, since currently you are changing the global page setup, it will make the change the page setup of the first report. We had this problem when we are using Landscape and Portrait orientation.


I think to fix it you have to make the DefaultPageSetup a private member and a copy of the
so in PageSetup i created a new method basically to create a new PageSetup object with the default settings:
Code:
 public static PageSetup NewDefaultPageSetup()
        {
            PageSetup p = new PageSetup();
            p.PageFormat = PageFormat.A4;
            p.SectionStart = BreakType.BreakNextPage;
            p.Orientation = Orientation.Portrait;
            p.PageWidth = "21cm";
            p.PageHeight = "29.7cm";
            p.TopMargin = "2.5cm";
            p.BottomMargin = "2cm";
            p.LeftMargin = "2.5cm";
            p.RightMargin = "2.5cm";
            p.HeaderDistance = "1.25cm";
            p.FooterDistance = "1.25cm";
            p.OddAndEvenPagesHeaderFooter = false;
            p.DifferentFirstPageHeaderFooter = false;
            p.MirrorMargins = false;
            p.HorizontalPageBreak = false;
            return p;
        }

Then in document i setup the default page setup with this method:
Code:
  private PageSetup defaultPageSetup = PageSetup.NewDefaultPageSetup();


So now every document has its own private page setup

Also in VisitorBase code:
Code:
 internal override void VisitSection(Section section)
    {
      Section prevSec = section.PreviousSection();
      // Here the document defaultpagesetup is more relevant than the global PageSetup
      PageSetup prevPageSetup = section.Document.DefaultPageSetup;
      if (prevSec != null)
      {
        prevPageSetup = prevSec.pageSetup; ...



I am sure you can do better, it was just changes i made to make this work.
Thanks for the excellent library,
Sofoklis

Author:  Thomas Hoevel [ Wed Sep 14, 2011 11:37 am ]
Post subject:  Re: DefaultPageSetup Bug

sofoklis24 wrote:
I think the Document.DefaultPageSetup is not implemented properly for running it on a concurrent application where more than one reports needs to be generated at the same time.

Depends on how you use the library. Do not change the DefaultPageSetup (unless you know what you are doing).
Every document has at least one section and every section can have a PageSetup. Assign a clone of the default setup and that's all (no need to change the DefaultPageSetup).
Code:
pageSetup = this.document.DefaultPageSetup.Clone();

I've changed PDFsharp so that the Debug build checks the DefaultPageSetup for modifications (using Debug.Assert).
This way you'll get warned when you tempered the global DefaultPageSetup (yep, I also fell in that trap).

Author:  sofoklis24 [ Wed Sep 14, 2011 1:56 pm ]
Post subject:  Re: DefaultPageSetup Bug

Hi Thomas,

Point about the section is clear, but i believe there should be a second level of "DefaultPageSetup" on a document level:
1. Global DefaulPageSetup for the application, which is what we have right now.
2. Document DefaultPageSetup, so all document objects can take it from here. Having the property on the Document suggests that this is the case, but its not.

Thank you very much Thomas.

On a side node when do you plan a next release?

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/