PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

How to show page number in PDF document ?
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1780
Page 1 of 1

Author:  Vadivelan [ Mon Sep 12, 2011 1:16 pm ]
Post subject:  How to show page number in PDF document ?

Could you please tell me how to show page number in the pdf document while creating it on the fly ?

Author:  Thomas Hoevel [ Mon Sep 12, 2011 2:15 pm ]
Post subject:  Re: How to show page number in PDF document ?

With MigraDoc you add page numbers using AddPageField().
See also:
viewtopic.php?p=611#p611

Author:  Vadivelan [ Tue Sep 13, 2011 2:37 pm ]
Post subject:  Re: How to show page number in PDF document ?

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.

Author:  Thomas Hoevel [ Tue Sep 13, 2011 3:05 pm ]
Post subject:  Re: How to show page number in PDF document ?

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

Author:  Vadivelan [ Mon Sep 19, 2011 12:38 pm ]
Post subject:  Re: How to show page number in PDF document ?

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.

Author:  Thomas Hoevel [ Mon Sep 19, 2011 1:01 pm ]
Post subject:  Re: How to show page number in PDF document ?

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

Author:  Vadivelan [ Mon Sep 19, 2011 2:59 pm ]
Post subject:  Re: How to show page number in PDF document ?

It is working now and able to show page numbers.

Thanks for your support.

Regards
Vadivelan.

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