I´m trying to add a text at a specifik position on top of each page in a PDF, without manipulating the actual page.
Adding a new layer seems to be the solution and this method does the job as expected, with the exception that swedish characters is not displayd correctly. I am using version 22.10 (licensed) and have tried 24.10 too.
public string Sign(string path, string filename, string text, string name)
{
var doc = new Document(Path.Combine(path, filename));
for (int i = 1; i <= doc.Pages.Count; i++)
{
var newLayer = new Layer("TopLayer", "Top Layer");
newLayer.Contents.Add(new GSave());
newLayer.Contents.Add(new SetColorSpace(ColorSpace.DeviceRGB.ToString()));
newLayer.Contents.Add(new SetCMYKColorStroke(1, 0, 0, 0));
newLayer.Contents.Add(new BT());
newLayer.Contents.Add(new SelectFont("Times New Roman", 12));
newLayer.Contents.Add(new MoveTextPosition(50, 20));
newLayer.Contents.Add(new ShowText("ÅÄÖåäö"));
newLayer.Contents.Add(new ShowText(text));
newLayer.Contents.Add(new ShowText($" {name}."));
newLayer.Contents.Add(new ShowText($" Page {i}/{doc.Pages.Count}"));
newLayer.Contents.Add(new ET());
newLayer.Contents.Add(new GRestore());
var layers = doc.Pages[i].Layers = new List<Layer>();
layers.Add(newLayer);
}
string output = Path.Combine(path, "signed_" + filename);
doc.Save(output);
return output;
}
2024-11-06 13-19.png (1.6 KB)
How do I fix this or is there a better way to solve the task?