PdfBox - change font of text in PDF - pdf

Is it possible to change text fonts in existed PDF through PdfBox? If yes how to do that? I have problems with some special fonts in PDF and I want to change them to font that is widely supported.
Thanks

Related

PDFBox changes font name from language character to english character

While merging 2 pdf with pdfbox / opening pdf in pdfbox debugger, if PDF file have font name with language character like MSゴシック or MS明朝, then it changes font to ",l,rfsfvfbfn" or ",l,r-3/4c"
If we have pdf with font "MS Gothic" in english, it merges document properly.
Changing font name leads to spacing issue in merged document and makes it unreadable as few characters overlaps.
Difference in font while open in PDFDebugger
Difference in font after merging

Problem showing a font with license restriction to pdf

I'm programming to convert a file to pdf on mac, file contains a Chinese text
using a font STFangsong which has license restriction and is not embeddable, I
tried many CMaps to encode it, but it seems the root cause is because pdf viewer(both
mac previewer and acrobat reader) does not recognize the font, as shown in the pdf
file properties, Actual Font Unknown and there is a pop message says can't find or
create the font.
The PDF 32000-1:2008 9.6.6.4 tells a guideline that when encoding truetype font,
the font program should be embedded, though no specific explanation, from my
understanding, embedding can guarantee the pdf is readable everywhere, but I do not
need this since the font is licensed, I just want it can be shown on my computer.
So my question here is does those pdf viewer has limitation on those CJK characters
when embedding is forbidden?
By the way, I used Microsoft word to write a text with the font and save word to
pdf, and it shows the font is embedded subset, does it mean Microsoft have bought the
license?

Replace fonts by converting PDF to PDF/A

I faced a problem while developing converter from pdf to pdf/a. I use PDFBox library. I need not only convert existing pdf to pdf/a, but also replace font. In input pdf are used standart Helvetica and Courier. I want to replace Helvetica with another font. Is it possible to do it without re-rendering?

Pdf partial font embedding with iText

I am asked to include partial font into a pdf.
I think I will use iText and I found how to embed the font but I found no clue about partial embedding.
Does anybody know if partial embedding is automatic ? Or maybe iText does not have this feature ?
Thank you.
When does iText embed the full font, a subset, or no font?
In this answer, it is assumed that you use the BaseFont class and the Font class like this:
BaseFont bf = BaseFont.createFont(pathToFont, encoding, embedded);
Font font = new Font(bf, 12);
In this snippet:
pathToFont is the path to a font file (.ttf, .ttc, otf, .afm),
encoding is an encoding such as "winansi", BaseFont.IDENTITY_H,...
embedded is a boolean: true or false.
Will iText embed the font or not?
That's determined by the embedded parameter:
If it is false, the font isn't embedded.
If it is true, the font is embedded, except in the case of the Standard Type 1 fonts or Type 1 fonts for which the .pfb file is missing or CJK fonts.
Regarding the exceptions:
The Standard Type 1 fonts are 4 flavors of Helvetica (regular, bold, italic, bold-italic), 4 flavors of Times Roman (...), 4 flavors of Courier (...), Symbol and Zapfdingbats. iText ships with 14 Adobe Font Metrics (AFM) files. These files contain the metrics that are needed to calculate widths of glyphs and words. iText doesn't have the necessary Printer Font Binary (PFB) files that are required to embed the font.
Type 1 fonts are stored in two files: an AFM file and a PFB file. If you provide an AFM file, iText will look for the PFB file in the same directory. If iText doesn't find any PFB file, the font can't be embedded.
CJK stands for a series of Chinese, Japanese and Korean fonts that are available in downloadable font packs. It's a special type of Asian fonts; Asian fonts in .ttf, .otf or .ttc files can be embedded.
Will iText subset the font or not?
iText will always try to embed a subset of the font, not the whole font, except in case you provide a Type 1 font (AFM and PFB file). In case a Type 1 font is provided, the full font is embedded.
Can iText embed the full font?
Yes, you can force iText to embed the full font by adding this line:
bf.setSubset(false);
However, this value will be ignored in case you use the encoding Identity-H because that's how it's described in ISO-32000-1. iText will only embed full fonts that are stored inside the PDF as a simple font (256 characters); iText will never embed fonts that are stored as a composite font (up to 65,535 characters).

Which Chinese font is commonly supported by PDF readers of Chinese people?

I am generating PDF files which contain English and Chinese characters (using the Ruby Prawn library). I don't want to embed a Chinese font file in the generated PDF files, because these files need to stay small. So I'm wondering if I could just mentioning a Chinese font name in my PDF files, and have the PDF readers correctly rendering the Chinese characters because the PDF readers would already have the Chinese font file.
Is that something sensible? If so is there any commonly used Chinese font that one can expect to be installed in most of the PDF readers used by Chinese people?
The best way to ensure that a PDF file can be displayed on a any reader, is to use partially embedded fonts (also known as font subset). In PDF, you don't need to include the whole font with your document, having a subset with just the glyphs that were used in the file is enough for the file to be portable.