Hi

 

I have written some code for printing on Avery J8160 labels (A4 sheet of 21 labels 3x7), by making a label template then duplicating it in the document. However I can not figure out how to get my text in the template to wrap onto a new line. This is probably something to do with using the "PdfTemplate.ShowText" method:

PdfTemplate.ShowText("Blah bla blaa blah. This is my first paragraph. And it is very long. Very very long.");

 

I’ve tried using paragraphs and phrases instead but can't work out how to add these to a template (to be honest I don't realy know what i'm doing, i've only be using itext for 1/2 a day). Please help me, I have to get this sorted today.

 

Full code below.

 

Thanks

 

 

Jon D

 

 

public void fnTest2(string sFileName)

{

Document document = new Document(PageSize.A4, 0, 0, 0, 0);

 

//Set layout parameters for printing on Avery J8160 labels (A4 sheet of 21 labels 3x7)

int iTopMargin=46;                 

int iLeftMargin=17;

int iVerticalDivide=7;

int iLabelHeight=108;

int iLabelWidth=181;

int iLabelColumns=3;

int iLabelRows=7;

       

try

{

//Create label template

PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(Server.MapPath(sFileName), FileMode.Create));           

document.Open();           

PdfContentByte cb = writer.DirectContent;

PdfTemplate template = cb.CreateTemplate(iLabelWidth, iLabelHeight);

 

//Add some graphics to template so I can see label borders

template.MoveTo(0, iLabelHeight);

      template.LineTo(iLabelWidth, iLabelHeight);

      template.LineTo(iLabelWidth, 0);

      template.LineTo(0, 0);

      template.LineTo(0, iLabelHeight);

      template.Stroke();

      template.SetRGBColorStrokeF(255f, 0f, 0f);

template.Circle((iLabelWidth/2), (float.Parse(iLabelHeight.ToString())/2), (float.Parse(iLabelHeight.ToString())/2));

      template.Stroke();           

 

      //Write text to template – Why doesn’t it wrap onto a new line?

      template.BeginText();                    

      BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

      template.SetFontAndSize(bf, 12);

      template.SetTextMatrix(10, 90);

template.ShowText("Blah bla blaa blah. This is my first paragraph. And it is very long. Very very long.");

template.ShowText("snacks - ai sabor de cerdo");

      template.EndText();

 

      //Attempt to add text as paragraph instead, but it won’t let me add a paragraph to a template

//Phrase p1 = new Phrase(new Chunk(“blah bla blaa blah. This is my first paragraph. And it is very long. Very very long."));

      //template.Add(p1.d);

                 

//Loop to add labels to document

for (int i=1; i<=iLabelRows; i++)

{                            

for (int r=1; r<=iLabelColumns; r++)

{                                  

cb.AddTemplate(template, iLeftMargin+((iLabelWidth+iVerticalDivide)*(r-1)), document.PageSize.Height-(iTopMargin+(iLabelHeight*i)));

      }

      }

catch(Exception ex)

{

      Response.Write(ex.Message);

}       

document.Close();

}

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to