私はitextsharp SDKを使用しています。データがあるpdfファイルがあります。ヘッダやフッタテキストを追加したいのですが、itextsharpフッターテキストを追加するが部分的に表示する(C#.NET)
私もPDFのスクリーンショットの出力を添付しましたPdfReader reader = new PdfReader("C:\Source pdf file.pdf");
string f_textPrefix = "Page No : 1";
using (MemoryStream memoryStream = new MemoryStream())
{
PdfStamper pdfStamper = new PdfStamper(reader, memoryStream);
bool flag = false;
for (int i = 1; i <= reader.NumberOfPages; i++)
{
iTextSharp.text.Rectangle pageSize = reader.GetPageSizeWithRotation(i);
PdfContentByte pdfPageContents = pdfStamper.GetOverContent(i);
pdfPageContents.BeginText();
BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD,
BaseFont.CP1252,
false);
System.Drawing.Color m_Color = new System.Drawing.Color();
pdfPageContents.SetFontAndSize(baseFont, Convert.ToInt32(p_objParam.pdfBatesDetail.FontSize));
pdfPageContents.SetRGBColorFill(m_Color.R, m_Color.G,
m_Color.B);
// this is to set the cursor tp Bottom Middle
int yPos = 0;
yPos = PDFLayout.BottomHeight;
pdfPageContents.SetTextMatrix(pageSize.Width/2, yPos);
pdfPageContents.ShowText(f_textPrefix.Trim());
pdfPageContents.EndText();
}
pdfStamper.FormFlattening = true; // enable this if you want the PDF flattened.
pdfStamper.Close(); // Always close the stamper or you'll have a 0 byte stream.
byte []bt = btmemoryStream.ToArray();
File.WriteAllBytes("C:\new_file.pdf", bt);
}
、スクリーンショットを参照してください。ページの一番最後には、ヘッダー/フッターのテキストは
サンプルコードを参照してください一部が表示されます。事前に
感謝。
PDFLayout.BottomHeight = 0 p_objParam.pdfBatesDetail.FontSize = 5.0; これらはちょうどuser_definedオブジェクトですいくつかの値は、これらの値を考慮してください –
私はあなたの問題を理解していません。 ** y **座標を選択します。あなたがそれを低く選んでテキストを切り取ったら、もっと大きな値を選ぶのはなぜですか? – mkl
ページの下部に余白を追加することはできますが、それを行うにはテンプレートを作成する必要があると思います(これは私がやったやり方です)。 – Spluf