icepdf icon indicating copy to clipboard operation
icepdf copied to clipboard

ClassCastException in parseDescendantFont

Open SirFrancix opened this issue 9 months ago • 5 comments

unchecked cast in descendantFont = (CompositeFont) library.getObject(descendantFontReference); produces a ClassCastException if object is a FontDescriptor. Handling for a FontDescriptor should be added

SirFrancix avatar Apr 30 '25 11:04 SirFrancix

Can you post a sample file or post the stack trace?

pcorless avatar Apr 30 '25 14:04 pcorless

I can add a fix to avoid the class cast issue but without a sample I won't be able to piece together if the FontDescriptor should be searched for an embedded file.

pcorless avatar May 02 '25 04:05 pcorless

this is the stactrace we get:

java.lang.ClassCastException: class org.icepdf.core.pobjects.fonts.FontDescriptor cannot be cast to class org.icepdf.core.pobjects.fonts.zfont.CompositeFont (org.icepdf.core.pobjects.fonts.FontDescriptor and org.icepdf.core.pobjects.fonts.zfont.CompositeFont are in module [email protected] of loader 'app')
	at [email protected]/org.icepdf.core.pobjects.fonts.zfont.Type0Font.parseDescendantFont(Type0Font.java:76)
	at [email protected]/org.icepdf.core.pobjects.fonts.zfont.Type0Font.init(Type0Font.java:38)
	at [email protected]/org.icepdf.core.pobjects.Resources.getFont(Resources.java:171)
	at [email protected]/org.icepdf.core.util.parser.content.AbstractContentParser.consume_Tf(AbstractContentParser.java:820)
	at [email protected]/org.icepdf.core.util.parser.content.ContentParser.parseText(ContentParser.java:743)
	at [email protected]/org.icepdf.core.util.parser.content.ContentParser.parse(ContentParser.java:149)
	at [email protected]/org.icepdf.core.pobjects.Page.init(Page.java:441)
	at [email protected]/org.icepdf.core.pobjects.Page.init(Page.java:381)
	at [email protected]/org.icepdf.ri.common.views.AbstractPageViewComponent$PageImageCaptureTask.call(AbstractPageViewComponent.java:412)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)

SirFrancix avatar May 02 '25 05:05 SirFrancix

I'll try to provide a sample-pdf. The one i've got right now contains personal data, so I have to modify it. Additionally I could create a pull request with a change fixing the error

SirFrancix avatar May 02 '25 06:05 SirFrancix

There is the redaction and edit text feature on the main branch (right click on text with the text tool selected). Might work well in this instance, just make sure to export the document, not save as.

pcorless avatar May 02 '25 13:05 pcorless

Committed a fix, marking as done.

pcorless avatar May 15 '25 02:05 pcorless