Exemplo n.º 1
0
 public override IList<IElement> Start(IWorkerContext ctx, Tag tag)
 {
     List<IElement> l = new List<IElement>(1);
     try
     {
         IDictionary<String, String> css = tag.CSS;
         if (css.ContainsKey(CSS.Property.BACKGROUND_COLOR))
         {
             Type type = typeof(PdfWriterPipeline);
             MapContext pipeline = (MapContext)ctx.Get(type.FullName);
             if (pipeline != null)
             {
                 Document document = (Document)pipeline[PdfWriterPipeline.DOCUMENT];
                 if (document != null)
                 {
                     Rectangle rectangle = new Rectangle(document.Left, document.Bottom, document.Right, document.Top, document.PageSize.Rotation);
                     rectangle.BackgroundColor = HtmlUtilities.DecodeColor(css[CSS.Property.BACKGROUND_COLOR]);
                     PdfBody body = new PdfBody(rectangle);
                     l.Add(body);
                 }
             }
         }
     }
     catch (NoCustomContextException e)
     {}
     
     return l;
 }
Exemplo n.º 2
0
        public override IList <IElement> Start(IWorkerContext ctx, Tag tag)
        {
            List <IElement> l = new List <IElement>(1);

            try
            {
                IDictionary <String, String> css = tag.CSS;
                if (css.ContainsKey(CSS.Property.BACKGROUND_COLOR))
                {
                    Type       type     = typeof(PdfWriterPipeline);
                    MapContext pipeline = (MapContext)ctx.Get(type.FullName);
                    if (pipeline != null)
                    {
                        Document document = (Document)pipeline[PdfWriterPipeline.DOCUMENT];
                        if (document != null)
                        {
                            Rectangle rectangle = new Rectangle(document.Left, document.Bottom, document.Right, document.Top, document.PageSize.Rotation);
                            rectangle.BackgroundColor = HtmlUtilities.DecodeColor(css[CSS.Property.BACKGROUND_COLOR]);
                            PdfBody body = new PdfBody(rectangle);
                            l.Add(body);
                        }
                    }
                }
            }
            catch (NoCustomContextException e)
            {}

            return(l);
        }
Exemplo n.º 3
0
 public virtual ICustomContext GetLocalContext(IWorkerContext context)
 {
     try {
         ICustomContext cc = context.Get(GetContextKey());
         if (null != cc)
         {
             return(cc);
         }
         throw new PipelineException(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.OWN_CONTEXT_404), this.GetType().FullName));
     } catch (NoCustomContextException e) {
         throw new PipelineException(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.OWN_CONTEXT_404), this.GetType().FullName), e);
     }
 }
Exemplo n.º 4
0
        /*
         * (non-Javadoc)
         *
         * @see
         * com.itextpdf.tool.xml.pipeline.AbstractPipeline#close(com.itextpdf.tool
         * .xml.Tag, com.itextpdf.tool.xml.pipeline.ProcessObject)
         */
        public override IPipeline Close(IWorkerContext context, Tag t, ProcessObject po)
        {
            String tagName = t.Name;

            if (tag.Equals(tagName))
            {
                MapContext cc;
                try {
                    cc = (MapContext)context.Get(typeof(PdfWriterPipeline).FullName);
                    Document d = (Document)cc[PdfWriterPipeline.DOCUMENT];
                    d.Close();
                } catch (NoCustomContextException e) {
                    throw new PipelineException("AutoDocPipeline depends on PdfWriterPipeline.", e);
                }
                try {
                    HtmlPipelineContext hpc   = (HtmlPipelineContext)context.Get(typeof(HtmlPipeline).FullName);
                    HtmlPipelineContext clone = (HtmlPipelineContext)hpc.Clone();
                    clone.SetPageSize(pagesize);
                    ((WorkerContextImpl)context).Put(typeof(HtmlPipeline).FullName, clone);
                } catch (NoCustomContextException) {
                }
            }
            return(GetNext());
        }
Exemplo n.º 5
0
 /**
  * Utility method that fetches the CSSResolver from the if any and if it uses the default key.
  *
  * @return CSSResolver
  * @throws NoCustomContextException if the context of the
  *             {@link CssResolverPipeline} could not be found.
  */
 public virtual ICSSResolver GetCSSResolver(IWorkerContext context)
 {
     return(((ObjectContext <ICSSResolver>)context.Get(typeof(CssResolverPipeline).FullName)).Get());
     //return (ICSSResolver) ((MapContext)ctx.Get(typeof(CssResolverPipeline).FullName))[CssResolverPipeline.CSS_RESOLVER];
 }
Exemplo n.º 6
0
 /**
  * Utility method that fetches the HtmlPipelineContext used if any and if it
  * uses the default key.
  * @return a HtmlPipelineContext
  * @throws NoCustomContextException if the context of the
  *             {@link HtmlPipelineContext} could not be found.
  */
 public virtual HtmlPipelineContext GetHtmlPipelineContext(IWorkerContext ctx)
 {
     return((HtmlPipelineContext)ctx.Get(typeof(HtmlPipeline).FullName));
 }
