Hi Tilman, Thank you so much. This works.
I added the following lines to the end of the method that creates the overlay document: try (ByteOutputStream devNull = new ByteOutputStream()) { watermarkDoc.save(devNull); } and that solved the problem with the embedding of the font. Would it be an idea to add these lines (prophylactically) to the code in the Overlay class? Ideally it would happen only if the PDDocument hadn’t been saved yet but I don’t know if it’s possible to check for that. If there is interest in this approach I’d be happen to submit a patch that adds this. - Rainer PS: I encountered a different problem while troubleshooting and trying to fix this one: I originally used PdfBox 2.0.14 and upgraded to 2.0.20 while troubleshooting. After that I had a problem with an jpeg image (a logo) that is part of the overlay. It shows up on some pages but not on others in most viewers. When opening the file Acrobat it pops up a dialog saying “There was an error while reading a stream”. This went away after reverting too 2.0.14. Is this a known problem? > On Aug 6, 2020, at 8:45 PM, Tilman Hausherr <thaush...@t-online.de> wrote: > > Hi, > > This is related to a known problem, that the font subsetting is done when > saving. So try saving to a dummy, e.g. to a ByteArrayOutputStream. > > I would like to know whether that works, or whether you have to always > reload, so that the documentation can be improved. > > Tilman > > Am 07.08.2020 um 00:34 schrieb Support: >> I am using the org.apache.pdfbox.multipdf.Overlay class to add a watermark >> to an existing PDF file. The watermark contains the name of the customer and >> therefore can contain a wide range of characters. To accommodate that I am >> embedding the NotoSansCJKtc-Regular.ttf font in the overlay document. (If I >> write the overlay document to a file the font is embedded as expected). >> However, when I use Overlay.overlayDocuments(Map<Integer,PDDocument>) the >> resulting file does not embed the font. >> >> How the resulting PDF file is displayed depends on the PDF viewer and on >> whether the font happens to be installed on the system. Sometimes helpful >> warnings are produced (Acrobat if the font is not installed), sometimes the >> overlay text is displayed with what appears to random characters and random >> font (Google Chrome) and sometimes everything is shown beautifully. >> >> Can anyone direct me to how I can get the true type font embedded in the >> PDDocument created by overlayDocuments? What part am I missing? I will >> gladly provide some sample code / documents if there is obvious answer. >> >> Thanks, >> >> - Rainer >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org > For additional commands, e-mail: users-h...@pdfbox.apache.org >