Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

PDFontType3

Help
Visitor
2013-02-25
2013-05-28
  • Visitor
    Visitor
    2013-02-25

    Hi,
    I'm trying to create a font type 3
    First I tried to create it using just

    (PDFontType3) PDFontType3.META.createNew();
    

    But obviously I didn't configured anything inside it.
    so I got a

    java.lang.NullPointerException
    at de.intarsys.pdf.font.PDFontType3.getGlyphWidthEncoded(PDFontType3.java:147)

    then I got a pdf with font type3 inside to extract and reuse in another pdf
    but I got this error:

    java.lang.IllegalStateException: You can not merge objects from different documents
    at de.intarsys.pdf.cos.COSIndirectObject.registerWith(COSIndirectObject.java:514)

    Which is quite clear
    so I tried to reconstruct the new Font starting from the old font using this:

            PDFontType3 newfont  = (PDFontType3) PDFontType3.META.createNew();
    
            newfont.setFontMatrix(fontResource.getFontMatrix());
    

    but I got this error:

    java.lang.IllegalStateException: object may only be contained once (use indirect object)
    at de.intarsys.pdf.cos.COSCompositeObject.associate(COSCompositeObject.java:94)
    at de.intarsys.pdf.cos.COSObject.addContainer(COSObject.java:214)

    so now I'm stuck at this point.

    how could I extract type3 fonts and re embed  in another PDF?
    Thanks
    Marco

     
  • Visitor
    Visitor
    2013-02-25

    solved with this:

            PDFontType3 newfont  = (PDFontType3) PDFontType3.META.createFromCos(fontResource.cosGetObject().copyDeep());
    
     
  • mtraut
    mtraut
    2013-02-25

    Hi. Im glad you found a solution to your question - it is the right one!

    You can find an example that uses resources from another PDF file in the "Overlay" example, where a complete page content is drawn on the target page.

    The jPod PDF model is strictly attached to a document (compare the W3C DOM model). To use a part of one document, copy it and attach it to the new document. When making a copy, you must always be aware of the complex internal structure of PD level objects, that for example often have back references or references to some other resources you did not intend to copy.

    BTW. when you have an issue, you should always provide complete context. The constructor (PDFontType3) PDFontType3.META.createNew(); will never result in a NPE. This must be a follow up problem later in the context.