Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.
Thu May 28, 2020 12:48 pm
How is this intended to be implemented?
- Code: Select all
PdfGrid headerGrid = new PdfGrid();
headerGrid.Columns.Add(3);
var hRow1 = headerGrid.Rows.Add();
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Impact", 10f), true);
PdfPageNumberField number = new PdfPageNumberField();
PdfPageCountField count = new PdfPageCountField();
PdfCompositeField compositeField = new PdfCompositeField(font, PdfBrushes.Gray, "Page {0} of {1}", number, count);
compositeField.StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Top);
hRow1.Cells[2].Value = compositeField; // <- does not work... i don't want to use compositeField.Draw(...)
My goal is to use a grid in a header template and besides text and images, i want to add pagination in one of the cells.
-

olivborc
-
- Posts: 2
- Joined: Thu May 28, 2020 10:04 am
Fri May 29, 2020 9:19 am
Hi,
Thanks for your inquiry.
Kindly note that "compositeField" object must be drawn on PDF pages. You only can assign a string value for "hRow1.Cells [2] .Value". As for your situation, you can refer to the following sample code to draw the field in grid cell. The attament is my testing result. If there is still any issue, please provide us with your full testing code as well as your desired effect of output to help further look into it. You can upload here or send them to us via email(
[email protected]).
- Code: Select all
PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();
PdfPageTemplateElement headerTemplate = new PdfPageTemplateElement(page.ActualSize.Width, 200);
doc.Template.Top = headerTemplate;
//add grid
PdfGrid headerGrid = new PdfGrid();
headerGrid.Columns.Add(3);
var hRow1 = headerGrid.Rows.Add();
hRow1.Height = 50f;
float gridX = 0;
float gridY = 30;
//field for page number
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Impact", 10f), true);
PdfPageNumberField number = new PdfPageNumberField();
PdfPageCountField count = new PdfPageCountField();
PdfCompositeField compositeField = new PdfCompositeField(font, PdfBrushes.Gray, "Page {0} of {1}", number, count);
compositeField.StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Top);
//draw grid on page
headerGrid.Draw(page, new PointF(gridX, gridY));
//draw field on page
float width = headerGrid.Columns[0].Width + headerGrid.Columns[1].Width + headerGrid.Columns[2].Width / 3;
float height = gridY + hRow1.Height / 3;
compositeField.Draw(headerTemplate.Graphics, width, height);
//save
doc.SaveToFile("result.pdf");
Sincerely,
Sara
E-iceblue support team
Login to view the files attached to this post.
-


Sara.Yang
-
- Posts: 33
- Joined: Wed May 06, 2020 1:05 am
Fri May 29, 2020 10:09 am
Hi Sara,
thank you for looking into this, i appreciate it. I was hoping for a little more convenient way to use this.
-

olivborc
-
- Posts: 2
- Joined: Thu May 28, 2020 10:04 am
Mon Jun 01, 2020 1:47 am
Hi,
Thanks for your inquiry.
Sorry, I am afraid there is no convenient way at present. If you have any other questions, just feel free to contact us.
Sincerely,
Sara
E-iceblue support team
-


Sara.Yang
-
- Posts: 33
- Joined: Wed May 06, 2020 1:05 am