Exemplo n.º 7
0
        /*
         * (non-Javadoc)
         *
         * @see
         * com.itextpdf.tool.xml.pipeline.AbstractPipeline#open(com.itextpdf.tool
         * .xml.Tag, com.itextpdf.tool.xml.pipeline.ProcessObject)
         */
        public override IPipeline Open(IWorkerContext context, Tag t, ProcessObject po)
        {
            try {
                String tagName = t.Name;
                if (tag.Equals(tagName)) {
                    MapContext cc;
                    cc = (MapContext) context.Get(typeof(PdfWriterPipeline).FullName);
                    Document d = new Document(pagesize);
                    try {
                        Stream os = fm.GetStream();
                        cc[PdfWriterPipeline.DOCUMENT] = d;
                        cc[PdfWriterPipeline.WRITER] = PdfWriter.GetInstance(d, os);
                    } catch (IOException e) {
                        throw new PipelineException(e);
                    } catch (DocumentException e) {
                        throw new PipelineException(e);
                    }

                }
                if (Util.EqualsIgnoreCase(t.Name, opentag)) {
                    MapContext cc;
                    cc = (MapContext) context.Get(typeof(PdfWriterPipeline).FullName);
                    Document d = (Document) cc[PdfWriterPipeline.DOCUMENT];
                    CssUtils cssUtils = CssUtils.GetInstance();
                    float pageWidth = d.PageSize.Width;
                    float marginLeft = 0;
                    float marginRight = 0;
                    float marginTop = 0;
                    float marginBottom = 0;
                    IDictionary<String, String> css = t.CSS;
                    foreach (KeyValuePair<String, String> entry in css) {
                        String key = entry.Key;
                        String value = entry.Value;
                        if (Util.EqualsIgnoreCase(key, CSS.Property.MARGIN_LEFT)) {
                            marginLeft = cssUtils.ParseValueToPt(value, pageWidth);
                        } else if (Util.EqualsIgnoreCase(key, CSS.Property.MARGIN_RIGHT)) {
                            marginRight = cssUtils.ParseValueToPt(value, pageWidth);
                        } else if (Util.EqualsIgnoreCase(key, CSS.Property.MARGIN_TOP)) {
                            marginTop = cssUtils.ParseValueToPt(value, pageWidth);
                        } else if (Util.EqualsIgnoreCase(key, CSS.Property.MARGIN_BOTTOM)) {
                            marginBottom = cssUtils.ParseValueToPt(value, pageWidth);
                        }
                    }
                    d.SetMargins(marginLeft, marginRight, marginTop, marginBottom);
                    d.Open();

                }
            } catch (NoCustomContextException e) {
                throw new PipelineException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.PIPELINE_AUTODOC), e);
            }

            return GetNext();
        }
Exemplo n.º 8
0
 /*
  * (non-Javadoc)
  *
  * @see
  * com.itextpdf.tool.xml.pipeline.AbstractPipeline#close(com.itextpdf.tool
  * .xml.Tag, com.itextpdf.tool.xml.pipeline.ProcessObject)
  */
 public override IPipeline Close(IWorkerContext context, Tag t, ProcessObject po)
 {
     String tagName = t.Name;
     if (tag.Equals(tagName)) {
         MapContext cc;
         try {
             cc = (MapContext) context.Get(typeof(PdfWriterPipeline).FullName);
             Document d = (Document) cc[PdfWriterPipeline.DOCUMENT];
             d.Close();
         } catch (NoCustomContextException e) {
             throw new PipelineException("AutoDocPipeline depends on PdfWriterPipeline.", e);
         }
         try {
             HtmlPipelineContext hpc = (HtmlPipelineContext) context.Get(typeof(HtmlPipeline).FullName);
             HtmlPipelineContext clone = (HtmlPipelineContext)hpc.Clone();
             clone.SetPageSize(pagesize);
             ((WorkerContextImpl)context).Put(typeof(HtmlPipeline).FullName, clone);
         } catch (NoCustomContextException) {
         }
     }
     return GetNext();
 }
Exemplo n.º 9
0
 /**
  * Utility method that fetches the HtmlPipelineContext used if any and if it
  * uses the default key.
  * @return a HtmlPipelineContext
  * @throws NoCustomContextException if the context of the
  *             {@link HtmlPipelineContext} could not be found.
  */
 public virtual HtmlPipelineContext GetHtmlPipelineContext(IWorkerContext ctx) {
     return (HtmlPipelineContext) ctx.Get(typeof(HtmlPipeline).FullName);
 }
