I encountered two problems:
The first question is why the font is not changed after embedding the value into the pdf
Code:
XFont font2 = new XFont("DFKai-SB", 12, XFontStyle.Regular);
XmlDocument xml = new XmlDocument();
xml.LoadXml(nodeList.Item(i).OuterXml);
MemoryStream modifiedStream = new MemoryStream();
PdfDocument inputDocument = PdfReader.Open(new MemoryStream(pdfTemplate), PdfDocumentOpenMode.Modify);
PdfPage page = inputDocument.Pages[0];
XGraphics gfx = XGraphics.FromPdfPage(page);
// inputDocument.AddCharacters(font2);
foreach (XmlNode node in xml.DocumentElement.ChildNodes)
{
if (node is XmlElement)
{
string fieldName = string.Format("topmostSubform[0].Page1[0].{0}[0]", node.Name);
PdfTextField field = inputDocument.AcroForm.Fields[fieldName] as PdfTextField;
if (field != null)
{
field.Font = font2;
field.Value = new PdfString(node.InnerText);
}
}
}
The second question is how to set up this coordinate system? What are the units of the x-axis and y-axis? Is it (pixel)?
Code:
gfx.DrawImage(image, posx, newPosY, image.PixelWidth * 0.3, image.PixelHeight * 0.3);
After I converted the itextsharp program to pdfsharp, I found that the image position was not in the correct position.
------------
Thanks to everyone who offered to answer questions