PDFsharp:有没有一种方法来生成和QUOT; Y&QUOT的第X页;在页的头部? [英] PDFsharp: Is there a way to generate "Page X of Y" in the header of the page?

查看:248
本文介绍了PDFsharp:有没有一种方法来生成和QUOT; Y&QUOT的第X页;在页的头部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎很简单,但我找不到类似getPageCount()中的API中。我能得到它返回当前页面,但不是总页数。也许我错过了吗?

It seems rather simple, but I can't find something like getPageCount() in the API. I can get it to return the current page, but not the total number of pages. Perhaps I'm missing it?

我想以某种方式能够在每个页面的顶部,打印第1页,9',其中'1',当然是当前页码。

I would like to somehow be able to print 'Page 1 of 9' at the top of every page, where '1' of course is the current page number.

推荐答案

通过PDFsharp它给你。

With PDFsharp it's up to you.

我相信你正在使用MigraDoc:随着MigraDoc你可以添加一个页眉。添加 paragraph.AddPageField()当前页码和 paragraph.AddNumPagesField()总页数。

I presume you are using MigraDoc: With MigraDoc you can add a page header. Add paragraph.AddPageField() for the current page number and paragraph.AddNumPagesField() for the total page count.

使用样品AddPageField

代码从样本片段:

// Create a paragraph with centered page number. See definition of style "Footer".
Paragraph paragraph = new Paragraph();
paragraph.AddTab();
paragraph.AddPageField();

// Add paragraph to footer for odd pages.
section.Footers.Primary.Add(paragraph);
// Add clone of paragraph to footer for odd pages. Cloning is necessary because an object must
// not belong to more than one other object. If you forget cloning an exception is thrown.
section.Footers.EvenPage.Add(paragraph.Clone());

代码段,用于设置制表位(假设DIN A 4用身体为16厘米):

Code snippet that sets the tab stop (assuming DIN A 4 with a body with of 16 cm):

style = document.Styles[StyleNames.Footer]; 
style.ParagraphFormat.AddTabStop("8cm", TabAlignment.Center); 



从链接的网站,而采取的片段。示例代码也可以下载了。

Both snippets taken from the linked site. Sample code is also available for download.

这篇关于PDFsharp:有没有一种方法来生成和QUOT; Y&QUOT的第X页;在页的头部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