public virtual void AttemptToProcessBySvgProcessingUtilSvgWithSvgTest() { // TODO review this test in the scope of DEVSIX-4107 String fileName = "svgWithSvg.svg"; ProcessorContext context = new ProcessorContext(new ConverterProperties()); HtmlResourceResolver resourceResolver = new HtmlResourceResolver(sourceFolder, context); ISvgConverterProperties svgConverterProperties = ContextMappingHelper.MapToSvgConverterProperties(context); ISvgProcessorResult res = SvgConverter.ParseAndProcess(resourceResolver.RetrieveResourceAsInputStream(fileName ), svgConverterProperties); ISvgNodeRenderer imageRenderer = ((SvgTagSvgNodeRenderer)res.GetRootRenderer()).GetChildren()[1]; // Remove the previous result of the resource resolving in order to demonstrate that the resource will not be // resolved due to not setting of baseUri in the SvgProcessingUtil#createXObjectFromProcessingResult method. // But even if set baseUri in the SvgProcessingUtil#createXObjectFromProcessingResult method, the SVG will not // be processed, because in the createXObjectFromProcessingResult method we create ResourceResolver, not HtmlResourceResolver. imageRenderer.SetAttribute(SvgConstants.Attributes.XLINK_HREF, "res\\itextpdf.com\\lines.svg"); SvgProcessingUtil processingUtil = new SvgProcessingUtil(resourceResolver); PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new ByteArrayOutputStream())); PdfFormXObject pdfFormXObject = processingUtil.CreateXObjectFromProcessingResult(res, pdfDocument); PdfDictionary resources = (PdfDictionary)pdfFormXObject.GetResources().GetPdfObject().Get(PdfName.XObject); PdfDictionary fm1Dict = (PdfDictionary)resources.Get(new PdfName("Fm1")); NUnit.Framework.Assert.IsFalse(((PdfDictionary)fm1Dict.Get(PdfName.Resources)).ContainsKey(PdfName.XObject )); }
/// <exception cref="System.IO.IOException"/> private PdfFormXObject ProcessAsSvg(Stream stream, ProcessorContext context) { SvgProcessingUtil processingUtil = new SvgProcessingUtil(); SvgConverterProperties svgConverterProperties = new SvgConverterProperties(); svgConverterProperties.SetBaseUri(context.GetBaseUri()).SetFontProvider(context.GetFontProvider()).SetMediaDeviceDescription (context.GetDeviceDescription()); ISvgProcessorResult res = SvgConverter.ParseAndProcess(stream, svgConverterProperties); if (context.GetPdfDocument() != null) { return(processingUtil.CreateXObjectFromProcessingResult(res, context.GetPdfDocument())); } else { return(null); } }
/// <exception cref="System.IO.IOException"/> private PdfFormXObject ProcessAsSvg(Stream stream, ProcessorContext context, String parentDir) { SvgProcessingUtil processingUtil = new SvgProcessingUtil(); SvgConverterProperties svgConverterProperties = ContextMappingHelper.MapToSvgConverterProperties(context); if (parentDir != null) { svgConverterProperties.SetBaseUri(parentDir); } ISvgProcessorResult res = SvgConverter.ParseAndProcess(stream, svgConverterProperties); if (context.GetPdfDocument() != null) { return(processingUtil.CreateXObjectFromProcessingResult(res, context.GetPdfDocument())); } else { return(null); } }