2012-02-23 3 views
7

iTextSharp 4.2.0을 사용하여 159x159 포인트의 크기로 이미지의 크기를 조정할 수 있기를 원하지만 이미지의 크기가 정확하게 지정되어야합니다.iTextSharp : 픽스 크기에 맞게 이미지의 크기를 조정하는 방법은 무엇입니까?

나는 이것을 시도했다 :

Image image = Image.GetInstance(imagePath); 
image.ScaleAbsolute(159f, 159f); 

그러나 이미지가 사각형이 아닙니다. 가로 세로 비율을 유지합니다.

예 :이 loke 보일 것

enter image description here

그리고 결과 이미지 :

enter image description here

감사 나는이 이미지를 가지고있다.

답변

29

당신이 설명하는 문제는 당신이 시도하고 항상PdfPCell에 맞게 이미지 크기를 조정 AddCell()를 호출하여 PdfPTable에 직접 Image를 추가 할 때 발생하는 일반적입니다. 이 같은 Document에 이미지를 추가하는 경우 그래서 :

Image img = Image.GetInstance(imagePath); 
img.ScaleAbsolute(159f, 159f); 
PdfPTable table = new PdfPTable(1); 
table.AddCell(img); 
document.Add(table); 

당신의 ScaleAbsolute() 호출이 무시됩니다. 당신이 원하는 확장으로 활용하려면 다음

PdfPTable table = new PdfPTable(1); 
table.AddCell(new PdfPCell(img)); 
document.Add(table); 
+0

이것은 매우 유용한 답변입니다. 감사. – Emanuel

+0

정말 유용합니다 .. 감사. –

+1

'new PdfPCell(). setImage (img)'로 이미지를 추가하지 않도록 조심하십시오.이 이미지는 셀의 배경으로 추가되며 자동으로 셀의 너비와 높이에 맞게 조절됩니다. –

0

PdfPCell 그래서 그냥 true로 설정 셀의 이미지에 맞게 속성이 있습니다.

iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance("/test.png"); 

    PdfPCell logocell = new PdfPCell(logo,true); // **PdfPCell(Image,Boolean Fit)** 
관련 문제