olyanren
olyanren

Reputation: 1458

Merge two Paragraph objects

I want to insert a piece of text in a PDF which contains bold and not-bold areas, but I do not know how can I do this ?

I'm using iText5 (java).

This is my code:

public class CreatePdf{
   private Font bigFont = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 12, Font.BOLD, new Color(0, 0, 0));
   private Font smallFont = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 8, Font.NORMAL, new Color(0, 0, 0));

   public void create(){
      Paragraph parag1=new Paragraph("Number: ",bigFont);//This gonna be bold font
      Paragraph parag2=new Paragraph("12", smallFont); //This gonna be normal font

      //Create one paragraph from these two paragraphs. But How ?
   }
}

Upvotes: 4

Views: 8096

Answers (3)

javier jaimes ruiz
javier jaimes ruiz

Reputation: 1

        Chunk parag1 = new Chunk("Number: ", texto);//This gonna be bold font
        Chunk parag2 = new Chunk("12", textosub); //This gonna be normal font
        Paragraph comb = new Paragraph();
        comb.Add(new Chunk(parag1));
        comb.Add(new Chunk(parag2));
        pdfDoc.Add(comb);

Upvotes: 0

rics
rics

Reputation: 5596

You can make simpler:

comb.add(parag1);
comb.add(parag2);

The Chunk is not necessary.

Upvotes: 7

olyanren
olyanren

Reputation: 1458

I found the solution:

public class CreatePdf{
   private Font bigFont = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 12, Font.BOLD, new Color(0, 0, 0));
   private Font smallFont = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 8, Font.NORMAL, new Color(0, 0, 0));

   public void create(){
      Paragraph parag1=new Paragraph("Number: ",bigFont);//This gonna be bold font
      Paragraph parag2=new Paragraph("12", smallFont); //This gonna be normal font
      Paragraph comb=new Paragraph(); 
      comb.add(new Chunk(parag1)) 
      comb.add(new Chunk(parag2)); 
   }
}

Upvotes: 6

Related Questions