![]() In the FontConstants object, you'll find a constant for each of the 14 Standard Type 1 fonts. In lines 5 and 6, we create a PdfFont using the PdfFontFactory. This is a high-level object that will allow you to create a document without having to worry about the complexity of PDF syntax. We're creating a Document instance in line 2. These are low-level objects that will create PDF output based on your content. In line 1, we create a PdfDocument using a PdfWriter as parameter. Paragraph p = new Paragraph().add(title).add(" by ").add(author) Text author = new Text("Robert Louis Stevenson").setFont(font) PdfFont bold = PdfFontFactory.createFont(FontConstants.TIMES_BOLD) PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN) PdfDocument pdf = new PdfDocument(new PdfWriter(dest)) To create the PDF shown in figure 1.1, we used three of these fonts: we defined two fonts explicitly one font was defined implicitly. Not every viewer will use that exact font, but it will use a font that looks almost identical. These fonts are often referred to as the Standard Type 1 fonts. Traditionally, there are 14 fonts that every PDF viewer should be able to recognize and render in a reliable way: four Helvetica fonts (normal, bold, oblique, and bold-oblique), four Times-Roman fonts (normal, bold, italic, and bold-italic), four Courier fonts (normal, bold, oblique, and bold-oblique), Symbol and Zapfdingbats. If a specific font can be found, another font will be used instead. ![]() The viewer searches the operating system for the fonts that are needed to present the document. This is typically what happens when you don't embed fonts. ![]() If you'd open the same file on a Linux machine, other fonts would be used as actual fonts. These are fonts shipped with Microsoft Windows. ![]() The MT in the names of the Actual Font refers to the vendor of the fonts: the Monotype Imaging Holdings, Inc. In reality, three other fonts are used by the viewer: ArialMT, TimesNewRomanPS-BoldMT and TimesNewRomanPSMT. If we look at figure 1.1, we see that three different fonts were used to create a PDF document with the title and the author of the Jekyll and Hyde story: Helvetica, Times-Bold and Times-Roman. This will allow us to introduce some classes such as FontProgram and PdfFont. The movie posters could serve as sample material when discussing images in PDF.īut first things first: let's start with an example that displays the title and the author using different fonts. When I discovered how many movies, cartoons and series were made based on this work, I saw an opportunity to create a database that could be converted into a table. I made a first example turning a plain text file into a PDF eBook and I liked the result. That's not always easy because real-world use cases can get quite complex, whereas a tutorial needs to explain different concepts as simple as possible. While I was looking for a theme for this tutorial, I stumbled upon the short story "The Strange Case of Dr. When writing a tutorial, I always prefer working with real-world use cases. If you are looking for a specific version, you can always download these examples from our GitHub repo ( Java/. This Tutorial was written with iText 7.0.x in mind, however, if you go to the linked Examples you will find them for the latest available version of iText.
0 Comments
Leave a Reply. |