2012-04-19 13 views
6

क्या iTextSharp में एक तालिका (पीडीएफपीटेबल) के भीतर सेल स्पेसिंग होना संभव है? मैं कहीं भी नहीं देख सकता कि यह संभव है। मैंने iTextSharp.text.Table का उपयोग करने का एक सुझाव देखा था, लेकिन यह iTextSharp (5.2.1) के मेरे संस्करण पर उपलब्ध नहीं प्रतीत होता है।iTextSharp टेबल सेल स्पेसिंग संभव है?

उत्तर

1

तालिका वर्ग को पीडीएफपीटेबल के पक्ष में 5.x से शुरू होने वाले आईटेक्स्ट से हटा दिया गया है।

अंतर के लिए, आप जो खोज रहे हैं वह सेटपैडिंग विधियां हैं। आप देख रहे हैं

http://api.itextpdf.com/itext/com/itextpdf/text/pdf/PdfPCell.html

(यह जावा संस्करण के लिए है, लेकिन सी # बंदरगाह तरीकों के नाम बनाए रखता है)

+4

कि के लिए धन्यवाद, लेकिन वह (कोशिका के भीतर) सेल गद्दी को जोड़ने के लिए है। मुझे सेल स्पेसिंग (कोशिकाओं के बीच) की आवश्यकता है। –

13

:

अधिक जानकारी के लिए iText के एपीआई पर एक नज़र डालें एचटीएमएल की तरह सही सेल स्पेसिंग के लिए, PdfPTable उस मूल रूप से समर्थन नहीं करता है। हालांकि, PdfPCell ऐसी संपत्ति का समर्थन करता है जो IPdfPCellEvent का कस्टम कार्यान्वयन करता है जिसे सेल लेआउट होने पर कॉल किया जाएगा। नीचे एक का एक सरल कार्यान्वयन है, आप शायद इसे अपनी जरूरतों के अनुसार बदलना चाहते हैं।

public class CellSpacingEvent : IPdfPCellEvent { 
    private int cellSpacing; 
    public CellSpacingEvent(int cellSpacing) { 
     this.cellSpacing = cellSpacing; 
    } 
    void IPdfPCellEvent.CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { 
     //Grab the line canvas for drawing lines on 
     PdfContentByte cb = canvases[PdfPTable.LINECANVAS]; 
     //Create a new rectangle using our previously supplied spacing 
     cb.Rectangle(
      position.Left + this.cellSpacing, 
      position.Bottom + this.cellSpacing, 
      (position.Right - this.cellSpacing) - (position.Left + this.cellSpacing), 
      (position.Top - this.cellSpacing) - (position.Bottom + this.cellSpacing) 
      ); 
     //Set a color 
     cb.SetColorStroke(BaseColor.RED); 
     //Draw the rectangle 
     cb.Stroke(); 
    } 
} 

इसका इस्तेमाल करने के लिए:

//Create a two column table 
PdfPTable table = new PdfPTable(2); 
//Don't let the system draw the border, we'll do that 
table.DefaultCell.Border = 0; 
//Bind our custom event to the default cell 
table.DefaultCell.CellEvent = new CellSpacingEvent(2); 
//We're not changing actual layout so we're going to cheat and padd the cells a little 
table.DefaultCell.Padding = 4; 
//Add some cells 
table.AddCell("Test"); 
table.AddCell("Test"); 
table.AddCell("Test"); 
table.AddCell("Test"); 

doc.Add(table); 
-4

प्रयास करें यह

 PdfPTable table = new PdfPTable(2); 
     table.getDefaultCell().setBorder(0); 
     table.getDefaultCell().setPadding(8); 
     table.addCell("Employee ID"); 
     table.addCell(""); 
     table.addCell("Employee Name"); 
     table.addCell(""); 
     table.addCell("Department"); 
     table.addCell(""); 
     table.addCell("Place"); 
     table.addCell(""); 
     table.addCell("Contact Number"); 
     table.addCell(""); 
     document.add(table); 
संबंधित मुद्दे