Share itextsharp vb.net,

tranphuongfirst

New member
#itextsharp, #vb.net, #pdf, #Document Generation, #Print

ITEXTSHARP là một thư viện nguồn mở và miễn phí để tạo các tài liệu PDF trong .NET.Đây là một công cụ mạnh mẽ và đa năng có thể được sử dụng để tạo các tệp PDF từ nhiều nguồn khác nhau, bao gồm văn bản, hình ảnh và bảng tính.ITEXTSHARP rất dễ sử dụng và có thể được tích hợp với bất kỳ ứng dụng .NET nào.

Hướng dẫn này sẽ chỉ cho bạn cách bắt đầu với ITEXTSHARP trong vb.net.Chúng tôi sẽ bao gồm những điều cơ bản của việc tạo tài liệu PDF, bao gồm thêm văn bản, hình ảnh và bảng.Chúng tôi cũng sẽ chỉ cho bạn cách xuất dữ liệu từ cơ sở dữ liệu sang tài liệu PDF.

Đến cuối hướng dẫn này, bạn sẽ có thể tạo các tài liệu PDF với ITEXTSHARP trong VB.NET.

## Bắt đầu với ITEXTSHARP

Bước đầu tiên là cài đặt thư viện ITEXTSHARP.Bạn có thể tải xuống phiên bản mới nhất từ trang web ITEXT.

Khi bạn đã cài đặt thư viện, bạn có thể thêm nó vào dự án của mình.Trong Visual Studio, nhấp chuột phải vào dự án của bạn và chọn "Thêm tham chiếu".Trong hộp thoại "Trình quản lý tham chiếu", nhấp vào nút "Duyệt" và định vị cụm ITEXTSHARP.Chọn lắp ráp và nhấp vào nút "Thêm".

Bây giờ bạn đã thêm thư viện ITEXTSHARP vào dự án của mình, bạn có thể bắt đầu sử dụng nó để tạo tài liệu PDF.

## Tạo tài liệu PDF

Để tạo tài liệu PDF, trước tiên bạn cần tạo đối tượng `document`.Bạn có thể làm điều này bằng cách gọi phương thức `new` của lớp` document`.

`` `
Tài liệu dim là tài liệu mới ()
`` `

Đối tượng `Document` đại diện cho một tài liệu PDF.Bạn có thể sử dụng nó để thêm nội dung vào tài liệu, chẳng hạn như văn bản, hình ảnh và bảng.

## Thêm nội dung vào tài liệu PDF

Bạn có thể thêm nội dung vào tài liệu PDF bằng cách sử dụng phương thức `add ()` của đối tượng `document`.Phương thức `add ()` lấy đối tượng `pdfcontentByte` làm đối số của nó.Đối tượng `pdfcontentByte` đại diện cho nội dung của tài liệu PDF.Bạn có thể sử dụng đối tượng `pdfcontentByte` để thêm văn bản, hình ảnh và bảng vào tài liệu PDF.

Để thêm văn bản vào tài liệu PDF, bạn có thể sử dụng phương thức `write ()` của đối tượng `pdfcontentByte`.Phương thức `write ()` lấy một chuỗi làm đối số của nó.

`` `
Document.Add (PDFContentByte.Createtext (100, 100, "Hello World")))
`` `

Mã này sẽ thêm văn bản "Hello World" vào tài liệu PDF tại tọa độ (100, 100).

Bạn cũng có thể thêm hình ảnh vào tài liệu PDF.Để làm điều này, bạn có thể sử dụng phương thức `addimage ()` của đối tượng `pdfcontentByte`.Phương thức `addImage ()` lấy đối tượng `pdfimage` làm đối số của nó.Đối tượng `pdfimage` đại diện cho một hình ảnh.Bạn có thể tạo đối tượng `pdfimage` từ một tệp hoặc từ mảng byte.

