PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index PDFsharp - moved to http://forum.pdfsharp.net/
Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Adding page to a document

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/
View previous topic :: View next topic  
Author Message
pbturner



Joined: 30 Oct 2007
Posts: 12

PostPosted: Tue Jan 15, 2008 7:52 pm    Post subject: Adding page to a document Reply with quote

used one of the samples (the one which puts text & graphics on a document and then launches the previewer) to create an application which creates text/graphic documents on the fly. basic premise (for my reports so far) is...

renderer = new Renderer();
form.RenderEvent = new PagePreview.RenderEvent(renderer.RenderRoomQA);

// next, display the preview
form.MakePdf();

RendererRoomQA is a method (one of several in my application) that uses gfx.<methods> to draw text/graphics to a "canvas".

initially had the previewer come up as part of the process, but had problems controlling it (I think), so i went straight to the PDF viewer after doing the render.

so far, i've been lucky and all the reports have been only 1 page. now i have a table that has the potential to go to multiple pages. have updated the RendererRoomQA function to determine if i'm at the end of the page, but don't know how to add a page. is it possible at this level? if so, how. if not, is there an example of how to do this (eg. am i doing this incorrectly)?

Thanks,

pete turner.
Back to top
View user's profile Send private message
Thomas Hoevel



Joined: 16 Oct 2006
Posts: 387
Location: Cologne, Germany

PostPosted: Wed Jan 16, 2008 9:14 am    Post subject: Reply with quote

The PageSizes sample shows how to add several pages.
Pass the Document to the drawing routine so it can add pages as needed or pass the current page number to the drawing routine and use a result that indicates if further pages are needed (create a new page and call the drawing routine again).
_________________
Regards
Thomas Hoevel
PDFsharp Team
Back to top
View user's profile Send private message Visit poster's website
pbturner



Joined: 30 Oct 2007
Posts: 12

PostPosted: Wed Jan 16, 2008 2:34 pm    Post subject: Reply with quote

thanks for the update.

i looked at this example when i was starting, but, since i was initally required to do a preview, i chose the graphics sample, which displayed a preview form.

at the top of my Form1 "class", i do a "new PreviewForm", which is outside of the Renderer class. my test app has a bunch of buttons on Form1, each of which does the 3 steps mentioned previously (new Renderer, RenderEvent, and MakePdf). the document is actually "created" in the MakePdf method, then, the renderer is re-called inside of the MakePdf method (very similar to the way the original graphics application worked).

i'm very new to C#, but very versed in C/C++, so, if these questions seem "dumb", please excuse me. is passing in the form the same as passing in the document (to the render "function")?

i mentioned this "situation" to our project manager, and, he's ok with the idea that the initial release of the application might only have 1 page of this report (and another i've got to do), so, "we" have some time.

i might have to re-consider how these 2 methods build their documents - using a Document, instead of a PreviewForm. is this the way to go? is it that simple (replacing PreviewForm with Document)?

thanks for your support.

pete.
Back to top
View user's profile Send private message
Thomas Hoevel



Joined: 16 Oct 2006
Posts: 387
Location: Cologne, Germany

PostPosted: Wed Jan 16, 2008 3:51 pm    Post subject: Reply with quote

Sorry, I was on the wrong track ...

Inside "void MakePdf()" you have "PdfPage page = document.AddPage();"; this can be called inside a loop if more pages are needed.

In "void PrintPage" there is "ev.HasMorePages = false;"; set true if you need more pages.

A "sample" of a preview with several pages can be seen in class "DocumentPreview" (namespace "MigraDoc.Rendering.Forms").

You need the PageCount, have to keep the "current page" and you need a RenderPage that can render individual pages.

There are 2 ways you can go: either add multi-page support to PreviewForm (like it's done in DocumentPreview) or strip the MigraDoc stuff (DDL, Renderer) from DocumentPreview.
_________________
Regards
Thomas Hoevel
PDFsharp Team
Back to top
View user's profile Send private message Visit poster's website
pbturner



Joined: 30 Oct 2007
Posts: 12

PostPosted: Wed Jan 16, 2008 4:39 pm    Post subject: Reply with quote

thanks for the update - very informative, and getting much closer to what i "think" i need.

my problem is that i don't know how many pages i'm going to need until i actually start the rendering, unless i'm going about this the wrong way. the data that's going into the report is variable length, so, each "record" could be multiple lines on the report. in my current "scheme", when i'm rendering, i check to see if there is enough room left on the page for what i'm trying to "print". if so, then i "print" (draw) the line(s). if not, then i'm going to need a new page. remember, the current implementation is based on the Graphics sample, so it creates a PreviewForm, but goes directly to the MakePdf method, "passing" the gfx into the renderer. it would be nice, if possible, to be able to do the AddPage inside the renderer. again, being a C# newbie, i'm not sure how to get the "handle" of the document into the renderer.

since i'm going right into the MakePdf, i don't go "thru" the PrintPage method of the PreviewForm. my "preview" is the actual display of the PDF. again, maybe i'm taking the wrong approach for a multiple page document. might have to investigate doing it "differently" (like DocumentPreview, or MigraDoc) for these multipage, tabular reports.

thanks,

pete.
Back to top
View user's profile Send private message
pbturner



Joined: 30 Oct 2007
Posts: 12

PostPosted: Thu Jan 17, 2008 5:37 pm    Post subject: Reply with quote

found an interesting solution. not sure if it's the best, but, based on my current application, it works.

1) make the document a "public" variable in the PreviewForm class (right under the page worth of private System...

public PdfDocument document;

2) comment out the document creation in the MakePdf method

3) in the renderer event/callback, after determining you need a new page, do the following:

// create a new page
PdfPage page = gfx.PdfPage.Owner.AddPage();
page.Size = PageSize.A4;
gfx = XGraphics.FromPdfPage(page);

Works like a charm - now have a PDF file with 6 pages.

Thanks for your support!!!

pete.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/ All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own YouTube Clone

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com