使用iTextSharp的画线在PDF文件中的问题

问题描述:

我在asp.net C#中使用iTextSharp的生成PDF文件。我不能够画一条水平线/ verticle线/虚线。

I am generating a pdf file in asp.net c# using itextsharp. i am not able to draw a horizontal line/verticle line/dotted line.

我试着用以下code,我得到没有错误画一条线,但该行也没有得到显示在PDF文件

i tried to draw a line using the following code,i am getting no errors but the line is also not getting displayed in the pdf file

    PdfContentByte cb = wri.DirectContent;
    cb.SetLineWidth(2.0f);   // Make a bit thicker than 1.0 default
    cb.MoveTo(20, pdfDocument.Top - 40f);
    cb.LineTo(400, pdfDocument.Top - 40f);
    cb.Stroke();

什么是在code.Is,因为x和y坐标的位置的问题?我曾用粗糙点,知道PDF格式大致位置,但线在PDF文件从未apears。

What is the problem in the code.Is it because of the position of x y co-ordinates? I had used rough points to know approximate position in pdf,but the line never apears in the pdf file.

我找出来的输出在下面的图像,如图所示。

The output i am looking out for is as shown in image below.

您应该始终确保来为您执行操作的颜色,否则你不会知道你会得到什么(这将是无论从任何进行previous操作)。尝试做cb.setStrokeColor(255,0,0)(纯红色),你想让它,直到你得到你行。

You should always make sure to set the color for the operation that you're performing, otherwise you won't know what you'll get (it will be from whatever previous operation was performed). Try doing cb.setStrokeColor(255, 0, 0) (pure red) until you get your line where you want it.