Example #1
0
        /// <exception cref="iText.Svg.Exceptions.SvgProcessingException"/>
        public virtual ISvgProcessorResult Process(INode root, ISvgConverterProperties converterProps)
        {
            if (root == null)
            {
                throw new SvgProcessingException(SvgLogMessageConstant.INODEROOTISNULL);
            }
            if (converterProps == null)
            {
                converterProps = new SvgConverterProperties();
            }
            //Setup processorState
            PerformSetup(root, converterProps);
            //Find root
            IElementNode svgRoot = FindFirstElement(root, SvgConstants.Tags.SVG);

            if (svgRoot != null)
            {
                //Iterate over children
                ExecuteDepthFirstTraversal(svgRoot);
                ISvgNodeRenderer rootSvgRenderer = CreateResultAndClean();
                return(new SvgProcessorResult(namedObjects, rootSvgRenderer, context.GetFontProvider(), context.GetTempFonts
                                                  ()));
            }
            else
            {
                throw new SvgProcessingException(SvgLogMessageConstant.NOROOT);
            }
        }
Example #2
0
        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
                                                                                                       ));
        }
 /// <summary>Load in configuration, set initial processorState and create/fill-in context of the processor</summary>
 /// <param name="converterProps">that contains configuration properties and operations</param>
 internal virtual void PerformSetup(INode root, ISvgConverterProperties converterProps)
 {
     processorState = new ProcessorState();
     if (converterProps.GetRendererFactory() != null) {
         rendererFactory = converterProps.GetRendererFactory();
     }
     context = new SvgProcessorContext(converterProps);
     cssResolver = new SvgStyleResolver(root, context);
     new SvgFontProcessor(context).AddFontFaceFonts(cssResolver);
     //TODO RND-1042
     namedObjects = new Dictionary<String, ISvgNodeRenderer>();
     cssContext = new SvgCssContext();
 }
Example #4
0
        /// <summary>
        /// Instantiates a new
        /// <see cref="SvgProcessorContext"/>
        /// instance.
        /// </summary>
        /// <param name="converterProperties">
        /// a
        /// <see cref="iText.Svg.Processors.ISvgConverterProperties"/>
        /// instance
        /// </param>
        public SvgProcessorContext(ISvgConverterProperties converterProperties)
        {
            deviceDescription = converterProperties.GetMediaDeviceDescription();
            if (deviceDescription == null)
            {
                deviceDescription = MediaDeviceDescription.GetDefault();
            }
            fontProvider = converterProperties.GetFontProvider();
            if (fontProvider == null)
            {
                fontProvider = new BasicFontProvider();
            }
            String baseUri = converterProperties.GetBaseUri();

            if (baseUri == null)
            {
                baseUri = "";
            }
            resourceResolver = new ResourceResolver(baseUri);
        }
Example #5
0
        /// <summary>
        /// Instantiates a new
        /// <see cref="SvgProcessorContext"/>
        /// instance.
        /// </summary>
        /// <param name="converterProperties">
        /// a
        /// <see cref="iText.Svg.Processors.ISvgConverterProperties"/>
        /// instance
        /// </param>
        public SvgProcessorContext(ISvgConverterProperties converterProperties)
        {
            deviceDescription = converterProperties.GetMediaDeviceDescription();
            if (deviceDescription == null)
            {
                deviceDescription = MediaDeviceDescription.GetDefault();
            }
            fontProvider = converterProperties.GetFontProvider();
            if (fontProvider == null)
            {
                fontProvider = new BasicFontProvider();
            }
            IResourceRetriever retriever = null;

            // TODO DEVSIX-3814 change the clause if block to retriever = new ResourceResolver(props.getBaseUri(),
            //  converterProperties.getResourceRetriever()) when the ISvgConverterProperties#getResourceRetriever() is added
            if (converterProperties is SvgConverterProperties)
            {
                retriever = ((SvgConverterProperties)converterProperties).GetResourceRetriever();
            }
            resourceResolver = new ResourceResolver(converterProperties.GetBaseUri(), retriever);
        }
 public virtual void Before()
 {
     properties = new SvgConverterProperties().SetBaseUri(SOURCE_FOLDER);
 }
Example #7
0
 public virtual void Before()
 {
     properties = new SvgConverterProperties().SetBaseUri(sourceFolder);
 }
Example #8
0
 public virtual void ConvertToSinglePage(FileInfo svg, FileInfo pdf, ISvgConverterProperties properties)
 {
     SvgConverter.CreatePdf(svg, pdf, properties);
 }
Example #9
0
 public virtual void ConvertAndCompareSinglePage(String src, String dest, String fileName, ISvgConverterProperties
                                                 properties)
 {
     ConvertToSinglePage(new FileStream(src + fileName + ".svg", FileMode.Open, FileAccess.Read), new FileStream
                             (dest + fileName + ".pdf", FileMode.Create), properties);
     Compare(fileName, src, dest);
 }
Example #10
0
 public virtual void ConvertToSinglePage(Stream svg, Stream pdfOutputStream, ISvgConverterProperties properties
                                         , WriterProperties writerprops)
 {
     SvgConverter.CreatePdf(svg, pdfOutputStream, properties, writerprops);
 }