Bad border of image iTextSharp

2019-04-17 10:12发布

问题:

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();
        }
标签: c# itext