Hello.

I have two questions about iText.

The pdf file exactly has to be like the word file that was sent to me. In the word file; the character is Times New Roman and its 10 puntos.

But in the pdf file when i try to do Times.Roman and 10 puntos; it seems little according to the word format.

Are there any paralellism between the size of word and pdf?

Like size 10 in word is equal to size 14 in pdf.

I also have another question...

The paragraph i wrote seems like this in pdf document.

aaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaa

but i want it to be as the same like

aaaaaaaaaaaaaa
aaaaaaaaaaaaaa
aaaaaaaaaaaaaa

I want all the lines end up vertically equal. How can I achieve this?

Thanks from now...

Dani AI

Generated

As pointed out, the iText tutorial is a good start for creating PDFs from scratch. For reproducing an existing Word file exactly, 's suggestion to read the Word document settings (font name, size, spacing, margins) first is useful—Apache POI can extract those properties so they can be reproduced in iText.

Short, practical points for 's two questions:

  • Font-size mismatch: Word and PDF use the same unit (points = 1/72 inch). If 10pt looks different, it is almost always because iText is using a different font file (built-in Type1 Times-Roman) than Word (TrueType/OTF Times New Roman). Embed the exact TrueType font used by Word and use that font at 10pt in iText to match metrics and glyph shapes. Example (pseudo-code):
String pathToTtf = "C:\\Windows\\Fonts\\Times New Roman.ttf";
BaseFont bf = BaseFont.createFont(pathToTtf, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font times = new Font(bf, 10f);
  • Lines ending vertically equal (right edge alignment): use full justification and control line spacing (leading). Justification spreads word spaces so right edges align; hyphenation allows breaking long words. Example:
Paragraph p = new Paragraph(text, times);
p.setLeading(0, 1.2f);                // e.g. 1.2x font size to match Word's single spacing
p.setAlignment(Element.ALIGN_JUSTIFIED);
HyphenationAuto h = new HyphenationAuto("en", "US", 2, 2);
p.setHyphenation(h);

Notes and troubleshooting:

  • Justification cannot split a single unbroken word; add soft hyphens or enable hyphenation patterns if needed.
  • Match page size and margins from the Word file; small differences there will change wrapping.
  • Embed fonts to avoid viewer substitution; check font license before embedding.
  • If pixel-perfect WYSIWYG with Word is required, consider converting Word -> PDF with a dedicated renderer (Word automation, LibreOffice headless or commercial converters) instead of reflowing text manually.

Recommended Answers

All 2 Replies

Take a look at this tutorial -

Take a look at this tutorial -

Good link, but this useful only if you are creating document from scratch. In above scenario getting documents settings from document together with context is essential. So Apache POI would be more relevant

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.