How to create a PDF grid and insert a picture in C # _c# tutorial

Source: Internet
Author: User

In this article I'll show you how to programmatically create a grid in a PDF document and insert a picture into a particular grid.

There are some similar solutions on the web, where I chose a free version of the PDF component. After you install the control, create a new project, add the DLL file under the installation directory as a reference to the project, and the namespace, as follows:

Using Spire.pdf;
Using Spire.Pdf.Graphics;
Using Spire.Pdf.Grid;

Next is the detailed steps and code snippets:

Step 1: First create a PDF document and add a new page.

Pdfdocument doc = new pdfdocument ();
Pdfpagebase page = doc. Pages.Add ();

Step 2: Create a grid of one row and two columns.

Pdfgrid Grid = new Pdfgrid ();
Pdfgridrow row = grid. Rows.Add ();
Grid. Columns.Add (2);

Step 3: Set the spacing between the cell border and the fill content.

Grid. style.cellpadding = new Pdfpaddings (1, 1, 1, 1);

Step 4: Set the column width.

Float width = page. Canvas.ClientSize.Width-(grid. Columns.count + 1);
Grid. Columns[0]. width = width * 0.1f;
Grid. COLUMNS[1]. width = width * 0.1f;

Step 5: Load the picture.

Pdfgridcelltextandstylelist lst = new Pdfgridcelltextandstylelist ();
Pdfgridcelltextandstyle Textandstyle = new Pdfgridcelltextandstyle ();
Textandstyle.image=pdfimage.fromfile (@ "C:\Users\Administrator\Pictures\448a5ba8f8851709a1f53e.jpg");

Step 6: Set the size of the picture and insert it into the first cell.

Textandstyle.imagesize = new SizeF (m);
Lst. List.add (Textandstyle);
Row. Cells[0]. Value = LST;

Step 7: Draw the PDF grid at a specific point in the page.

Pdflayoutresult result = grid. Draw (page, new PointF (10, 30));

Step 8: Save and run the PDF file.

Doc. SaveToFile (OutputFile, fileformat.pdf);
System.Diagnostics.Process.Start (outputfile);

Effect Chart:

This spire. The PDF component is based on the. NET Office software Library, as well as other rich features. So for the office development needs of friends, interested in words can be in the official website reference online tutorials.

All code:

Using System;
Using System.Drawing;
Using System.Windows.Forms;
Using Spire.pdf;
Using Spire.Pdf.Graphics;
Using Spire.Pdf.Grid; 
namespace Insert_an_image_to_pdf_grid_cell {public partial class Form1:form {public Form1 () {InitializeComponent ();} private void Button1_Click (object sender, EventArgs e) {string outputfile = "output.pdf";//new PDF document Pdfdocument doc = n
EW pdfdocument (); Add pages Pdfpagebase page = doc.
Pages.Add ();
Create a PDF grid Pdfgrid Grid = new Pdfgrid (); Sets the spacing grid between the cell border and the fill content.
style.cellpadding = new Pdfpaddings (1, 1, 1, 1); Add row Pdfgridrow row = grid.
Rows.Add (); Add column grid.
Columns.Add (2); Float width = page. Canvas.ClientSize.Width-(grid.
Columns.count + 1); Sets the column width grid. Columns[0].
width = width * 0.1f; Grid. COLUMNS[1].
width = width * 0.1f;
Load picture pdfgridcelltextandstylelist lst = new Pdfgridcelltextandstylelist ();
Pdfgridcelltextandstyle Textandstyle = new Pdfgridcelltextandstyle (); Textandstyle.image=pdfimage.fromfile (@ "C:\Users\Administrator\Pictures\448a5ba8f8851709a1f53e.jpg ");
Set Picture size textandstyle.imagesize = new SizeF (50, 50); Lst.
List.add (Textandstyle); Add a picture row to the first cell. Cells[0].
Value = LST; Draws a PDF grid at a specific point in the page pdflayoutresult result = grid.
Draw (page, new PointF (10, 30)); Save and run the PDF file doc.
SaveToFile (OutputFile, fileformat.pdf);
System.Diagnostics.Process.Start (outputfile); }
}
}

The above is a small part of the introduction of C # to create a PDF grid and insert pictures of the method, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.