I am trying to add SVG as a layer to a PDF.
The code is below. And I attach the SVG and PDF to this post.
- Code: Select all
String licenseKey = ...;
LicenseProvider.setLicenseKey(licenseKey);
String basePdfPath = ...;
String svgPath = ...;
String destPdfPath = ...;
String layerName = "l...;
PdfDocument basePdf = new PdfDocument(basePdfPath);
PdfDocument svg = new PdfDocument();
svg.loadFromSvg(svgPath);
PdfLayer pdfLayer = basePdf.getLayers().addLayer(layerName);
PdfCanvas canvas = pdfLayer.createGraphics(basePdf.getPages().get(0).getCanvas());
canvas.drawTemplate(svg.getPages().get(0).createTemplate(), new Point2D.Float(0, 0));
basePdf.saveToFile(destPdfPath, FileFormat.PDF);
basePdf.clone();
Spire.PDF Version: 10.7.3
OS: Windows 11
1
When I add a layer using the above method, I get an error when I open it in Acrobat Reader.
I was able to view this PDF in Google Chrome.
With PNG, the error does not occur.
Is there any solution?
(It may possibly be a problem with Acrobat Reader.)
2
When I run the above code on Linux and open the PDF with Google Chrome on Windows, Japanese characters are garbled (Tofu characters).
When I convert SVG to PNG in the same environment, the characters are not garbled. I think the font issue in this environment is cleared.
Also, the fonts are installed in the environment where the PDF is displayed.
What could be the cause?