Merge two paragraph objects

I want to insert a piece of text into a PDF that contains bold and non-greasy areas, but I don’t know how I can do this?

I am 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 ? } } 
+4
source share
2 answers

I found a 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)); } } 
+6
source

You can make it easier:

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

Chunk is not needed.

+4
source

Source: https://habr.com/ru/post/1386051/


All Articles