아래 코드에서 기존 텍스트 위에 텍스트 레이어를 배치하려고합니다 (기존의 기존 텍스트는 흰색 글꼴로 작성하여 "숨김"이며이 대체 프로세스의 자리 표시 자 역할을합니다).). 아래의 코드는이 게시물에 크리스 하스에서 제공하는 코드에 매우 크게 의존 :iTextSharp - 텍스트 덮어 쓰기
하지만, 내 텍스트 배치에 대해 "왼쪽"위치는 괜찮지 만은 "바닥"텍스트보다 낮은 덮어 쓰기를 시도하고 있습니다 (글꼴이 같더라도). 원본 문서에있는 텍스트의 정확한 좌표를 얻기 위해 이것을 어떻게 변경할 수 있습니까? 원본 문서는 레이아웃 용 테이블을 사용하여 작성되었으므로이 "덮어 쓰기"프로세스에 영향을 줍니까?
byte[] content;
string tmppath = @"C:\Junk\MSE_1.pdf";
using (MemoryStream output = new MemoryStream())
{
PdfReader pdf_rdr = new PdfReader(tmppath);
PdfStamper stamper = new PdfStamper(pdf_rdr, output);
for (int i = 1; i < pdf_rdr.NumberOfPages; i++)
{
//Create an instance of our strategy
var t = new MyLocationTextExtractionStrategy("stuff");
if (t != null)
{
//Parse the page of the document above
//(if the text was found)
var ex = PdfTextExtractor.GetTextFromPage(pdf_rdr, i, t);
//Loop through each chunk found
foreach (var p in t.myPoints)
{
Console.WriteLine(string.Format("Found text {0} at {1} x {2} on page {3}", p.Text, p.Rect.Left, p.Rect.Bottom, i.ToString()));
PdfContentByte pcb = stamper.GetOverContent(i);
pcb.BeginText();
try
{
BaseFont bf = BaseFont.CreateFont(@"C:\Junk\FontFiles\georgia.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
pcb.SetFontAndSize(bf, 10);
pcb.SetTextMatrix(p.Rect.Left, p.Rect.Bottom);
//pcb.SetTextRise(3);
pcb.ShowText("STUFF");
}
finally
{
pcb.EndText();
}
}
}
}
// Set the flattening flag to true, as the editing is done
stamper.FormFlattening = true;
// close the pdf stamper
stamper.Close();
//close the PDF reader
pdf_rdr.Close();
//put the output into the byte array
content = output.ToArray();
}
//write the content to a PDF file
using (FileStream fs = File.Create(@"C:\Junk\MSE_REPLACED.pdf"))
{
fs.Write(content, 0, (int)content.Length);
fs.Flush();
}
나는베이스 라인 작업에 익숙하지 않다. 공유 할 수있는 예제가 있습니까? – cro717
그것은 매력처럼 작동했습니다! 당신의 도움을 주셔서 대단히 감사합니다! – cro717