2012-08-07 16 views
16

जोड़ना मैं लिफाफा खिड़की कहां जा रहा हूं, इस पर निर्भर करता हूं कि मैं एक खाली स्थान छोड़कर एक पत्र उत्पन्न करने की कोशिश कर रहा हूं और फिर पते के शीर्ष पर पेस्ट कर रहा हूं।पूर्ण स्थानित टेक्स्ट

तो मैं यह कर रहा शुरू:

Document doc = new Document(PageSize.LETTER, 72, 72, 72, 72); 
var w = PdfWriter.GetInstance(doc, output); 
Font font = FontFactory.GetFont("arial", 10); 
doc.Open(); 
doc.Add(new Paragraph("date", font) { SpacingAfter = 5 }); 
doc.Add(new Paragraph("\n\n\n\n\n\n", font));//empty spot 
doc.Add(new Paragraph("long\n paragraph\ns panning\ multiple\n lines\n", font) { SpacingAfter = 5 }); 
doc.Add(new Paragraph("long\n paragraph\ns panning\ multiple\n lines\n", font) { SpacingAfter = 5 }); 
doc.Add(new Paragraph("long\n paragraph\ns panning\ multiple\n lines\n", font) { SpacingAfter = 5 }); 
doc.Add(new Paragraph("long\n paragraph\ns panning\ multiple\n lines\n", font) { SpacingAfter = 5 }); 
doc.Add(new Paragraph("long\n paragraph\ns panning\ multiple\n lines\n", font) { SpacingAfter = 5 }); 

float llx = 63f, lly = 450f, urx = 387f, ury = 531f; 
?? Somehow add "name\n address line 1\n address line2\n city state zip" 

doc.Close(); 

मैं उन निर्देशांक पर कुछ पाठ जोड़ने के लिए सक्षम होने के लिए उम्मीद कर रहा था, लेकिन मैं समझ नहीं सकता कैसे ... किसी को भी यह करने के लिए एक तरह से पता है ?

उत्तर

21

उत्तर मिला "Here"। (Yannick Smits से नीचे उद्धृत किया गया है इस सवाल का जवाब)

===============

इस प्रयास करें: SetSimpleColumn की

ColumnText ct = new ColumnText(cb); 
Phrase myText = new Phrase("TEST paragraph\nNewline"); 
ct.SetSimpleColumn(myText, 34, 750, 580, 317, 15, Element.ALIGN_LEFT); 
ct.Go(); 

मानकों हैं:

  1. वाक्यांश
  2. नीचे-बाएं-x
  3. नीचे-बाएं-y
  4. ऊपरी-दाएँ-x (LLX + चौड़ाई)
  5. ऊपरी-दाएँ-y (lly + ऊंचाई)
  6. (प्रिंट की लाइनों के बीच खाली स्थान की मात्रा) प्रमुख
  7. संरेखण।
+0

बॉक्स ऊंचाई और चौड़ाई बॉक्स का क्या मतलब है:

यह iTextSharp ETIQUETAS के लिए मेरे कोड है? (आइटम 4,5) –

+0

मुझे लगता है कि तर्क 4 और 5 'यूआरएक्स' और' ury' हैं, न कि 'बॉक्स चौड़ाई' और 'बॉक्स ऊंचाई'। और तर्क 6 'अग्रणी' है, जो मुझे यकीन नहीं है कि यह क्या है, लेकिन पाठ के लिए 0 एफ काम करता है, इसलिए यह 'रेखा ऊंचाई' नहीं है। –

+0

धन्यवाद मार्क। मैंने इसे सही किया। – colinbashbash

16

आप जहां भी चाहें टेक्स्ट खींचने के लिए टेक्स्ट मैट्रिक्स के साथ एक सामग्रीबाइट का उपयोग भी कर सकते हैं।

