HTML JPG PDF XML DOCX
  Product Family
PDF

Thay đổi kích thước PDF trong .NET SDK

API để làm việc với thay đổi kích thước tài liệu PDF bằng .NET.

Get Started

Cách thay đổi kích thước PDF qua Cloud .NET SDK

Để thay đổi kích thước tài liệu PDF, chúng tôi 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 dựa 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 để thay đổi kích thước PDF bằng .NET SDK

Các nhà phát triển Aspose.PDF Cloud có thể dễ dàng tải & thay đổi kích thước PDF chỉ trong vài dòng mã.

  1. Tải lên PDF.
  2. Chuyển đổi nó thành HTML (giữ nguyên cấu trúc/nội dung).
  3. Chuyển đổi HTML trở lại thành một PDF mới với kích thước được chỉ định.
  4. Tải xuống tài liệu đã thay đổi kích thước.
 

Thay đổi kích thước PDF bằng .NET Cloud SDK


    using Aspose.Pdf.Cloud.Sdk.Model;


    namespace ChangeLayout
    {
        public class ResizeDocumentAllPages
        {
            private ChangeLayoutHelper _helper;

            public ResizeDocumentAllPages(ChangeLayoutHelper helper)
            {
                _helper = helper;
            }

            public async Task MakeResizeDocumentAllPages(string document, string htmlTempDoc, int pageWidth, int pageHeight)
            {
                await _helper.UploadFile(document);
                string htmlTempPath = Path.Combine(_helper.config.REMOTE_TEMP_FOLDER, htmlTempDoc);
                AsposeResponse response = await _helper.pdfApi.PutPdfInStorageToHtmlAsync(
                    document, htmlTempPath,
                    documentType: HtmlDocumentType.Xhtml.ToString(),
                    outputFormat: OutputFormat.Folder.ToString(),
                    folder: _helper.config.REMOTE_TEMP_FOLDER
                );
                if (response == null)
                    Console.WriteLine("MakeResizeDocumentAllPages(): Unexpected error - no response in Pdf to Html convert!");
                else if (response.Code != 200)
                    Console.WriteLine("MakeResizeDocumentAllPages(): Error -> Code {0} -> Status '{1}'", [response.Code, response.Status]);
                else
                {
                    Console.WriteLine("MakeResizeDocumentAllPages(): temporary file '{0}' successfully created.", htmlTempDoc);
                    string outputDocument = "resized_" + document;
                    await _helper.pdfApi.PutHtmlInStorageToPdfAsync(
                        outputDocument, htmlTempPath,
                        dstFolder: _helper.config.REMOTE_TEMP_FOLDER,
                        htmlFileName: htmlTempDoc,
                        height: pageHeight,
                        width: pageWidth
                    );

                    if (response == null)
                        Console.WriteLine("MakeResizeDocumentAllPages(): Unexpected error - no response in html to Pdf convert!");
                    else if (response.Code != 200)
                        Console.WriteLine("MakeResizeDocumentAllPages(): Error -> Code {0} -> Status '{1}'", [response.Code, response.Status]);
                    else
                    {
                        Console.WriteLine("resizePages(): Pages successfully resized.");
                        await _helper.DownloadFile(outputDocument, "resized_doc_");
                    }
                }

            }
        }
    }