Ví dụ mã này cho thấy cách trích xuất tất cả liên kết từ tệp PDF bằng cách sử dụng các tùy chọn tùy chỉnh.
C#
// Khởi tạo Parser với tài liệu PDF
using (Parser parser = new Parser("input.docx"))
{
// Kiểm tra xem trích xuất liên kết có được hỗ trợ không
if (!parser.Features.Hyperlinks)
{
return;
}
// Đặt tùy chọn trích xuất liên kết để thu hẹp kết quả
PageAreaOptions options = new PageAreaOptions(new Rectangle(new Point(380, 90), new Size(150, 50)));
// Trích xuất dữ liệu liên kết từ tài liệu
IEnumerable<PageHyperlinkArea> hyperlinks = parser.GetHyperlinks(options);
// Xử lý danh sách các liên kết đã được trích xuất
foreach (PageHyperlinkArea h in hyperlinks)
{
Console.WriteLine(h.Text);
Console.WriteLine(h.Url);
}
}