Apr 07, 2017 Report Broken Link.
- Itextsharp Examples
- Itextsharp Pdf Example
- Itextsharp Pdf Download
- Itextsharp Rectangle On Existing Pdf Download
- Itextsharp C# Examples
Active1 year, 4 months ago
here's a simple code:
Download spyro game free. and now, if I do the following:
then I see the rectangle. But I need to set its border width, so I do
and now the rectangle is not visible. Why ?
TonyTony5,5742929 gold badges109109 silver badges201201 bronze badges
4 Answers
The
Rectangle()
method on PdfContentByte
has a couple of overloads and they behave quite differently depending on what you pass in.Your first example is using the very simple overload that just takes 4 floats. If you look at the source for that you'll see that beyond some sanity checking it just writes those coordinates directly to the PDF stream and no actual
Rectangle
objects are created in the process. Later when you call Stroke()
iText writes the stroke command to the stream and that's it. When a PDF renderer (like Adobe's) actually parses the stroke command it looks backwards in the buffer and sees the coordinates that it needs to stroke and performs the action.Your second example uses the much more complex overload that you can see here which takes an actual
Rectangle
object. Besides representing four points in space a Rectangle
has concepts like background colors and borders and, most importantly for you, these borders can be drawn per side and you need to tell it which sides to draw on.For instance, for just left and right you'd do:
And for all borders you'd change it to:
Also, when calling this overload it is actually incorrect to call
Chris HaasChris HaasStroke()
immediately after because this overload takes care of that for you (and might have done it more than once, actually.)40.8k77 gold badges103103 silver badges220220 bronze badges
(an Addendum to @Chris' answer)
If you want to implement your task (to set its border width) using the simple means of the first example, you can explicitly set the width of lines to stroke:
You may want to envelope these lines in
mklmklcb.SaveState() .. cb.RestoreState()
to prevent the changed line width to influence later operations.60.3k1212 gold badges7373 silver badges164164 bronze badges
the function writer is start to write in pdf and rectangle function is create rectangle and stroke is to draw above rectangle specification. so you have to write the stroke() function.
Er. Binod MehtaEr. Binod Mehta
DeviDevi