title: How to add an SVG to a PDF using iText7
body: <p>I need to add an SVG graphic into PDF file.</p>
  
  <p>Is it that possible using iText7?</p>
  
  <p>Using iText5:</p>
  
  <pre><code>BufferedReader in = new BufferedReader(new InputStreamReader(svgUrl.openStream()));
  String xmlParser = XMLResourceDescriptor.getXMLParserClassName();
  
  SVGDocument svgDoc = new SAXSVGDocumentFactory(xmlParser).createSVGDocument(null, in);
  in.close();
  
  
  // Try to read embedded height and width
  float svgWidth = Float.parseFloat(svgDoc.getDocumentElement().getAttribute("width").replaceAll("[^0-9.,]",""));
  float svgHeight = Float.parseFloat(svgDoc.getDocumentElement().getAttribute("height").replaceAll("[^0-9.,]",""));
  
  PdfTemplate svgTempl = PdfTemplate.createTemplate(writer, svgWidth, svgHeight);
  Graphics2D g2d = svgTempl.createGraphics(svgWidth,svgHeight);          
  
  GraphicsNode chartGfx = (new GVTBuilder()).build(new BridgeContext(new UserAgentAdapter()), svgDoc);
  chartGfx.paint(g2d);
  g2d.dispose();
  
  Image img = new ImgTemplate(svgTempl);
  </code></pre>
  
  <p>I found out that in the following page:
  <a href="https://developers.itextpdf.com/examples/tables/clone-pdfptable-and-pdftemplate" rel="nofollow noreferrer">PdfPTable and PdfTemplate</a> </p>
  
  <p>there is a way to create something similar as Template:</p>
  
  <pre><code>PdfFormXObject svgTempl = new PdfFormXObject(new Rectangle(svgWidth, svgHeight));
  </code></pre>
  
  <p>How can I create Graphics2D?</p>