2010-05-03 15 views
23

पीडीएफ मैं पल में उत्पादन कर सकते हैं: screenshot http://yart.com.au/junk/itextsharp_problem.jpgलंबे टेक्स्ट को कैसे रखें और लपेटें?

मैं पाठ निचले बाएँ में अंतरिक्ष को भरने के लिए चाहते हैं। मैं उसे कैसे कर सकता हूँ? धन्यवाद!

यह मेरा कोड है:

private static void CreatePdf4(string pdfFilename, string heading, string text, string[] photos, string emoticon) 
{ 
    Document document = new Document(PageSize.A4.Rotate(), 26, 36, 0, 0); 
    PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(pdfFilename, FileMode.Create)); 
    document.Open(); 

    // Heading 
    Paragraph pHeading = new Paragraph(new Chunk(heading, FontFactory.GetFont(FontFactory.HELVETICA, 54, Font.NORMAL))); 
    document.Add(pHeading); 

    // Photo 1 
    Image img1 = Image.GetInstance(HttpContext.Current.Server.MapPath("/uploads/photos/" + photos[0])); 
    img1.ScaleAbsolute(350, 261); 
    img1.SetAbsolutePosition(46, 220); 
    img1.Alignment = Image.TEXTWRAP; 
    document.Add(img1); 

    // Photo 2 
    Image img2 = Image.GetInstance(HttpContext.Current.Server.MapPath("/uploads/photos/" + photos[1])); 
    img2.ScaleAbsolute(350, 261); 
    img2.SetAbsolutePosition(438, 220); 
    img2.Alignment = Image.TEXTWRAP; 
    document.Add(img2); 

    // Text 

    PdfContentByte cb = writer.DirectContent; 
    cb.BeginText(); 
    cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false), 18); 
    cb.SetTextMatrix(46, 175); 
    cb.ShowText(text); 
    cb.EndText(); 

    // Photo 3 
    Image img3 = Image.GetInstance(HttpContext.Current.Server.MapPath("/uploads/photos/" + photos[2])); 
    img3.ScaleAbsolute(113, 153); 
    img3.SetAbsolutePosition(556, 38); 
    document.Add(img3); 

    // Emoticon 
    Image imgEmo = Image.GetInstance(HttpContext.Current.Server.MapPath("/Content/images/" + emoticon)); 
    imgEmo.ScaleToFit(80, 80); 
    imgEmo.SetAbsolutePosition(692, 70); 
    document.Add(imgEmo); 

    document.Close(); 
} 

उत्तर

36

हल

PdfContentByte cb = writer.DirectContent; 
    ColumnText ct = new ColumnText(cb); 
    ct.SetSimpleColumn(new Phrase(new Chunk(text, FontFactory.GetFont(FontFactory.HELVETICA, 18, Font.NORMAL))), 
        46, 190, 530, 36, 25, Element.ALIGN_LEFT | Element.ALIGN_TOP); 
    ct.Go(); 
+1

वास्तव में क्या मैं देख रहा था :) –

+0

AS3 में PurePDF के लिए भी समान काम करता है। – DoubleThink

+2

आप लाइन स्पेसिंग को कैसे समायोजित करते हैं? –

2

कोको देव के लिए, हाँ हम के रूप में PdfPCell के SetLeading संपत्ति का उपयोग कर पाठ के लिए पंक्ति रिक्ति सेट कर सकते हैं: PdfPCell.SetLeading(float fixedleading, float multiplied leading);

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