/// <summary> /// Create an /// <see cref="iText.Kernel.Pdf.Xobject.PdfFormXObject"/> /// tied to the passed /// <c>PdfDocument</c> /// using the SVG processing result. /// </summary> /// <param name="result">Processing result containing the SVG information</param> /// <param name="pdfDocument">pdf that shall contain the image</param> /// <returns>PdfFormXObject instance</returns> public virtual PdfFormXObject CreateXObjectFromProcessingResult(ISvgProcessorResult result, PdfDocument pdfDocument ) { ISvgNodeRenderer topSvgRenderer = result.GetRootRenderer(); float width; float height; float[] wh = SvgConverter.ExtractWidthAndHeight(topSvgRenderer); width = wh[0]; height = wh[1]; PdfFormXObject pdfForm = new PdfFormXObject(new Rectangle(0, 0, width, height)); PdfCanvas canvas = new PdfCanvas(pdfForm, pdfDocument); ResourceResolver tempResolver = new ResourceResolver(null, resourceResolver.GetRetriever()); // TODO DEVSIX-4107 pass the resourceResolver variable (not tempResolver variable) to the // SvgDrawContext constructor so that the SVG inside the SVG is processed. SvgDrawContext context = new SvgDrawContext(tempResolver, result.GetFontProvider()); if (result is SvgProcessorResult) { context.SetCssContext(((SvgProcessorResult)result).GetContext().GetCssContext()); } context.AddNamedObjects(result.GetNamedObjects()); context.PushCanvas(canvas); ISvgNodeRenderer root = new PdfRootSvgNodeRenderer(topSvgRenderer); root.Draw(context); return(pdfForm); }