Пример #1
0
        public iTextSharp.text.Image GetImage(string src,
                                              IDictionary <string, string> h,
                                              ChainedProperties cprops,
                                              IDocListener doc)
        {
            string imgPath = string.Empty;

            if (src.ToLower().Contains("http://") == false)
            {
                imgPath = HttpContext.Current.Request.Url.Scheme + "://" +

                          HttpContext.Current.Request.Url.Authority + src;
            }
            else
            {
                imgPath = src;
            }

            return(iTextSharp.text.Image.GetInstance(imgPath));
        }
Пример #2
0
    Image IImageProvider.GetImage(string src, IDictionary <string, string> attrs, ChainedProperties chain, IDocListener doc)
    {
        //Prepend the src tag with our path. NOTE, when using HTMLWorker.IMG_PROVIDER, HTMLWorker.IMG_BASEURL gets ignored unless you choose to implement it on your own
        src = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\" + src;
        //Get the image. NOTE, this will attempt to download/copy the image, you'd really want to sanity check here
        Image img = Image.GetInstance(src);

        //Make sure we got something
        if (img == null)
        {
            return(null);
        }
        //Determine the usable area of the canvas. NOTE, this doesn't take into account the current "cursor" position so this might create a new blank page just for the image
        float usableW = this.MainDoc.PageSize.Width - (this.MainDoc.LeftMargin + this.MainDoc.RightMargin);
        float usableH = this.MainDoc.PageSize.Height - (this.MainDoc.TopMargin + this.MainDoc.BottomMargin);

        //If the downloaded image is bigger than either width and/or height then shrink it
        if (img.Width > usableW || img.Height > usableH)
        {
            img.ScaleToFit(usableW, usableH);
        }
        //return our image
        return(img);
    }
Пример #3
0
    // alias: using iTextImage = iTextSharp.text.Image;
    public iTextImage GetImage(string src,
                               IDictionary <string, string> attrs,
                               ChainedProperties chain,
                               IDocListener doc)
    {
        Match match;

        // [1]
        if ((match = Base64.Match(src)).Length > 0)
        {
            return(iTextImage.GetInstance(
                       Convert.FromBase64String(match.Groups["data"].Value)
                       ));
        }

        // [2]
        if (!src.StartsWith("http", StringComparison.OrdinalIgnoreCase))
        {
            src = HttpContext.Current.Server.MapPath(
                new Uri(new Uri(BaseUri), src).AbsolutePath
                );
        }
        return(iTextImage.GetInstance(src));
    }
        public Image GetImage(string src, Hashtable h, ChainedProperties cprops, IDocListener doc)
        {
            var fileName = Path.GetFileName(src);

            return(Image.GetInstance(TestUtils.GetPosterPath(fileName)));
        }
Пример #5
0
    public iTextSharp.text.Image GetImage(string src, Dictionary <string, string> imageProperties, ChainedProperties cprops, IDocListener doc)
    {
        string imageLocation = imageProperties["src"].ToString();
        string siteUrl       = HttpContext.Current.Request.Url.AbsoluteUri.Replace(HttpContext.Current.Request.Url.AbsolutePath, "");

        if (siteUrl.EndsWith("/"))
        {
            siteUrl = siteUrl.Substring(0, siteUrl.LastIndexOf("/"));
        }

        iTextSharp.text.Image image = null;

        if (!imageLocation.StartsWith("http:") && !imageLocation.StartsWith("file:") && !imageLocation.StartsWith("https:") && !imageLocation.StartsWith("ftp:"))
        {
            imageLocation = siteUrl + (imageLocation.StartsWith("/") ? "" : "/") + imageLocation;
        }

        return(iTextSharp.text.Image.GetInstance(imageLocation));
    }