`` `
Hình ảnh mờ như pdfimage mới (file.openread ("Image.png")))
document.add (pdfcontentByte.CreateImage (hình ảnh, 100, 100)))
`` `

Mã này sẽ thêm hình ảnh "Image.png" vào tài liệu PDF tại tọa độ (100, 100).

Bạn cũng có thể thêm bảng vào tài liệu PDF.Để làm điều này, bạn có thể sử dụng phương thức `addTable ()` của đối tượng `document`.Phương thức `addTable ()` lấy một đối tượng `pdftable` làm đối số của nó.Một đối tượng `pdftable` đại diện cho một bảng.Bạn có thể tạo một đối tượng `pdftable` bằng cách chỉ định số lượng hàng và cột trong bảng.

`` `
Bảng mờ như pdftable mới (5, 3)
document.add (bảng)
`` `

Mã này sẽ tạo một bảng với 5 hàng và 3 cột.

Sau đó, bạn có thể thêm các ô vào bảng bằng cách sử dụng phương thức `addCell ()` của đối tượng `pdftable`.Phương thức `addCell ()`
=======================================
#itextsharp, #vb.net, #pdf, #Document generation, #printing ### iTextsharp VB.NET: A Beginner's Guide

iTextsharp is a free and open-source library for generating PDF documents in .NET. It is a powerful and versatile tool that can be used to create PDFs from a variety of sources, including text, images, and spreadsheets. iTextsharp is easy to use and can be integrated with any .NET application.

This guide will show you how to get started with iTextsharp in VB.NET. We will cover the basics of creating PDF documents, including adding text, images, and tables. We will also show you how to export data from a database to a PDF document.

By the end of this guide, you will be able to create PDF documents with iTextsharp in VB.NET.

## Getting Started with iTextsharp

The first step is to install the iTextsharp library. You can download the latest version from the iText website.

Once you have installed the library, you can add it to your project. In Visual Studio, right-click on your project and select "Add Reference". In the "Reference Manager" dialog box, click on the "Browse" button and locate the iTextsharp assembly. Select the assembly and click on the "Add" button.

Now that you have added the iTextsharp library to your project, you can start using it to create PDF documents.

## Creating a PDF Document

To create a PDF document, you first need to create a `Document` object. You can do this by calling the `New` method of the `Document` class.

```
Dim document As New Document()
```

The `Document` object represents a PDF document. You can use it to add content to the document, such as text, images, and tables.

## Adding Content to a PDF Document

You can add content to a PDF document by using the `Add()` method of the `Document` object. The `Add()` method takes a `PdfContentByte` object as its argument. A `PdfContentByte` object represents the content of a PDF document. You can use a `PdfContentByte` object to add text, images, and tables to a PDF document.

To add text to a PDF document, you can use the `Write()` method of the `PdfContentByte` object. The `Write()` method takes a string as its argument.

```
document.Add(PdfContentByte.CreateText(100, 100, "Hello World"))
```

This code will add the text "Hello World" to the PDF document at the coordinates (100, 100).

You can also add images to a PDF document. To do this, you can use the `AddImage()` method of the `PdfContentByte` object. The `AddImage()` method takes a `PdfImage` object as its argument. A `PdfImage` object represents an image. You can create a `PdfImage` object from a file or from a byte array.

```
Dim image As New PdfImage(File.OpenRead("image.png"))
document.Add(PdfContentByte.CreateImage(image, 100, 100))
```

This code will add the image "image.png" to the PDF document at the coordinates (100, 100).

You can also add tables to a PDF document. To do this, you can use the `AddTable()` method of the `Document` object. The `AddTable()` method takes a `PdfTable` object as its argument. A `PdfTable` object represents a table. You can create a `PdfTable` object by specifying the number of rows and columns in the table.

```
Dim table As New PdfTable(5, 3)
document.Add(table)
```

This code will create a table with 5 rows and 3 columns.

You can then add cells to the table by using the `AddCell()` method of the `PdfTable` object. The `AddCell()` method
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top