ITEXTPDF 5:使用特定字体打印svg

ITEXTPDF 5:使用特定字体打印svg,itext,batik,Itext,Batik,我用的是ItextPdf 5 我有一个带有特定字体的SVG文件(集成在SVG中) 当我打印SVG(使用batik 1.8)时,图形将打印在文档上,但字体被阻止,因此无法选择它们 请参见下面我的java代码: public class ItextPdfSmallTests { @Test public void svgFontsTest() throws IOException, DocumentException, URISyntaxException { St

我用的是ItextPdf 5

我有一个带有特定字体的SVG文件(集成在SVG中)

当我打印SVG(使用batik 1.8)时,图形将打印在文档上,但字体被阻止,因此无法选择它们

请参见下面我的java代码:

public class ItextPdfSmallTests {

    @Test
    public void svgFontsTest() throws IOException, DocumentException, URISyntaxException {
        String RESULT = "C:\\test\\svgFontsTest.pdf";

        Document document = new Document(PageSize.A4, 36, 36, 54, 36);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));

        document.open();
        document.add(new Paragraph("SVG Example"));

        int width = 250;
        int height = 250;
        PdfContentByte cb = writer.getDirectContent();
        PdfTemplate template = cb.createTemplate(width, height);

        PdfPrinterGraphics2D g2 = new PdfPrinterGraphics2D(cb, width, height, new MyFontMapper(), PrinterJob.getPrinterJob());


        PrintTranscoder prm = new PrintTranscoder();
        URI svgFileURI = getClass().getResource("myfont.svg").toURI();
        TranscoderInput ti = new TranscoderInput(svgFileURI.toString());
        prm.transcode(ti, null);

        PageFormat pg = new PageFormat();
        Paper pp = new Paper();
        pp.setSize(width, height);
        pp.setImageableArea(0, 0, width, height);
        pg.setPaper(pp);
        prm.print(g2, pg, 0);
        g2.dispose();

        ImgTemplate img = new ImgTemplate(template);
        document.add(img);
        document.close();
    }


    class MyFontMapper extends DefaultFontMapper {

        @Override
        public BaseFont awtToPdf(java.awt.Font font) {
            try {
                return BaseFont.createFont("AmaticSC-Regular.ttf", BaseFont.WINANSI, false);
            } catch (DocumentException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    }
}
是否可以使其可编辑? 谢谢你的帮助