PdfContentByte cb = writer.DirectContent; 
cb.BeginText(); 
BaseFont f_cn = BaseFont.CreateFont("c:\\windows\\fonts\\calibri.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED); 
cb.SetFontAndSize(f_cn, 6); 
cb.SetTextMatrix(475, 15); //(xPos, yPos) 
cb.ShowText("Some text here and the Date: " + DateTime.Now.ToShortDateString()); 
cb.EndText(); 

लाभ यह है कि यदि आपको बॉक्स के पूर्ण आकार को आकर्षित करने की आवश्यकता नहीं है तो पाठ में जाएगा। सरल कॉलम के साथ, आप दस्तावेज़ पर एक आयत खींच रहे हैं, और इसके भीतर पाठ को पोजिशन कर रहे हैं। ContentByte के साथ, आप आयताकार चकमा देते हैं, और पाठ को स्वयं ही स्थिति में रखते हैं।

+0

यह अच्छा है। मैं वास्तव में पाठ की चौड़ाई को सीमित करना चाहता था, हालांकि। इसलिए कॉलमटेक्स्ट का उपयोग करना मेरे उदाहरण में वास्तव में अधिक उपयोगी है। धन्यवाद! – colinbashbash

+0

मैं फ़ंक्शन कॉल में setSimpleColumn का उपयोग कर रहा था, और उसी माप के साथ बाद की कॉल बल्कि अप्रिय स्थिति के कारण हुई थी। इस विधि में बदलना बहुत जल्दी तय! धन्यवाद। –

+0

लेकिन शोटेक्स्ट विधि का उपयोग करके आप आरटीएल भाषाओं के लिए रनडिरेक्शन सेट नहीं कर सकते हैं। – Arman

0

आपके डेटा के लिए बहुत बहुत धन्यवाद, मुझे यह पसंद है लेकिन मेरी अंग्रेजी बहुत खराब है, क्षमा करें।

public void impriItex() 
{ 
    iTextSharp.text.Font fontH1 = new iTextSharp.text.Font(FUENTE_BASE, 14, iTextSharp.text.Font.ITALIC); 
    iTextSharp.text.Font fuente = new iTextSharp.text.Font(FUENTE_BASE, 12, iTextSharp.text.Font.NORMAL); 
    iTextSharp.text.Font FUENTE_CABECERA_TABLA = new iTextSharp.text.Font(FUENTE_BASE, 10, iTextSharp.text.Font.BOLD); 
    dataGridViewOculta.DataSource = fun.CargaDato(cargaVelores); 
    dataGridViewTotales.DataSource = fun.CargaDato(cargaVelores); 
    dataGridViewVentas.DataSource = fun.CargaDato(cargaVelores); 
    //Letras 
    //Tabla 
    PdfPTable pdfTable = new PdfPTable(6); 
    pdfTable.DefaultCell.Padding = 2; 
    pdfTable.WidthPercentage = 40; 
    pdfTable.HorizontalAlignment = Element.ALIGN_CENTER; 
    pdfTable.DefaultCell.BorderWidth = 1; 
    //cabeceras 
    foreach (DataGridViewColumn column in dataGridViewOculta.Columns) 
    { 

     PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText, FUENTE_CABECERA_TABLA)); 
     cell.HorizontalAlignment = Element.ALIGN_CENTER; 
     cell.BackgroundColor = new iTextSharp.text.BaseColor(210, 240, 240); 
     pdfTable.AddCell(cell); 
    } 

    //datos 
    foreach (DataGridViewRow row in dataGridViewOculta.Rows) 
    { 
     try 
     { 
      foreach (DataGridViewCell cell in row.Cells) 
      { 
       String texto = cell.Value.ToString(); 
       String textovacio = texto.Replace("00:00:00", " "); 
       PdfPCell cosa = new PdfPCell(new Phrase(textovacio, fuente)); 
       cosa.HorizontalAlignment = Element.ALIGN_CENTER; 
       pdfTable.AddCell(cosa); 
       pdfTable.HorizontalAlignment = Element.ALIGN_CENTER; 
      } 
     } 
     catch { return; } 
    } 

    //Exporting to PDF 
    string folderPath = "C:\\PDFs\\"; 
    if (!Directory.Exists(folderPath)) 
    { 
     Directory.CreateDirectory(folderPath); 
    } 
    using (FileStream stream = new FileStream(folderPath + "Etiquetas.pdf", FileMode.Create)) 
    { 
     Document pdfDoc = new Document(PageSize.A4, 0f, 0f, 0f, 0f); 
     PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream); 
     PdfPTable tabla = new PdfPTable(1); 
     pdfDoc.Open(); 
     PdfContentByte cb = writer.DirectContent; 
     PdfContentByte lineas = writer.DirectContent; 

     for (int fila = 0; fila < dataGridViewVentas.Rows.Count - 1; fila++) 
     { 
      for (int col = 0; col < dataGridViewVentas.Rows[fila].Cells.Count; col++) 
       labelTitulo.Text = "Etiquetas"; 
      Cantidad = dataGridViewVentas.Rows[fila].Cells[0].Value.ToString(); 
      IdColor = dataGridViewVentas.Rows[fila].Cells[1].Value.ToString(); 
      IdCategoria = dataGridViewVentas.Rows[fila].Cells[2].Value.ToString(); 
      NomCategoria = dataGridViewVentas.Rows[fila].Cells[3].Value.ToString(); 
      Colores = dataGridViewVentas.Rows[fila].Cells[4].Value.ToString(); 
      CodigoDeGrupo = dataGridViewVentas.Rows[fila].Cells[5].Value.ToString(); 
      lblNombreSocio.Text = IdColor + ":" + Cantidad; 
      String espacio = "   "; 
      Paragraph linea = new Paragraph("________________________________________________________", fuente); 
      Paragraph lineaDoble = new Paragraph(Cantidad, fuente); 
      Paragraph SocioPar = new Paragraph("Color:" + lblNombreSocio.Text, fuente); 
      Paragraph SociedadPar = new Paragraph("Categoria: " + NomCategoria, fuente); 
      Paragraph Titulo = new Paragraph(labelTitulo.Text, fontH1); 
      Paragraph parrafoEspacio = new Paragraph(" ", fuente); 
      linea.Alignment = Element.ALIGN_CENTER; 
      lineaDoble.Alignment = Element.ALIGN_CENTER; 
      Titulo.Alignment = Element.ALIGN_CENTER; 

      SocioPar.Alignment = Element.ALIGN_CENTER; 
      SociedadPar.Alignment = Element.ALIGN_CENTER; 
      pdfTable.HorizontalAlignment = Element.ALIGN_CENTER; 
      pdfDoc.Add(linea); 
      pdfDoc.Add(Titulo); 
      pdfDoc.Add(lineaDoble); 
      pdfDoc.Add(parrafoEspacio); 
      pdfDoc.Add(SocioPar); 
      pdfDoc.Add(SociedadPar); 

      // pdfDoc.Add(pdfTable);} 
      for (int x = 0; x < Convert.ToInt32(Cantidad); x++) 
      { 
       cb.Rectangle(posx, posy, 40f, 25f); 
       lineas.SetLineWidth(1); 
       lineas.MoveTo(posx+20, posy+15); 
       lineas.LineTo(posx+20,posy); 
       lineas.Stroke(); 
      // lineas. 
       lineas.MoveTo(posx + 20, posy+10); 
       lineas.LineTo(posx, posy + 10); 
       lineas.MoveTo(posx + 40, posy + 10); 
       lineas.LineTo(posx, posy + 10); 
       lineas.Stroke(); 
       //texto !!!!!!!!!!! 
       lineas.BeginText(); 
       lineas.SetFontAndSize(FUENTE_BASE, 6); 
       lineas.SetTextMatrix(posx, posy); 
       lineas.ShowText(IdColor); 
       lineas.EndText(); 
       //tabla.AddCell("prueba"); 
       // pdfDoc.Add(tabla); 
       Chunk c = new Chunk(x.ToString()); 
       // iTextSharp.text.Rectangle rect = new iTextSharp.text.Rectangle(posx, 650f, 25f, 10f); 
       // cb.Rectangle(rect); 
       cb.Stroke(); 
       float nuevo = posx + 42f; 
       posx = nuevo; 
       if (posx > 500f) 
        { posx = 20; posy = posy-35f; } 
      } 
      pdfDoc.NewPage();    
      posx = 10f; 
      posy = 700; 
     } 
     pdfDoc.Close(); 
     stream.Close(); 
    } 
} 
संबंधित मुद्दे