2012-04-22 10 views
5

मैं itextsharp में एक गोल आयताकार बनाना चाहता हूं। यहाँ है उत्पादन गोलाई के बिना मैं अब है:मैं iTextSharp तालिका सीमा के कोनों को कैसे घुमा सकता हूं?

enter image description here

और यहाँ मेरे कोड है कि प्रक्रियाओं है उत्पादन:

pdftbl = new PdfPTable(3); 
pdftbl.WidthPercentage = 100; 
width = new float[3]; 
width[0] = 0.6F; 
width[1] = 0.2F; 
width[2] = 0.6F; 
pdftbl.SetWidths(width); 
pdfcel = new PdfPCell(new Phrase(Insuredaddress, docFont9)); 
pdfcel.BorderColor = Color.BLACK; 
pdftbl.AddCell(pdfcel); 
pdfcel = new PdfPCell(new Phrase("", docWhiteFont9)); 
pdfcel.Border = 0; 
pdftbl.AddCell(pdfcel); 
pdfcel = new PdfPCell(new Phrase(BkrAddrss, docFont9)); 
pdfcel.BorderColor = Color.BLACK; 
pdftbl.AddCell(pdfcel); 
objDocument.Add(pdftbl); 

मैं क्या बदल सकते हैं/वांछित परिणाम प्राप्त करने के लिए जोड़?

उत्तर

7

iText [तीव्र] में यह कार्यक्षमता बॉक्स से बाहर नहीं है। यह चीजों को करने का एक चौराहे तरीका है, लेकिन सबसे पहले आपको IPdfPCellEvent इंटरफ़ेस को कार्यान्वित करना होगा, और दूसरा ईवेंट हैंडलर को प्रत्येक सेल में जोड़ देगा जिसे आप तालिका में जोड़ते हैं। सबसे पहले एक सरल कार्यान्वयन:

public class RoundRectangle : IPdfPCellEvent { 
    public void CellLayout(
    PdfPCell cell, Rectangle rect, PdfContentByte[] canvas 
) 
    { 
    PdfContentByte cb = canvas[PdfPTable.LINECANVAS]; 
    cb.RoundRectangle(
     rect.Left, 
     rect.Bottom, 
     rect.Width, 
     rect.Height, 
     4 // change to adjust how "round" corner is displayed 
    ); 
    cb.SetLineWidth(1f); 
    cb.SetCMYKColorStrokeF(0f, 0f, 0f, 1f); 
    cb.Stroke(); 
    } 
} 

PdfContentByte documentation देखें - मूल रूप से सभी कोड से ऊपर है दौर कोनों के साथ एक सेल बॉर्डर आकर्षित जैसे आप चाहते हैं।

RoundRectangle rr = new RoundRectangle();  
using (Document document = new Document()) { 
    PdfWriter writer = PdfWriter.GetInstance(document, STREAM); 
    document.Open(); 
    PdfPTable table = new PdfPTable(1); 
    PdfPCell cell = new PdfPCell() { 
    CellEvent = rr, Border = PdfPCell.NO_BORDER, 
    Padding = 4, Phrase = new Phrase("test") 
    }; 
    table.AddCell(cell); 
    document.Add(table); 
} 
+2

अपनी कार्यशील धन्यवाद @kuujinbo धन्यवाद – Neeraj

+0

बहुत यह बिल्कुल क्योंकि ओपी तालिका सेल नहीं गोलाई लिए पूछ रहा है इस सवाल का जवाब नहीं दे रहा है:

तो इस तरह ऊपर बनाया ईवेंट हैंडलर आवंटित। – Icet

संबंधित मुद्दे