2011-02-03 11 views
4

어떻게하면 두 개의 셀을 수직으로 정렬 할 수 있습니까? 현재 두 번째 셀은 첫 번째 셀 아래에 렌더링됩니다. 첫 번째 셀은 이미지이고 두 번째 셀은 텍스트입니다. 여기 내 코드가있다. 이미지가 테이블의 셀 (플러스 오히려 관대 한 패딩)의 최대 폭보다 넓은처럼 다음 셀이 다음 행에 나타나도록itextsharp pdfpcell 수직 정렬 문제

private Document pdoc; 
    Font font99 = FontFactory.GetFont("HELVETICA", 60); 
    PdfPTable pdfRatingTable = new PdfPTable(2); 
    PdfPCell pRatCell = null; 
    pdfRatingTable.WidthPercentage = 100; 
    pdfRatingTable.SetWidths(new int[] { 75, 25 }); 

    hImage = iTextSharp.text.Image.GetInstance(MapPath("~/Images/fyler3_Rating.jpg")); 
    NewWidth = 338; 
    MaxHeight = 18; 
    if (hImage.Width <= NewWidth) 
    { 
     NewWidth = hImage.Width; 
    } 
    NewHeight = hImage.Height * NewWidth/hImage.Width; 
    if (NewHeight > MaxHeight) 
    { 
     NewWidth = hImage.Width * MaxHeight/hImage.Height; 
     NewHeight = MaxHeight; 
    } 

    ratio = hImage.Width/hImage.Height; 
    hImage.ScaleAbsolute(NewWidth, NewHeight); 
    pRatCell = new PdfPCell(hImage); 
    pRatCell.Border = 0; 
    pRatCell.PaddingLeft = 20f; 
    pRatCell.HorizontalAlignment = Element.ALIGN_LEFT; 
    pdfRatingTable.AddCell(pRatCell); 

    pRatCell = new PdfPCell(new Phrase(new Chunk("405", font99))); 
    pRatCell.HorizontalAlignment = Element.ALIGN_LEFT; 
    pRatCell.Border = 0; 
    pRatCell2.VerticalAlignment = Element.ALIGN_TOP; 
    pdfRatingTable.AddCell(pRatCell); 
    pdoc.Add(pdfRatingTable); 

답변

1

그것은 보인다.

저는이 이미지가 더 작은 이미지 (또는 더 작은 스케일로 동일한 이미지)로 시도하여 제가 맞는지 확인할 것을 제안합니다.


또는하여

"아래에"당신은 그들이 같은 행에 모두 걸 의미 할 수 있지만, 이미지가 너무 주위에 20 점 패드 중앙에있는 동안 텍스트가 셀의 하단에 표시 텍스트가 완전히 이미지 아래에 있습니까?

IIRC이면 Paragraph은 전체 셀을 차지하지만 Chunk은 셀 수직 및 수평 정렬 설정을 따릅니다. my answer here의 주석을 참조하십시오.

+0

안녕하세요. 이미지를 약간 작게 조정했는데 오른쪽 셀이 여전히 다음 행에있는 것으로 보입니다. 심지어 나는 pRatCell = new PdfPCell (새로운 Phrase (새로운 Chunk ("This is a test")))로 이미지를 대체했습니다. 두 번째 셀은 여전히 ​​다음 행에 나타납니다. 테이블 너비가 맞습니까? – bladerunner

+1

나는 당신이 셀 경계선을 켜기 만하면 정말로 다음 줄에 있고, 훨씬 더 낮을 것 같지 않다. (나는 20pt 패드로 기대한다). –

+0

국경을 설정해 주셔서 감사합니다. 첫 번째 셀의 맨 위에 다음 패딩을 맞추기 위해 약간의 패딩이 필요했습니다. 다시 한번 감사합니다. – bladerunner