Wie platziere ich Text an einer bestimmten Position auf der PDF-Datei? Ich habe ein wenig gesucht, aber nichts zu gut gefunden. Ich habe document.Add(new Paragraph("Date:" + DateTime.Now));
und ich wollte das auf einen bestimmten Bereich in der PDF-Datei platzieren.So platzieren Sie Absätze mit iTextSharp an einem bestimmten Ort
Mein Code:
private void savePDF_Click(object sender, EventArgs e)
{
FileStream fileStream = new FileStream(nameTxtB.Text + "Repair.pdf", FileMode.Create, FileAccess.Write, FileShare.None);
Document document = new Document();
document.Open();
iTextSharp.text.Rectangle rectangle = new iTextSharp.text.Rectangle(PageSize.LETTER);
PdfWriter pdfWriter = PdfWriter.GetInstance(document, fileStream);
iTextSharp.text.Image r3tsLogo = iTextSharp.text.Image.GetInstance("rt3slogo.PNG"); //creates r3ts logo
iTextSharp.text.Image r3Info = iTextSharp.text.Image.GetInstance("R3 Information.PNG"); //creates r3 information text below r3ts logo
r3tsLogo.SetAbsolutePosition(document.PageSize.Width - 375 - 0f, document.PageSize.Height - 130 - 0f);
r3Info.SetAbsolutePosition(document.PageSize.Width - 365 - 0f, document.PageSize.Height - 170 - 0f); //higher the number in height the lower the place of text on paper
//less number will result in text more to right in width
//increase size of picture
r3tsLogo.ScalePercent(120);
r3Info.ScalePercent(65);
//---------------adds all images to pdf file ---------------------------------
document.Add(r3tsLogo);
document.Add(r3Info);
document.Add(new Paragraph("Date:" + DateTime.Now));
document.Close();
}
Ich denke, dass das Problem nicht die Positionierung Bilder, sondern Positionierung ' "Date:" + DateTime.Now)' an einer absoluten Position. Natürlich ist das auch eine Frage, die schon oft beantwortet wurde. –