Introduction:
In this article,i am going to explain about how to draw shapes in pdf using iTextsharp pdfwriter.
Main:
The itextsharp pdfwriter object allows us to draw all kind of shapes in pdf document.
for ex,
Document pdfdoc = new Document();
PdfWriter local_writer = PdfWriter.GetInstance(doc, new FileStream(pdfpath + "C:\\Sample.pdf", FileMode.Create));
pdfdoc.Open();
PdfContentByte local_byte = local_writer.DirectContent;
//For Drawing square,
local_byte.MoveTo(70, 200);
local_byte.LineTo(170, 200);
local_byte.LineTo(170, 300);
local_byte.LineTo(70, 300);
local_byte.ClosePathStroke();
for elipse,
local_byte.Rectangle(100f, 200f, 300f, 100f);
local_byte.Stroke();
local_byte.Ellipse(100f, 200f, 400f, 300f);
local_byte.Stroke();
For rectangle and circle,
local_byte.RoundRectangle(100f, 500f, 200f, 200f, 20f);
local_byte.Stroke();
local_byte.Circle(120f, 520f, 20f);
local_byte.Stroke();
local_byte.MoveTo(118f, 520f);
local_byte.LineTo(122f, 520f);
local_byte.Stroke();
local_byte.MoveTo(120f, 518f);
local_byte.LineTo(120f, 522f);
local_byte.Stroke();
Document pdfdoc = new Document(); PdfWriter local_writer = PdfWriter.GetInstance(doc, new FileStream(pdfpath + "C:\\Sample.pdf", FileMode.Create)); pdfdoc.Open(); PdfContentByte local_byte = local_writer.DirectContent; //For Drawing square, local_byte.MoveTo(70, 200); local_byte.LineTo(170, 200); local_byte.LineTo(170, 300); local_byte.LineTo(70, 300); local_byte.ClosePathStroke(); for elipse, local_byte.Rectangle(100f, 200f, 300f, 100f); local_byte.Stroke(); local_byte.Ellipse(100f, 200f, 400f, 300f); local_byte.Stroke(); For rectangle and circle, local_byte.RoundRectangle(100f, 500f, 200f, 200f, 20f); local_byte.Stroke(); local_byte.Circle(120f, 520f, 20f); local_byte.Stroke(); local_byte.MoveTo(118f, 520f); local_byte.LineTo(122f, 520f); local_byte.Stroke(); local_byte.MoveTo(120f, 518f); local_byte.LineTo(120f, 522f); local_byte.Stroke(); |
Conclusion:
Hope this helps,
Happy Coding.
I found an Excellent site for posting your Oytsourcing Projects and Requirements for Free !!
Wow this is a great resource.. I’m enjoying it.. good article
I can’t figure out how to subscribe to the comments via feedburner. I want to keep abrest of this, how do I do that?
Thanks for an idea, you sparked at idea from a perspective I hadn’t considerd before . Now lets see if I can do something productive with it.
My friend referred me to your blog, so I thought I’d come have a read. Very interesting material, will be back for more!
interesting blog. It would be great if you can provide more details about it. Thanks you
Good read … headline catchy … good points, some of which I have learned along the way as well (humility, grace, layoff the controversial stuff). Will share with my colleagues at work as we begin blogging from a corporate perspective. Thanks!
Well, I don’t know if that’s going to work for me, but definitely worked for you!
Excellent post!