HTML
JPG
PDF
XML
DOCX
PDF
如何通过云 .NET SDK 裁剪 PDF
要裁剪 PDF 文档,我们将使用 Aspose.PDF Cloud .NET SDK 此云 SDK 允许您轻松构建基于云的 PDF 创建、编辑和转换应用程序,支持 C#、ASP.NET 或其他 .NET 语言,用于各种云平台。打开 NuGet 包管理器,搜索 Aspose.PDF Cloud 并安装。您还可以在包管理器控制台中使用以下命令。
包管理器控制台命令
PM> Install-Package Aspose.Pdf-Cloud
使用 .NET SDK 裁剪 PDF 的步骤
Aspose.PDF Cloud 开发人员可以通过几行代码轻松加载和裁剪 PDF。
- 将 PDF 文件上传到云。
- 获取页面信息。
- 将页面提取为图像。
- 创建一个新的空 PDF 文档。
- 将图像插入新 PDF 中。
- 下载最终裁剪的 PDF。
使用 .NET 云 SDK 裁剪 PDF
using Aspose.Pdf.Cloud.Sdk.Model;
namespace ChangeLayout
{
public class CropDocumentPage
{
private ChangeLayoutHelper _helper;
public CropDocumentPage(ChangeLayoutHelper helper)
{
_helper = helper;
}
public async Task MakeCropDocumentPage(string document, string outputDocument, int pageNumber, int llx, int lly, int width, int height)
{
await _helper.UploadFile(document);
await _helper.GetPageInfo(document, pageNumber);
string imageFile = await _helper.ExtractPdfPage(document, pageNumber, _helper.config.CROP_PAGE_WIDTH, _helper.config.CROP_PAGE_HEIGHT);
DocumentResponse? newPdf = await _helper.CreatePdfDocument(outputDocument, width, height);
if (newPdf == null)
Console.WriteLine("MakeCropDocumentPage(): Unexpected error - new document is NULL");
else if (newPdf.Code != 200)
Console.WriteLine("MakeCropDocumentPage(): Failed to create new PDF document!");
else
{
AsposeResponse? response = await _helper.InsertPageAsImage(outputDocument, imageFile, llx, lly);
if (response == null)
Console.WriteLine("MakeCropDocumentPage(): Unexpected error - insert image return NULL");
else if (newPdf.Code != 200)
Console.WriteLine("MakeCropDocumentPage(): Failed to insert image to the new PDF document!");
else
{
Console.WriteLine("cropPage(): Page successfully cropped.");
await _helper.DownloadFile(outputDocument, "cropped_");
}
}
}
}
}