How to resize PDF docuemnt pages via Cloud .NET SDK
To resize PDF documents, we’ll use
Aspose.PDF Cloud .NET SDK
This Cloud SDK allows you to easily build cloud-based PDF creator, editor & converter apps in C#, ASP.NET, or other .NET languages for various cloud platforms. Open
NuGet
package manager, search for
Aspose.PDF Cloud
and install. You may also use the following command from the Package Manager Console: PM> Install-Package Aspose.Pdf-Cloud
Steps to resize PDF using .NET SDK
Aspose.PDF Cloud developers can easily load & resize PDF in just a few lines of code.
- Uploads the PDF.
- Converts it to HTML (retaining structure/content).
- Converts the HTML back to a new PDF with the specified dimensions.
- Downloads the resized document.
Resize PDF using .NET Cloud SDK
public static async Task ResizeDocumentPages()
{
const string localPdfFileName = @"C:\Samples\sample.pdf";
const string storageFileName = "sample.pdf";
const string localFolder = @"C:\Samples";
const string resultFileName = "output_resize_pages.pdf";
const string storageTempFolder = "YourTempFolder";
// Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required).
pdfApi = new PdfApi(AppSecret, AppSid);
using var file = File.OpenRead(localPdfFileName);
await pdfApi.UploadFileAsync(Path.Combine(storageTempFolder, storageFileName), file);
var response = await pdfApi.PostDocumentPagesResizeAsync(storageFileName, 300, 200, "1,3-5,8", folder: storageTempFolder);
if (response == null)
Console.WriteLine("ResizeDocumentPages(): Unexpected error!");
else if (response.Code != 200)
Console.WriteLine("ResizeDocumentPages(): Error -> Code {0} -> Status '{1}'", [response.Code, response.Status]);
else
{
using Stream downloadStream = pdfApi.DownloadFile(Path.Combine(storageTempFolder, storageFileName));
using FileStream localStream = File.Create(Path.Combine(localFolder, resultFileName));
downloadStream.CopyTo(localStream);
Console.WriteLine("ResizeDocumentPages(): pages successfully resized in the document '{0}.", resultFileName);
}
}
- Learning Resources
- Documentation
- Source Code
- API References
- Product Support
- Free Support
- Paid Support
- Blog
- Why Aspose.PDF Cloud for .NET?
- Customers List
- Security