Created
August 6, 2024 10:49
Append PDF with C# REST API. https://kb.aspose.cloud/pdf/net/append-pdf-with-net-rest-api/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using Aspose.Pdf.Cloud.Sdk.Api; | |
using Aspose.Pdf.Cloud.Sdk.Model; | |
namespace Aspose.PDF.Cloud.Examples.Kb | |
{ | |
public class PdfTasks | |
{ | |
public static void AppendPdf() | |
{ | |
PdfApi pdfApi = new PdfApi("key", "sid"); | |
String fileName = "Sample.pdf"; | |
String appendFileName = "sample-input.pdf"; | |
try | |
{ | |
// Upload source file to aspose cloud storage | |
pdfApi.UploadFile(fileName, new MemoryStream(File.ReadAllBytes(fileName))); | |
pdfApi.UploadFile(appendFileName, new MemoryStream(File.ReadAllBytes(appendFileName))); | |
int startPage = 2; | |
int endPage = 3; | |
String storage = ""; | |
String folder = ""; | |
// Invoke Aspose.PDF Cloud SDK API to append pdf file | |
DocumentResponse apiResponse = pdfApi.PostAppendDocument(fileName, appendFileName, startPage, endPage, storage, folder); | |
if (apiResponse != null && apiResponse.Status.Equals("OK")) | |
{ | |
// Download created pdf file | |
Stream storageRes = pdfApi.DownloadFile(fileName); | |
storageRes.Position = 0; | |
using (FileStream fileStream = new FileStream("Sample_out.pdf", FileMode.Create, FileAccess.Write)) | |
{ | |
storageRes.CopyTo(fileStream); | |
} | |
Console.WriteLine("PDF appended successfully, Done!"); | |
Console.ReadKey(); | |
} | |
} | |
catch (Exception ex) | |
{ | |
System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment