Java tutorial
import java.io.FileOutputStream; import com.lowagie.text.Chunk; import com.lowagie.text.Document; import com.lowagie.text.Image; import com.lowagie.text.PageSize; import com.lowagie.text.Paragraph; import com.lowagie.text.Phrase; import com.lowagie.text.pdf.BaseFont; import com.lowagie.text.pdf.PdfTemplate; import com.lowagie.text.pdf.PdfWriter; public class TemplateImagesScaleHeightPDF { public static void main(String[] args) { Document document = new Document(PageSize.A4, 50, 50, 50, 50); try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("TemplateImagesScaleHeightPDF.pdf")); document.open(); PdfTemplate template = writer.getDirectContent().createTemplate(20, 20); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); String text = "Vertical"; float size = 16; float width = bf.getWidthPoint(text, size); template.beginText(); template.setFontAndSize(bf, size); template.setTextMatrix(0, 2); template.showText(text); template.endText(); template.setWidth(width); template.setHeight(size + 2); Image img = Image.getInstance(template); img.setRotationDegrees(90); Paragraph p1 = new Paragraph("This is a template "); p1.add(new Phrase(new Chunk(img, 0, 0))); p1.setLeading(img.scaledHeight() * 1.1f); document.add(p1); document.close(); } catch (Exception de) { System.err.println(de.getMessage()); } } }