2
텍스트가있는 페이지 PDF 파일의 가운데에 그림을 추가하고 싶지만 제대로 처리 할 수 없습니다. 이미지 SetAbsolutePosition
에 사용하지만 텍스트가 그림 아래에 있지 않습니다. 내 PDF 파일 페이지의 다음 형식으로 필요ItextSharp 페이지 아래에 텍스트가있는 페이지의 중심에 이미지를 추가하십시오.
:
PdfWriter writer = PdfWriter.GetInstance(doc, fs);
ITextEvents ev = new ITextEvents();
writer.PageEvent = ev;
doc.Open();
var paragraph = new Paragraph();
var paragraph1 = new Paragraph();
var chunk = new Chunk("Text under picture", f14nb);
var chunk1 = new Chunk("Code of picture", f14);
img = ScaleImg(Image.GetInstance(imgNane_2));
img.SetAbsolutePosition((PageSize.A4.Width - img.ScaledWidth)/2,
((PageSize.A4.Height - img.ScaledHeight)/2));
paragraph.Add(img);
paragraph1.Add(chunk);
paragraph1.Add(chunk1);
doc.Add(paragraph);
doc.Add(paragraph1);
doc.Close();
private Image ScaleImg(Image img)
{
if (img.Height > img.Width)
{
//Maximum height is 800 pixels.
float percentage = 0.0f;
percentage = 640/img.Height;
img.ScalePercent(percentage * 100);
}
else
{
//Maximum width is 600 pixels.
float percentage = 0.0f;
percentage = 500/img.Width;
img.ScalePercent(percentage * 100);
}
return img;
}
는 내가 해결을위한 다른 방법을 사용해야한다는 생각 :
나는 다음 코드를 사용 내 문제지만, 나는 어느 것을 모른다.
감사합니다.