Does SaveAsPDF support page numbers?
Closed this issue ยท 5 comments
Wasn't able to find it in the documentation.
If no, is this a feature you would like help on?
Hi, what do you mean? Just adding a number at the bottom of each page?
You could achieve this with a simple for loop:
Document doc = ...
Font fnt = ...
double bottomMargin = ...
for (int i = 0; i < doc.Pages.Count; i++)
{
doc.Pages[i].Graphics.FillText(pag.Width * 0.5 - fnt.MeasureText((i + 1).ToString()).Width * 0.5, pag.Height - bottomMargin, (i + 1).ToString(), fnt, Colours.Black, TextBaselines.Bottom);
}
I'm not sure if it's worth adding a method just to do it... In any case, I think the best place would be as an instance method on the Page
class, which takes the page number as an argument, with another instance method on the Document
class that calls it on all the pages.
Oh, so there is a one to one translation from VectorSharps "Page" object and the resulting PDFs pages.
I guess that does make it straight forward.
Does the library handle any sort of auto page breaking? Let's say I'm adding graphics components to a Page.Graphics object in a loop. When the offset exceeds the page size will VectorSharp add another page, or does the user need to handle that when building up a large document?
The base VectSharp library just provides you with a plain drawing surface; if you draw anything outside the bounds of the Page
, the additional content will just be clipped out.
If you need some kind of document layouting, you can use VectSharp.Markdown to Markdown code to a Document
object containing pages of a fixed size. You can then access the Document.Pages
and do things with them (e.g., adding page numbers or drawing additional graphics on them).
Otherwise, you will have to "manually" compare the offset and the page size, and then create a new Page
object (and add it to the Document
) as necessary.
Understood thank you.
Perfect, I'm closing this issue for now, feel free to reopen it or to create a new one if you have more questions!