PDF (Portable Document Format) is one kind of electronic file format, which can be used on any operation systems. One PDF file can include many contents, such as hyperlink, audio, video and so on.
At present, PDF is widely used to create electronic books or magazines because it can display characters, colors and images as same as original document. Also, font size of some PDF e-books can be adjusted, which can be more convenient for reading.
How to create and edit PDF document? In this post, I will show the basic operation on PDF by using C#, including creating a blank document, adding text and image in it. And I use one component, Spire.PDF to achieve my goal.
At the beginning, I need to add reference in my project, Spire.PDF dll file and system.drawing for setting font color.
Then, let’s go to steps.
- Create a blank PDF document and add one page for it.
- Write text. The texts give a brief description of the following image which I will insert.
- Insert image in PDF and set size for it.
- Save and launch file.
static void Main(string args)
//Create PDF Document and Add Page
PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();
//Write Cue Words
page.Canvas.DrawString(“The following image shows parts of vip cusomters’ information.”,
new PdfFont(PdfFontFamily.TimesRoman, 20f),
PdfImage image = PdfImage.FromFile(@”D:\work\My Documents\vip.bmp”);
float width = image.Width * 0.75f;
float height = image.Height * 0.75f;
float x = (page.Canvas.ClientSize.Width – width) / 2;
page.Canvas.DrawImage(image, x, 60, width, height);
//Save and Launch File
Click Here to learn more about Spire.PDF
Click Here to download Spire.PDF