Entschuldigung für mein Englisch, Ich habe Code, der ein Dokument erstellt. Im ersten Drittel befindet sich das Rechteck mit dem Text, der den Header darstellt. Mein Code:Itextpdf Dokument mit Text, Rechtecke und Tabellen
private void createGPDFbutton_Click(object sender, EventArgs e)
{
string PDFcesta = AppDomain.CurrentDomain.BaseDirectory;
Document gdoc = new Document(iTextSharp.text.PageSize.A4, 42, 10, 42, 35);
//***** definice fontů *****
//Nastavení fontu, aby to tisklo řádně česky
string ARIALUNI_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");
string CONSOLA_TTF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "consola.ttf");
string COUR_TTF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "cour.ttf");
string COURBD_TTF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "courbd.ttf"); // courier tučné
string TIMES_TTF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "times.ttf");
string TIMESBD_TTF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "timesbd.ttf"); // courier tučné
//Create a base font object making sure to specify IDENTITY-H
BaseFont BF_ARIAL = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
BaseFont BF_CONSOLAS = BaseFont.CreateFont(CONSOLA_TTF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
BaseFont BF_COURIER = BaseFont.CreateFont(COUR_TTF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
BaseFont BF_COURIER_BOLD = BaseFont.CreateFont(COURBD_TTF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
BaseFont BF_TIMES = BaseFont.CreateFont(TIMES_TTF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
BaseFont BF_TIMES_BOLD = BaseFont.CreateFont(TIMESBD_TTF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
//Create a specific font object
iTextSharp.text.Font f = new iTextSharp.text.Font(BF_ARIAL, 12, iTextSharp.text.Font.NORMAL);
iTextSharp.text.Font f1 = new iTextSharp.text.Font(BF_CONSOLAS, 10, iTextSharp.text.Font.NORMAL);
//***** konec fontů *****
try
{
PdfWriter gwriter = PdfWriter.GetInstance(gdoc, new FileStream(PDFcesta + "graphicsPDF.pdf", FileMode.Create));
gdoc.Open();
PdfContentByte cb = gwriter.DirectContent;
cb.SaveState(); // uložení aktuálního nastavení grafiky
cb.SetColorStroke(new BaseColor(0,0,0));
cb.SetColorFill(new BaseColor(255,192,203));
cb.SetLineWidth(1.5f);
// Bottom left coordinates x & y, followed by width, height and radius of corners.
cb.RoundRectangle(48f, 600f, 495.833f, 192.4f, 5f);
cb.FillStroke();
cb.SetLineWidth(0.5f);
cb.Rectangle((gdoc.PageSize.Width/2) - 35f, 630f,70f,10f);
cb.Stroke();
cb.Rectangle((gdoc.PageSize.Width/2) - 35f, 640f, 70f, 10f);
cb.Stroke();
//zápis textu
cb.BeginText();
cb.SetColorFill(BaseColor.BLACK);
cb.SetFontAndSize(BF_TIMES_BOLD, 15f);
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "VÝKAZ", gdoc.PageSize.Width/2, 753f, 0);
cb.SetFontAndSize(BF_TIMES_BOLD, 15f);
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "ZISKU A ZTRÁTY", gdoc.PageSize.Width/2, 733f, 0);
cb.SetFontAndSize(BF_TIMES_BOLD, 5f);
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "v plném rozsahu", gdoc.PageSize.Width/2, 713f, 0);
cb.SetFontAndSize(BF_TIMES_BOLD, 12f);
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "31.12.2015", gdoc.PageSize.Width/2, 683f, 0);
cb.SetFontAndSize(BF_TIMES_BOLD, 7f);
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "v tisících Kč", gdoc.PageSize.Width/2, 663f, 0);
cb.SetFontAndSize(BF_TIMES, 5f);
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "IČO", gdoc.PageSize.Width/2, 643f, 0);
cb.SetFontAndSize(BF_TIMES_BOLD, 5f);
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "00020711", gdoc.PageSize.Width/2, 633f, 0);
cb.EndText();
//konec textu
cb.RestoreState(); // obnovení původního nastavení grafiky
// tabulka
// konec tabulky
gdoc.Close();
System.Diagnostics.Process.Start(PDFcesta + "graphicsPDF.pdf");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Ich brauche die Tabelle nach diesem Rechteck einzufügen. Zwischen den Kommentaren
// tabulka
// konec tabulky
Wie löst man das?
Gibt es einen Grund, warum Sie den gesamten Text an absoluten Positionen hinzufügen anstatt 'document.add()' oder 'ColumnText' zu verwenden? Ihr Code sieht komplexer aus als benötigt. –