You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Roland Detterbeck <ro...@mbsupport.de> on 2018/09/21 11:44:50 UTC

PDFBoxCharsetProvider not found

Hi, when using PDFBox 2 for converting a PDF to PDF/A I get this error:

(same error when creating a new one)

--------------------------------------------------------------

Exception in thread "Root Thread" java.util.ServiceConfigurationError:
java.nio.charset.spi.CharsetProvider: Provider
org.apache.pdfbox.encoding.PDFBoxCharsetProvider not found

               at java.util.ServiceLoader.fail(ServiceLoader.java:239)

               at java.util.ServiceLoader.access$300(ServiceLoader.java:185)

               at
java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:372)

               at
java.util.ServiceLoader$LazyIterator.access$700(ServiceLoader.java:323)

               at
java.util.ServiceLoader$LazyIterator$2.run(ServiceLoader.java:407)

               at java.security.AccessController.doPrivileged(Native Method)

               at
java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:409)

               at java.util.ServiceLoader$1.next(ServiceLoader.java:480)

               at java.nio.charset.Charset$1.getNext(Charset.java:375)

               at java.nio.charset.Charset$1.hasNext(Charset.java:388)

               at java.nio.charset.Charset$2.run(Charset.java:433)

               at java.nio.charset.Charset$2.run(Charset.java:430)

               at java.security.AccessController.doPrivileged(Native Method)

               at
java.nio.charset.Charset.lookupViaProviders(Charset.java:429)

               at java.nio.charset.Charset.lookup2(Charset.java:500)

               at java.nio.charset.Charset.lookup(Charset.java:487)

               at java.nio.charset.Charset.forName(Charset.java:551)

               at
com.sun.org.apache.xml.internal.serializer.Encodings$EncodingInfos.findChars
etNameFor(Encodings.java:386)

               at
com.sun.org.apache.xml.internal.serializer.Encodings$EncodingInfos.findChars
etNameFor(Encodings.java:422)

               at
com.sun.org.apache.xml.internal.serializer.Encodings$EncodingInfos.loadEncod
ingInfo(Encodings.java:450)

               at
com.sun.org.apache.xml.internal.serializer.Encodings$EncodingInfos.<init>(En
codings.java:308)

               at
com.sun.org.apache.xml.internal.serializer.Encodings$EncodingInfos.<init>(En
codings.java:296)

               at
com.sun.org.apache.xml.internal.serializer.Encodings.<clinit>(Encodings.java
:564)

               at
com.sun.org.apache.xml.internal.serializer.ToStream.<init>(ToStream.java:134
)

               at
com.sun.org.apache.xml.internal.serializer.ToXMLStream.<init>(ToXMLStream.ja
va:67)

               at
com.sun.org.apache.xml.internal.serializer.ToUnknownStream.<init>(ToUnknownS
tream.java:143)

               at
com.sun.org.apache.xalan.internal.xsltc.runtime.output.TransletOutputHandler
Factory.getSerializationHandler(TransletOutputHandlerFactory.java:160)

               at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandle
r(TransformerImpl.java:453)

               at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Trans
formerImpl.java:336)

               at
org.apache.xmpbox.xml.XmpSerializer.save(XmpSerializer.java:303)

               at
org.apache.xmpbox.xml.XmpSerializer.serialize(XmpSerializer.java:86)

               at PDFTools.createPDFA(PDFTOOLS:199)

--------------------------------------------------------------

 

