HTML JPG PDF XML DOCX
  Product Family
PDF

Làm việc với Liên kết trong PDF qua .NET SDK

API để làm việc với Liên kết trong tài liệu PDF bằng .NET.

Get Started

Các thao tác phổ biến nhất với Liên kết trong .NET

Cách làm việc với Liên kết trong tài liệu PDF bằng Cloud .NET SDK

Để quản lý Liên kết trong tài liệu PDF qua Cloud .NET SDK, chúng ta sẽ sử dụng Aspose.PDF Cloud .NET SDK Cloud SDK này cho phép bạn dễ dàng xây dựng ứng dụng tạo, chỉnh sửa & chuyển đổi PDF trên đám mây bằng C#, ASP.NET, hoặc các ngôn ngữ .NET khác cho các nền tảng đám mây khác nhau. Mở NuGet trình quản lý gói, tìm kiếm Aspose.PDF Cloud và cài đặt. Bạn cũng có thể sử dụng lệnh sau từ Bảng điều khiển Quản lý Gói.

Lệnh Bảng điều khiển Quản lý Gói


    PM> Install-Package Aspose.Pdf-Cloud
     

Các bước để thêm liên kết sử dụng .NET SDK

Các nhà phát triển Aspose.PDF Cloud có thể dễ dàng tải & thêm liên kết vào tài liệu PDF chỉ với vài dòng mã.

  1. Tạo một đối tượng Cấu hình mới với Ứng dụng Bí mật và Khóa của bạn.
  2. Tạo một đối tượng để kết nối với API Đám mây.
  3. Tải PDF lên lưu trữ đám mây.
  4. Tạo đối tượng chú thích liên kết mới
  5. Thêm một đối tượng chú thích liên kết mới vào PDF trong lưu trữ đám mây bằng cách sử dụng hàm PostPageLinkAnnotationsAsync.
  6. Kiểm tra phản hồi và ghi lại kết quả.
  7. Tải xuống tệp đã cập nhật để sử dụng cục bộ.
 

Mã mẫu này cho thấy cách thêm liên kết vào tài liệu PDF


using Aspose.Pdf.Cloud.Sdk.Model;

namespace Links
{
    public class LinksAdd
    {
        public static async Task Append(string documentName, string outputName, int pageNumber, string LinkAction, string remoteFolder)
        {
		// Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required). 
		pdfApi = new PdfApi(AppSecret, AppSid);

                using (var file = File.OpenRead(Path.Combine(localFolder, documentName)))
		{ // Upload the local PDF to cloud storage folder name.
                    FilesUploadResult uploadResponse = await pdfApi.UploadFileAsync(Path.Combine(remoteFolder, documentName), documentName);
                    Console.WriteLine(uploadResponse.Uploaded[0]);
                }

                // Create link annotation object with supported parameters
                Link link = new Link(LinkAction);

                LinkAnnotation newLink = new LinkAnnotation(
                    new List<Link>() { link },
                    ActionType: LinkActionType.GoToURIAction,
                    Action: LinkAction,
                    Highlighting: LinkHighlightingMode.Invert,
                    Color: new Color(A: 0xFF, R: 0xAA, G: 0x00, B: 0x00),
                    Rect: new Rectangle(LLX: 238, LLY: 488.622, URX: 305, URY: 498.588)
                );

                // Append new link annotation to the PDF on cloud storage.
                AsposeResponse response = await pdfApi.PostPageLinkAnnotationsAsync(documentName, pageNumber, new List<LinkAnnotation>() { newLink }, folder: remoteFolder);

                // Checks the response and logs the result.
                if (response == null)
                    Console.WriteLine("LinksAdd(): Unexpected error!");
                else if (response.Code < 200 || response.Code > 299)
                    Console.WriteLine("LinksAdd(): Failed to append link to the document.");
                else
                { // Downloads the updated file for local use.
                    Console.WriteLine("PagesAdd(): page successfully appended to the document '{0}.", documentName);
                    Stream stream = pdfApi.DownloadFile(Path.Combine(remoteFolder, documentName));
                    using var fileStream = File.Create(Path.Combine(localFolder, "append_links_" + outputName));
                    stream.Position = 0;
                    await stream.CopyToAsync(fileStream);
                    Console.WriteLine("PagesAdd(): File '{0}' successfully downloaded.", "append_links_" + outputName);
                }
            }
        }
    }