i'm tring to add a "header string" on the top of all pdf pages by the code below, but that partial string "<P/AA.0>" disappear from the final pdf.
Replacing '<' with '[' and '>' with ']' the pdf is generated properly. but i didn't find a good way to allow to draw < and > chars by .Canvas.DrawString method.
- Code: Select all
PdfDocument pdfDocument = new PdfDocument(File.ReadAllBytes("C:\\tmp\\origin.pdf"));
string signatureString = "<b>DGROOVE SPA/0000087/22/04/2024/I/U/Protocollo Generale<P/AA.0></b>";
string pageSignature = signatureString;
PdfFont signatureFont = new PdfFont(Spire.Pdf.Graphics.PdfFontFamily.TimesRoman, 10);
PdfBrush signatureColor = PdfBrushes.Black;
SizeF signatureMeasures = signatureFont.MeasureString(signatureString);
float effectiveSignatureLines = signatureMeasures.Width / PdfPageSize.A4.Width;
double truncatedValue = Math.Truncate(effectiveSignatureLines);
float signatureHeight = (float)((truncatedValue + ((effectiveSignatureLines - truncatedValue) > 0 ? 1 : 0)) * 20);
PdfPageBase page;
RectangleF signatureRectangle;
for (int i = 0; i < pdfDocument.Pages.Count; i++)
{
page = pdfDocument.Pages[i];
pageSignature = $"<span>{pageSignature} pagina {page.Document.Pages.IndexOf(page) + 1} di {page.Document.Pages.Count}</span>";
Console.WriteLine(pageSignature);
signatureRectangle = new RectangleF(PointF.Empty, new SizeF(page.ActualSize.Width, signatureHeight));
page.Canvas.DrawString(
s: pageSignature,
font: signatureFont,
brush: signatureColor,
layoutRectangle: signatureRectangle,
htmlTags: true);
}
pdfDocument.SaveToFile("pdf.pdf");
can you help me?
Regards
Fabrizio