2013-09-27 3 views
0

이미지가 있습니다. itextsharp를 통해 PDF를 넣습니다. ScalePercent 또는 ScaleAbsoluteWidth 또는 ScaleAbsoluteHeight를 사용할 때 아무 효과가 없습니다. 이미지가 PDF에 렌더링 될 때 이미지는 항상 페이지에서 사용할 수있는 공간을 차지합니다 (엄청나게 커집니다).itextsharp 이미지의 크기가 조정되지 않습니다 - 대부분의 페이지를 차지합니다

여기 내 코드입니다.

var chartImage = new System.IO.MemoryStream(); 
Chart1.SaveImage(chartImage, ChartImageFormat.Png); 
iTextSharp.text.Image imageForChart = iTextSharp.text.Image.GetInstance(chartImage.GetBuffer()); 

imageForChart.ScaleAbsoluteHeight(5f); 
imageForChart.ScaleAbsoluteWidth(5f); 

Dictionary<string, string> dictionary = new Dictionary<string, string>(); 
string pageTitle = "Event Recap Report"; 
dictionary.Add("Started", tbStartDate.Text); 
dictionary.Add("Ended", tbEndDate.Text); 
PDFDocument x = new PDFDocument(pageTitle, PageSize.LETTER, 15, 15, 40, 15); 

x.UserName = _currentUser.FullName; 
x.WritePageHeader(1, ref dictionary); 
x.WriteImage(ref imageForChart); 
x.WriteGrid(ref grdEventRecap); 
x.WritePageFooter(); 
x.Finish(false); 

답변

0

당신은이 같은 절대 위치 설정 시도 할 수 있습니다 :

var imageForChart = Image.GetInstance(chartImage.GetBuffer()); 
imageForChart.SetAbsolutePosition(positionX, positionY); 
image.ScaleAbsoluteHeight(5f); 
image.ScaleAbsoluteWidth(5f); 
0

희망이

string imagePath = Server.MapPath("~/Content/images"); 
iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance(imagePath + "/myimage.png"); 
png.ScaleToFit(520, 74); 
doc1.Add(png); 

사용 ScaleToFit() 귀하의 이미지 크기를 조정하는 데 도움이됩니다.

0

필자는 실제로 itextsharp 주위에 래퍼가 있음을 알게되어 당혹 스럽습니다. 래퍼의 WriteImage 메서드는 크기가 맞춰졌습니다. 내 솔루션은이 자동 크기 조정을 수행하지 않은 새로운 방법을 추가하는 것이 었습니다.

관련 문제