使用iTextSharp的画线在PDF文件中的问题 [英] problem in drawing a line in a pdf file using itextsharp

查看:3725
本文介绍了使用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.

这篇关于使用iTextSharp的画线在PDF文件中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