Bad border of image iTextSharp

六眼飞鱼酱① 提交于 2019-12-22 01:04:32

问题


I use iTextSharp to add images to a pdf-document.

When I add border for image I see one-pixel part of Image (look at the screenshot):

It is visible when I use white color for the border.

How I can remove it?

My code

iTextSharp.text.Rectangle rec = new iTextSharp.text.Rectangle(PageSize.A4);
iTextSharp.text.Document document = new iTextSharp.text.Document(rec);

using (var writer = PdfWriter.GetInstance(document, new FileStream("file.pdf", FileMode.Create)))
        {
            document.Open();
            iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance("picture.jpg");

            pic.ScaleToFit(document.PageSize.Width, document.PageSize.Height);
            pic.SetAbsolutePosition(0, (document.PageSize.Height - pic.ScaledHeight) / 2);

            pic.Border = Image.LEFT_BORDER | Image.TOP_BORDER | Image.RIGHT_BORDER | Image.BOTTOM_BORDER;
            pic.BorderWidthLeft = 20f;
            pic.BorderWidthTop = 20f;
            pic.BorderWidthRight = 20f;
            pic.BorderWidthBottom = 20f;
            pic.BorderColor = new iTextSharp.text.BaseColor(System.Drawing.Color.White);

            document.Add(pic);
            document.Close();
            writer.Close();
        }

来源:https://stackoverflow.com/questions/50320246/bad-border-of-image-itextsharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!