Hi,
I’m inserting an SVG into a com.aspose.words.Document
using a com.aspose.words.DocumentBuilder
which fails due to
Exception in thread "main" java.lang.NullPointerException
at com.aspose.words.internal.zz9V.zzYd(Unknown Source)
at com.aspose.words.internal.zz1.<init>(Unknown Source)
at com.aspose.words.zzYV5.zzW(Unknown Source)
at com.aspose.words.zzYV5.zzY(Unknown Source)
at com.aspose.words.zzYV5.zzW(Unknown Source)
at com.aspose.words.zzYV5.zzY(Unknown Source)
at com.aspose.words.zzYV5.zzW(Unknown Source)
at com.aspose.words.zzYV5.zzY(Unknown Source)
at com.aspose.words.zzYV5.zzW(Unknown Source)
at com.aspose.words.zzYV5.zzY(Unknown Source)
at com.aspose.words.zzYV1.zzZbB(Unknown Source)
at com.aspose.words.zzZO9.zzY(Unknown Source)
at com.aspose.words.zzZNT.setImageBytes(Unknown Source)
at com.aspose.words.ImageData.setImageBytes(Unknown Source)
at com.aspose.words.DocumentBuilder.insertImage(Unknown Source)
at com.aspose.words.DocumentBuilder.insertImage(Unknown Source)
at com.aspose.words.DocumentBuilder.insertImage(Unknown Source)
at com.orgavision.document.builder.svg.npe.example.DocumentBuilderSvgNpeExample.main(DocumentBuilderSvgNpeExample.java:16)
The relevant code is
String svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" hhead=\"0.0\" viewBox=\"0 0 286.0 168.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"286.0\" vhead=\"0.0\" id=\"59a95bf4-4251-4218-b95a-6a19349b40bb\" fill=\"#FFFFFF\" version=\"1.1\" class=\"svg-diagram svg-diagram-view\" height=\"168.0\"><defs/><g transform=\"translate(0.0,0.0)\"><rect x=\"0\" width=\"286.0\" y=\"0\" fill=\"#FFFFFF\" fill-opacity=\"0.0\" height=\"168.0\"/></g><g transform=\"translate(0.0,0.0)\" id=\"59a95bf4-4251-4218-b95a-6a19349b40bb_lanes\" class=\"svg-diagram-lanes\"></g><g transform=\"translate(0.0,0.0)\" id=\"59a95bf4-4251-4218-b95a-6a19349b40bb_grid\" class=\"svg-diagram-grid\"><g column=\"0.0\" row=\"0.0\" class=\"svg-diagram-cell\"><g transform=\"translate(42.0,42.0)\" id=\"6452cd63-3d91-4d96-b988-0281c8252f7c\" type=\"reference\" class=\"svg-diagram-node\"><rect x=\"0\" width=\"160.0\" y=\"0\" stroke-dasharray=\"none\" stroke-width=\"1.0\" fill=\"#FFFFFF\" stroke=\"#B4B4B4\" class=\"svg-diagram-fill svg-diagram-stroke\" height=\"42.0\"/><g transform=\"translate(7.0,7.0)\" class=\"svg-diagram-icon\"><g transform=\"scale(0.5,0.5)\"><path class=\"svg-diagram-fill\" fill=\"#003F66\" d=\"M3.781,1.994h14.045l6.393,6.329v17.683H3.781V1.994z M6.502,4.519v19.004h15.007v-11.38h-7.822v-7.624H6.502z M16.363,4.28v5.146h5.146L16.363,4.28z\"/><rect class=\"svg-diagram-fill\" fill=\"#003F66\" x=\"8.016\" y=\"6.16\" width=\"4.233\" height=\"2.698\"/><rect class=\"svg-diagram-fill\" fill=\"#003F66\" x=\"8.014\" y=\"13.745\" width=\"12.057\" height=\"1.282\"/><rect class=\"svg-diagram-fill\" fill=\"#003F66\" x=\"8.014\" y=\"17.094\" width=\"12.057\" height=\"1.282\"/><rect class=\"svg-diagram-fill\" fill=\"#003F66\" x=\"7.996\" y=\"20.469\" width=\"12.056\" height=\"1.282\"/></g></g><a ref=\"f52584a8-bf15-4ec6-a54d-c642e47eb816\" class=\"svg-diagram-selectable\"><text transform=\"translate(28.0,7.0)\" font-weight=\"normal\" font-size=\"10.0px\" font-family=\"Montserrat, Helvetica, Arial, sans-serif\" fill=\"#000000\"><tspan x=\"0\" y=\"10.0\">fdsafdsaf</tspan></text></a></g></g></g><g transform=\"translate(0.0,0.0)\" id=\"59a95bf4-4251-4218-b95a-6a19349b40bb_net\" class=\"svg-diagram-net\"/></svg>";
Document document = new Document();
DocumentBuilder documentBuilder = new DocumentBuilder(document);
documentBuilder.insertImage(svg.getBytes());
File tmpFile = Files.createTempFile(DocumentBuilderSvgNpeExample.class.getSimpleName(), ".pdf").toFile();
document.save(tmpFile.getAbsolutePath(), new PdfSaveOptions());
I have attached a zipped SSCCE for reproduction.
Best regards
Kalle Richter