Hi Tilman
I've uploaded the following series of test PDF's (a single text label and
field) to DropBox that show how the PDF size grows with each subsequent
save when there's an embedded font.
FontTest_0_Original.pdf
FontTest_1_Fill_&_Save.pdf
FontTest_2_Open_&_Save.pdf
FontTest_3_Resave_(No_Changes).pdf
FontTest_4_Open_&_Save.pdf
If I first check for the font with "if ( resources.getFont( cosName ) ==
null )" then the following PDF is the result and subsequent saves don't
grow in size.
FontTest_with_Check_(Open_&_Save).pdf
https://www.dropbox.com/scl/fo/am1wdjihq94f4h0nyd604/AIGBihk-TA2IXTnwrLz5PPo?rlkey=zlpffg4ekrxh46y4q4s4d6b8y&st=nkohx8f5&dl=0
Thanks, regards
Jurgen
On Fri, 26 Apr 2024 16:03:47 +0200, Tilman Hausherr
<thaush...@t-online.de> wrote:
Re "bigger each time it's opened and then saved", hard to tell without
the PDF. Maybe the font you're replacing is used elsewhere due to other
code that used this font.
If you can't share the PDF, look at it with PDFDebugger or with
NOTEPAD++. In PDFDebugger don't forget to switch between the page view
and the internal structure view (in the view menu)
Tilman
On 26.04.2024 15:50, Jurgen Doll wrote:
Hi Tilman
My bad, I was working on the image code and just assumed that it was
the culprit.
It turns out that I must be embedding fonts incorrectly. I use this
code each time I open the PDF:
var resources = Objects.requireNonNullElseGet(
pdForm.getDefaultResources(), PDResources::new );
var lucidaFont = PDType0Font.load( pdfDoc,
LUCIDA_UNICODE_FILE.get() );
var cosName = COSName.getPDFName( lucidaFont.getName() );
resources.put( cosName, lucidaFont );
pdForm.setDefaultResources( resources );
The above seems to make the PDF get bigger each time it's opened and
then saved.
So I've added a check first, like this:
if ( resources.getFont( cosName ) == null )
{
resources.put( cosName, lucidaFont );
pdForm.setDefaultResources( resources );
}
And now the PDF doesn't seem to be growing any more.
Thanks,
Jurgen
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org