Outgoing from this piece of Code (running in an Stored Procedure in an
Oracle Database):

    public static byte[] createPDFA(byte[] pdf) throws Exception {

        ByteArrayOutputStream out = new ByteArrayOutputStream();

        ByteArrayInputStream in = new ByteArrayInputStream(pdf);

        try (PDDocument doc = PDDocument.load(in)) {

            // add XMP metadata

            XMPMetadata xmp = XMPMetadata.createXMPMetadata();

            try {

                DublinCoreSchema dc = xmp.createAndAddDublinCoreSchema();

                dc.setTitle("insert some title"); // xxx

                PDFAIdentificationSchema pdfaid =
xmp.createAndAddPFAIdentificationSchema();

                pdfaid.setPart(3);

                pdfaid.setConformance("B");

                XmpSerializer serializer = new XmpSerializer();

                ByteArrayOutputStream baos = new ByteArrayOutputStream();

                serializer.serialize(xmp, baos, true);

 

                PDMetadata metadata = new PDMetadata(doc);

                metadata.importXMPMetadata(baos.toByteArray());

                doc.getDocumentCatalog().setMetadata(metadata);

            } catch (BadFieldValueException badFieldexception) {

                // can't happen here, as the provided value is valid

               throw new IllegalArgumentException(badFieldexception);

            }

            // sRGB output intent

            InputStream colorProfile =
PDFTools.class.getResourceAsStream("/org/apache/pdfbox/resources/pdfa/sRGB.i
cc");

            PDOutputIntent intent = new PDOutputIntent(doc, colorProfile);

            intent.setInfo("sRGB IEC61966-2.1");

            intent.setOutputCondition("sRGB IEC61966-2.1");

            intent.setOutputConditionIdentifier("sRGB IEC61966-2.1");

            intent.setRegistryName("http://www.color.org");

            doc.getDocumentCatalog().addOutputIntent(intent);

 

            doc.save(out);

        }

        byte[] bytes = out.toByteArray();

        return bytes;

    }

 

I am not sure why the serializer uses PDFBoxCharsetProvider that is not
contained in PDFBox 2.

 

Can anyone help?

Thanks!

Roland

 


Re: PDFBoxCharsetProvider not found

Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Am 21.09.2018 um 13:44 schrieb Roland Detterbeck:
> Hi, when using PDFBox 2 for converting a PDF to PDF/A I get this error:
> 
> (same error when creating a new one)
> 
> --------------------------------------------------------------
> 
> Exception in thread "Root Thread" java.util.ServiceConfigurationError:
> java.nio.charset.spi.CharsetProvider: Provider
> org.apache.pdfbox.encoding.PDFBoxCharsetProvider not found
That class is 1.8.x specific and no longer available in 2.0.x, so that I assume 
that your classpath contains several versions of PDFBox.

Andreas

> 
>                 at java.util.ServiceLoader.fail(ServiceLoader.java:239)
> 
>                 at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
> 
>                 at
> java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:372)
> 
>                 at
> java.util.ServiceLoader$LazyIterator.access$700(ServiceLoader.java:323)
> 
>                 at
> java.util.ServiceLoader$LazyIterator$2.run(ServiceLoader.java:407)
> 
>                 at java.security.AccessController.doPrivileged(Native Method)
> 
>                 at
> java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:409)
> 
>                 at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
> 
>                 at java.nio.charset.Charset$1.getNext(Charset.java:375)
> 
>                 at java.nio.charset.Charset$1.hasNext(Charset.java:388)
> 
>                 at java.nio.charset.Charset$2.run(Charset.java:433)
> 
>                 at java.nio.charset.Charset$2.run(Charset.java:430)
> 
>                 at java.security.AccessController.doPrivileged(Native Method)
> 
>                 at
> java.nio.charset.Charset.lookupViaProviders(Charset.java:429)
> 
>                 at java.nio.charset.Charset.lookup2(Charset.java:500)
> 
>                 at java.nio.charset.Charset.lookup(Charset.java:487)
> 
>                 at java.nio.charset.Charset.forName(Charset.java:551)
> 
>                 at
> com.sun.org.apache.xml.internal.serializer.Encodings$EncodingInfos.findChars
> etNameFor(Encodings.java:386)
> 
>                 at
> com.sun.org.apache.xml.internal.serializer.Encodings$EncodingInfos.findChars
> etNameFor(Encodings.java:422)
> 
>                 at
> com.sun.org.apache.xml.internal.serializer.Encodings$EncodingInfos.loadEncod
> ingInfo(Encodings.java:450)
> 
>                 at
> com.sun.org.apache.xml.internal.serializer.Encodings$EncodingInfos.<init>(En
> codings.java:308)
> 
>                 at
> com.sun.org.apache.xml.internal.serializer.Encodings$EncodingInfos.<init>(En
> codings.java:296)
> 
>                 at
> com.sun.org.apache.xml.internal.serializer.Encodings.<clinit>(Encodings.java
> :564)
> 
>                 at
> com.sun.org.apache.xml.internal.serializer.ToStream.<init>(ToStream.java:134
> )
> 
>                 at
> com.sun.org.apache.xml.internal.serializer.ToXMLStream.<init>(ToXMLStream.ja
> va:67)
> 
>                 at
> com.sun.org.apache.xml.internal.serializer.ToUnknownStream.<init>(ToUnknownS
> tream.java:143)
> 
>                 at
> com.sun.org.apache.xalan.internal.xsltc.runtime.output.TransletOutputHandler
> Factory.getSerializationHandler(TransletOutputHandlerFactory.java:160)
> 
>                 at
> com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandle
> r(TransformerImpl.java:453)
> 
>                 at
> com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Trans
> formerImpl.java:336)
> 
>                 at
> org.apache.xmpbox.xml.XmpSerializer.save(XmpSerializer.java:303)
> 
>                 at
> org.apache.xmpbox.xml.XmpSerializer.serialize(XmpSerializer.java:86)
> 
>                 at PDFTools.createPDFA(PDFTOOLS:199)
> 
> --------------------------------------------------------------
> 
>   
> 
> Outgoing from this piece of Code (running in an Stored Procedure in an
> Oracle Database):
> 
>      public static byte[] createPDFA(byte[] pdf) throws Exception {
> 
>          ByteArrayOutputStream out = new ByteArrayOutputStream();
> 
>          ByteArrayInputStream in = new ByteArrayInputStream(pdf);
> 
>          try (PDDocument doc = PDDocument.load(in)) {
> 
>              // add XMP metadata
> 
>              XMPMetadata xmp = XMPMetadata.createXMPMetadata();
> 
>              try {
> 
>                  DublinCoreSchema dc = xmp.createAndAddDublinCoreSchema();
> 
>                  dc.setTitle("insert some title"); // xxx
> 
>                  PDFAIdentificationSchema pdfaid =
> xmp.createAndAddPFAIdentificationSchema();
> 
>                  pdfaid.setPart(3);
> 
>                  pdfaid.setConformance("B");
> 
>                  XmpSerializer serializer = new XmpSerializer();
> 
>                  ByteArrayOutputStream baos = new ByteArrayOutputStream();
> 
>                  serializer.serialize(xmp, baos, true);
> 
>   
> 
>                  PDMetadata metadata = new PDMetadata(doc);
> 
>                  metadata.importXMPMetadata(baos.toByteArray());
> 
>                  doc.getDocumentCatalog().setMetadata(metadata);
> 
>              } catch (BadFieldValueException badFieldexception) {
> 
>                  // can't happen here, as the provided value is valid
> 
>                 throw new IllegalArgumentException(badFieldexception);
> 
>              }
> 
>              // sRGB output intent
> 
>              InputStream colorProfile =
> PDFTools.class.getResourceAsStream("/org/apache/pdfbox/resources/pdfa/sRGB.i
> cc");
> 
>              PDOutputIntent intent = new PDOutputIntent(doc, colorProfile);
> 
>              intent.setInfo("sRGB IEC61966-2.1");
> 
>              intent.setOutputCondition("sRGB IEC61966-2.1");
> 
>              intent.setOutputConditionIdentifier("sRGB IEC61966-2.1");
> 
>              intent.setRegistryName("http://www.color.org");
> 
>              doc.getDocumentCatalog().addOutputIntent(intent);
> 
>   
> 
>              doc.save(out);
> 
>          }
> 
>          byte[] bytes = out.toByteArray();
> 
>          return bytes;
> 
>      }
> 
>   
> 
> I am not sure why the serializer uses PDFBoxCharsetProvider that is not
> contained in PDFBox 2.
> 
>   
> 
> Can anyone help?
> 
> Thanks!
> 
> Roland
> 
>   
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org