iTextsharp PDF,背景色缺少文字

时间:2017-06-19 01:39:31

标签: c# itext

我添加了背景颜色(添加了带填充颜色的矩形)和透明度,但添加矩形后,pdf中的现有文本不可见。

这是代码

public static void drawRectangle(PdfContentByte content, float width, float height)
    {
        content.SaveState();
        PdfGState state = new PdfGState();
        state.FillOpacity = 0.5F;
        content.SetGState(state);
        content.Rectangle(0, 0, width, height);
        content.SetColorFill(new BaseColor(255, 255, 0));
        content.Rectangle(0, 0, width, height);
        content.Fill();
        content.RestoreState();
    }

以下是我创建内容字节的方法

Document doc = new Document();
        PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(tBox_pdf.Text, FileMode.Create));
        doc.Open();
        PdfContentByte cb = writer.DirectContent;
        drawRectangle(cb, doc.PageSize.Width, doc.PageSize.Height);

        doc.Close();
        Process.Start(tBox_pdf.Text);

0 个答案:

没有答案
相关问题