PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Jul 18, 2024 3:23 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Mon Sep 12, 2011 1:16 pm 
Offline

Joined: Mon Sep 12, 2011 1:09 pm
Posts: 23
Could you please tell me how to show page number in the pdf document while creating it on the fly ?


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 12, 2011 2:15 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
With MigraDoc you add page numbers using AddPageField().
See also:
viewtopic.php?p=611#p611

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 13, 2011 2:37 pm 
Offline

Joined: Mon Sep 12, 2011 1:09 pm
Posts: 23
Thanks for your information.

Actully i am using the below code for creating PDF document.

PdfSharp.Pdf.PdfDocument document = PdfSharp.Pdf.PdfDocument();
document.Save(stream, false);

So please help me to insert page number in this context.


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 13, 2011 3:05 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
With PDFsharp you draw the page numbers like you draw any text: using DrawString or other text functions.

The samples Two Pages on One and Concatenate Documents draw page numbers.

PDFsharp samples:
http://www.pdfsharp.net/wiki/PDFsharpSamples.ashx

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 19, 2011 12:38 pm 
Offline

Joined: Mon Sep 12, 2011 1:09 pm
Posts: 23
Hi,

It does not work for me.

I am using the below code for generating the pdf document.

Code:
 public void Draw(PdfDocument doc)
    {
      XGraphics gfx = XGraphics.FromPdfPage(doc.AddPage());
      foreach (DrawBase item in Items) {
        try {

          //Start New Page if PageBreak
          if (item.GetType() == typeof(PageBreak)) {
            if (item.IsConditionTrue())
              gfx = XGraphics.FromPdfPage(doc.AddPage());
          }
         
          //Skip remaining page(s)
          else if (item.GetType() == typeof(Skip)) {
            if (item.IsConditionTrue())
              break; //skip rest of document
          }
          //This will draw
          else if (item.IsConditionTrue()) {
            item.Draw(gfx);
          }
         
        }
        catch (Exception ex) { Debug.Write("Unable to DRAW object: (" + ex.StackTrace + ")" + GetXml(item)); }
      }
    }

But i tried to use AddPageField() which you have mentioned in very first reply.But i cant see that method for any of the classes.
Even i tried to find out the classs FormattedText & paragraph like your first sample but such classes seems to be not exists in my code.
Please help me to insert page numbers in this above code.


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 19, 2011 1:01 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Vadivelan wrote:
But i tried to use AddPageField() which you have mentioned in very first reply.But i cant see that method for any of the classes.
Even i tried to find out the classs FormattedText & paragraph like your first sample but such classes seems to be not exists in my code.
In my first reply I was referring to MigraDoc. These are MigraDoc function available if you use MigraDoc.

In my second reply I was referring to some samples that do the trick with PDFsharp only (without MigraDoc) after you indicated that you don't use MigraDoc.
You only have to call "gfx.DrawString" to draw the page number.
See also:
http://www.pdfsharp.net/wiki/TwoPagesOnOne-sample.ashx

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 19, 2011 2:59 pm 
Offline

Joined: Mon Sep 12, 2011 1:09 pm
Posts: 23
It is working now and able to show page numbers.

Thanks for your support.

Regards
Vadivelan.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 43 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