Exemplo n.º 10
0
 /**
  * Utility method that fetches the CSSResolver from the if any and if it uses the default key.
  *
  * @return CSSResolver
  * @throws NoCustomContextException if the context of the
  *             {@link CssResolverPipeline} could not be found.
  */
 public virtual ICSSResolver GetCSSResolver(IWorkerContext context) {
     return ((ObjectContext<ICSSResolver>)context.Get(typeof(CssResolverPipeline).FullName)).Get();
     //return (ICSSResolver) ((MapContext)ctx.Get(typeof(CssResolverPipeline).FullName))[CssResolverPipeline.CSS_RESOLVER];
 }
Exemplo n.º 11
0
 public virtual ICustomContext GetLocalContext(IWorkerContext context) {
     try {
         ICustomContext cc = context.Get(GetContextKey());
         if (null != cc) {
             return cc;
         }
         throw new PipelineException(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.OWN_CONTEXT_404), this.GetType().FullName));
     } catch (NoCustomContextException e) {
         throw new PipelineException(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.OWN_CONTEXT_404), this.GetType().FullName), e);
     }
 }
Exemplo n.º 12
0
        /*
         * (non-Javadoc)
         *
         * @see
         * com.itextpdf.tool.xml.pipeline.AbstractPipeline#open(com.itextpdf.tool
         * .xml.Tag, com.itextpdf.tool.xml.pipeline.ProcessObject)
         */
        public override IPipeline Open(IWorkerContext context, Tag t, ProcessObject po)
        {
            try {
                String tagName = t.Name;
                if (tag.Equals(tagName))
                {
                    MapContext cc;
                    cc = (MapContext)context.Get(typeof(PdfWriterPipeline).FullName);
                    Document d = new Document(pagesize);
                    try {
                        Stream os = fm.GetStream();
                        cc[PdfWriterPipeline.DOCUMENT] = d;
                        cc[PdfWriterPipeline.WRITER]   = PdfWriter.GetInstance(d, os);
                    } catch (IOException e) {
                        throw new PipelineException(e);
                    } catch (DocumentException e) {
                        throw new PipelineException(e);
                    }
                }
                if (Util.EqualsIgnoreCase(t.Name, opentag))
                {
                    MapContext cc;
                    cc = (MapContext)context.Get(typeof(PdfWriterPipeline).FullName);
                    Document d                       = (Document)cc[PdfWriterPipeline.DOCUMENT];
                    CssUtils cssUtils                = CssUtils.GetInstance();
                    float    pageWidth               = d.PageSize.Width;
                    float    marginLeft              = 0;
                    float    marginRight             = 0;
                    float    marginTop               = 0;
                    float    marginBottom            = 0;
                    IDictionary <String, String> css = t.CSS;
                    foreach (KeyValuePair <String, String> entry in css)
                    {
                        String key   = entry.Key;
                        String value = entry.Value;
                        if (Util.EqualsIgnoreCase(key, CSS.Property.MARGIN_LEFT))
                        {
                            marginLeft = cssUtils.ParseValueToPt(value, pageWidth);
                        }
                        else if (Util.EqualsIgnoreCase(key, CSS.Property.MARGIN_RIGHT))
                        {
                            marginRight = cssUtils.ParseValueToPt(value, pageWidth);
                        }
                        else if (Util.EqualsIgnoreCase(key, CSS.Property.MARGIN_TOP))
                        {
                            marginTop = cssUtils.ParseValueToPt(value, pageWidth);
                        }
                        else if (Util.EqualsIgnoreCase(key, CSS.Property.MARGIN_BOTTOM))
                        {
                            marginBottom = cssUtils.ParseValueToPt(value, pageWidth);
                        }
                    }
                    d.SetMargins(marginLeft, marginRight, marginTop, marginBottom);
                    d.Open();
                }
            } catch (NoCustomContextException e) {
                throw new PipelineException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.PIPELINE_AUTODOC), e);
            }

            return(GetNext());
        }
 /**
  * Utility method that fetches the HtmlPipelineContext used if any and if it
  * uses the default key.
  * @param context the WorkerContext
  * @return a HtmlPipelineContext
  * @throws NoCustomContextException if the context of the
  *             {@link HtmlPipelineContext} could not be found.
  */
 public SvgPipelineContext GetSvgPipelineContext(IWorkerContext context)
 {
     return((SvgPipelineContext)context.Get(typeof(SvgPipeline).FullName));
 }
 /**
  * Utility method that fetches the CSSResolver from the if any and if it uses the default key.
  * @param context the WorkerContext
  *
  * @return CSSResolver
  * @throws NoCustomContextException if the context of the
  *             {@link CssResolverPipeline} could not be found.
  */
 //@SuppressWarnings("unchecked")
 public ICSSResolver GetCSSResolver(IWorkerContext context)
 {
     return(((ObjectContext <ICSSResolver>)context.Get(typeof(CssResolverPipeline).FullName)).Get());
 }