मुझे पता है कि यह प्रश्न पुराना है और इसका एक स्वीकार्य उत्तर है, हालांकि पीडीएफशर्प समाधान की खोज करते समय सवाल पहली बार सामने आता है।
रिकॉर्ड के लिए, पीडीएफशर्प में इसे प्राप्त करना आसान है। PdfDocument
वर्ग, PdfSharp.Pdf
नामस्थान के अंतर्गत पाया गया पृष्ठों का संग्रह (PdfDocument.Pages
) है। आपको बस इतना करना है कि संग्रह के माध्यम से पुनरावृत्ति करें और XGraphics
ऑब्जेक्ट का उपयोग करके प्रत्येक पृष्ठ पर पेज काउंटर कहीं भी जोड़ें, ताकि आप XGraphics.FromPdfPage(PdfPage)
का उपयोग करके तुरंत चालू कर सकें।
using PdfSharp.Pdf; // PdfDocument, PdfPage
using PdfSharp.Drawing; // XGraphics, XFont, XBrush, XRect
// XStringFormats
// Create a new PdfDocument.
PdfDocument document = new PdfDocument();
// Add five pages to the document.
for(int i = 0; i < 5; ++i)
document.AddPage();
// Make a font and a brush to draw the page counter.
XFont font = new XFont("Verdana", 8);
XBrush brush = XBrushes.Black;
// Add the page counter.
string noPages = document.Pages.Count.ToString();
for(int i = 0; i < document.Pages.Count; ++i)
{
PdfPage page = document.Pages[i];
// Make a layout rectangle.
XRect layoutRectangle = new XRect(0/*X*/, page.Height-font.Height/*Y*/, page.Width/*Width*/, font.Height/*Height*/);
using (XGraphics gfx = XGraphics.FromPdfPage(page))
{
gfx.DrawString(
"Page " + (i+1).ToString() + " of " + noPages,
font,
brush,
layoutRectangle,
XStringFormats.Center);
}
}
यह ध्यान देने योग्य है कि यदि एक XGraphics वस्तु पहले से ही दिए गए पृष्ठ के लिए मौजूद है, एक नया बनाने से पहले, एक पुरानी निपटारा किए जाने की जरूरत के लायक है। यह असफल हो जाएगा:
PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
XGraphics gfx1 = XGraphics.FromPage(page);
XGraphics gfx2 = XGraphics.FromPage(page);
क्या आप कुछ कोड कृपया दिखा सकते हैं? – sarseyn