PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Mar 29, 2024 11:45 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: DefaultPageSetup Bug
PostPosted: Wed Sep 14, 2011 9:29 am 
Offline

Joined: Mon Apr 27, 2009 12:33 pm
Posts: 7
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


Top
 Profile  
Reply with quote  
 Post subject: Re: DefaultPageSetup Bug
PostPosted: Wed Sep 14, 2011 11:37 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
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).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject: Re: DefaultPageSetup Bug
PostPosted: Wed Sep 14, 2011 1:56 pm 
Offline

Joined: Mon Apr 27, 2009 12:33 pm
Posts: 7
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?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 57 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group