HTML
JPG
PDF
XML
DOCX
PDF
Cách xóa trang khỏi tài liệu PDF bằng Cloud .NET SDK
Để xóa trang khỏi tài liệu PDF qua Cloud .NET SDK, chúng ta sẽ sử dụng Aspose.PDF Cloud .NET SDK SDK đám mây này cho phép bạn dễ dàng xây dựng các ứng dụng tạo, chỉnh sửa và chuyển đổi PDF trên nền tảng đám mây bằng C#, ASP.NET, hoặc các ngôn ngữ .NET khác cho nhiều nền tảng đám mây. 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 xóa trang bằng .NET SDK
Các nhà phát triển Aspose.PDF Cloud có thể dễ dàng tải và xóa trang khỏi tài liệu PDF chỉ trong vài dòng mã.
- Tạo một đối tượng Cấu hình mới với Bí mật Ứng dụng và Khóa của bạn.
- Tạo một đối tượng để kết nối với API Đám mây.
- Tải lên PDF lên lưu trữ đám mây.
- Xóa trang khỏi PDF trong lưu trữ đám mây.
- Kiểm tra phản hồi và ghi lại kết quả.
- 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 xóa các trang khỏi tài liệu PDF
using Aspose.Pdf.Cloud.Sdk.Model;
namespace Pages
{
public class PagesDelete
{
public static async Task Delete(string documentName, string outputName, int pageNumber, string localFolder, 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]);
}
// Delete page from the PDF on cloud storage.
AsposeResponse response = await pdfApi.DeletePageAsync(documentName, pageNumber, folder: remoteFolder);
// Checks the response and logs the result.
if (response == null)
Console.WriteLine("PagesDelete(): Unexpected error!");
else if (response.Code < 200 || response.Code > 299)
Console.WriteLine("PagesDelete(): Failed to delete page from the document.");
else
{ // Downloads the updated file for local use.
Console.WriteLine("PagesDelete(): page successfully deleted from the document '{0}.", documentName);
Stream stream = pdfApi.DownloadFile(Path.Combine(remoteFolder, documentName));
using var fileStream = File.Create(Path.Combine(localFolder, "delete_pages_" + outputName));
stream.Position = 0;
await stream.CopyToAsync(fileStream);
Console.WriteLine("PagesDelete(): File '{0}' successfully downloaded.", "delete_pages_" + outputName);
}
}
}
}