11using Syncfusion . Pdf ;
22using Syncfusion . Pdf . Graphics ;
3+ using Syncfusion . Drawing ;
34
4- //Create a new document.
5- PdfDocument document = new PdfDocument ( ) ;
6- //Add the section.
7- PdfSection section = document . Sections . Add ( ) ;
8- //Set the font.
9- PdfFont font = new PdfStandardFont ( PdfFontFamily . Helvetica , 12 ) ;
10- //Create section page number field.
11- PdfSectionPageNumberField sectionPageNumber = new PdfSectionPageNumberField ( ) ;
12- //Set the page number style as LowerRoman
13- sectionPageNumber . NumberStyle = PdfNumberStyle . LowerRoman ;
14- sectionPageNumber . Font = font ;
15- //Draw the sectionPageNumber in section.
16- for ( int i = 0 ; i < 3 ; i ++ )
5+ class Program
176{
18- PdfPage page = section . Pages . Add ( ) ;
19- sectionPageNumber . Draw ( page . Graphics ) ;
20- page . Graphics . DrawString ( "This code is a practical example of how to automatically add Roman numeral page numbers" , font , PdfBrushes . Black , new Syncfusion . Drawing . PointF ( 10 , 0 ) ) ;
21- }
22- //Create file stream.
23- using ( FileStream outputFileStream = new FileStream ( Path . GetFullPath ( @"Output/Output.pdf" ) , FileMode . Create , FileAccess . ReadWrite ) )
24- {
25- //Save the PDF document to file stream.
26- document . Save ( outputFileStream ) ;
27- }
28- //Close the document.
29- document . Close ( true ) ;
7+ static void Main ( string [ ] args )
8+ {
9+ //Create a new document.
10+ PdfDocument document = new PdfDocument ( ) ;
11+
12+ //Add a section to the document.
13+ PdfSection section = document . Sections . Add ( ) ;
14+
15+ //Set the font for the page number.
16+ PdfFont font = new PdfStandardFont ( PdfFontFamily . Helvetica , 12 ) ;
17+
18+ //Create a section page number field.
19+ PdfSectionPageNumberField sectionPageNumber = new PdfSectionPageNumberField ( ) ;
20+
21+ //Set the page number style to LowerRoman (i, ii, iii, etc.).
22+ sectionPageNumber . NumberStyle = PdfNumberStyle . LowerRoman ;
23+ sectionPageNumber . Font = font ;
24+
25+ //Add pages to the section and draw the page number field in the footer.
26+ for ( int i = 0 ; i < 3 ; i ++ )
27+ {
28+ //Add a new page to the section.
29+ PdfPage page = section . Pages . Add ( ) ;
30+
31+ //Get the page's client size to calculate the footer position.
32+ SizeF pageSize = page . GetClientSize ( ) ;
33+
34+ //Define the position for the page number in the footer (bottom-right).
35+ PointF footerPosition = new PointF ( pageSize . Width - 50 , pageSize . Height - 20 ) ;
36+
37+ //Draw the section page number at the calculated footer position.
38+ sectionPageNumber . Draw ( page . Graphics , footerPosition ) ;
39+
40+ // You can add other content to the main body of the page here.
41+ // For example, let's draw text at the top, leaving space for the footer.
42+ page . Graphics . DrawString ( "This is the main content of a page with a footer." , font , PdfBrushes . Black , new PointF ( 10 , 10 ) ) ;
43+ }
44+
45+ //Create file stream.
46+ using ( FileStream outputFileStream = new FileStream ( Path . GetFullPath ( @"Output/Output.pdf" ) , FileMode . Create , FileAccess . ReadWrite ) )
47+ {
48+ //Save the PDF document to file stream.
49+ document . Save ( outputFileStream ) ;
50+ }
51+
52+ //Close the document.
53+ document . Close ( true ) ;
54+ }
55+ }
0 commit comments