I am using iTunes 7 to create a PDF file with a mix of two fonts.(Example: Bold text in the middle of the paragraph)
When I was using iText5, I implemented it using Chunks, but
Font regular=new Font(FontFamily.HELVETICA, 12);
Fontbold = Fontfont = new Font (FontFamily.HELVETICA, 12, Font.BOLD);
Phrase p = new Phrase("NAME:",bold);
p.add(new chunk(cc_cust_dob, regular));
PdfPCellcell= new PdfPCell(p);
I couldn't find a way to do this with iText7. Is there a way to create a paragraph by mixing different fonts in iTunes 7?
Note: I'm using csharp, but it can be an example of java.
For more information, see iText7:iText7:building blocks" Chapter 1: Introducing the PdfFont class" . In this chapter, you'll find it easier to switch fonts with iTunes 7 than with iTunes 5.With iTunes 7, you can work with the default font size, define and reuse Style
objects.
Example:
Style normal=new Style();
PdfFontfont=PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
normal.setFont(font).setFontSize(14);
Style code = new Style();
PdfFont monospace=PdfFontFactory.createFont(FontConstants.COURIER);
code.setFont(monospace).setFontColor(Color.RED)
.setBackgroundColor (Color.LIGHT_GRAY);
Paragraph = new Paragraph();
p.add(new Text("The Strange Case of").addStyle(normal));
p.add(new Text("Dr. Jekyl").addStyle(code));
p.add(new Text("and").addStyle(normal));
p.add(new Text("Mr. Hyde").addStyle(code));
p.add(new Text(".").addStyle(normal));
document.add(p);
First, define Style
using 14pt Times-Roman called normal
. Next, define Style
using a 12pt Courier called code
(gray background/red letters). Then create a Parograph
using the Text
object that uses these styles.
You can associate add()
comments as shown in the following example:
Text title1 = new Text("The Strange Case of").setFontSize(12);
Text title2 = new Text("Dr. Jekyll and Mr. Hyde") .setFontSize(16);
Text author = new Text ("Robert Louis Stevenson");
Paragraph = new Paragraph().setFontSize(8)
.add(title1).add(title2).add("by").add(author);
document.add(p);
Set the font size of the newly created Parograph
to 8pt. This font size is inherited by all objects added to the Parograph
unless the object overwrites its default size.
For title1
, define a font size of 12pt, and for title2
, define a font size of 16pt. Content added as String("by")
and content added as Text
objects inherit the font size from the added Parograph
.
これThis is from the official tutorial.
© 2024 OneMinuteCode. All rights reserved.