Home > Code > C# > Select Attachment in PDF & Download Selected Attachment Using REST API

Select Attachment in PDF & Download Selected Attachment Using REST API

by sher azam   on Aug 15, 2012   Category: C#   |  Views: 1183    |  Points: 25   |  Gold 

This technical tip allows developers to download selected attachment in PDF file using Saaspose.Pdf REST API in your .NET applications. Saaspose.Pdf is a REST API to create, edit & manipulate PDF files. It also convert PDF file to DOC, DOCX, HTML, XPS, TIFF etc. You can create a new PDF either from scratch or from HTML, XML, template, database, XPS or an image. A PDF file can also be rendered to JPEG, PNG, GIF, BMP, TIFF and many other image formats. It works with any language like .NET, Java, PHP, Ruby, Python and many others. It is platform independent REST API & working with web, desktop, mobile or cloud applications alike.

Sample Code for downloading selected attachment in PDF file

//build URI to download selected attachment
Attachment FileInformation = GetAttachment(1);
//build URI to get page count
string strURI = "http://api.saaspose.com/v1.0/pdf/input.pdf/attachments/1/download";
string signedURI = Sign(strURI);
Stream responseStream = ProcessCommand(signedURI, "GET");
using (Stream fileStream = System.IO.File.OpenWrite(outputPath + "\\" + FileInformation.Name))
CopyStream(responseStream, fileStream);

public Attachment GetAttachment(int attachmentIndex)
//build URI to get page count
string strURI = "http://api.saaspose.com/v1.0/pdf/input.pdf/attachments/" + attachmentIndex;
string signedURI = Sign(strURI);
Stream responseStream = ProcessCommand(signedURI, "GET");
StreamReader reader = new StreamReader(responseStream);
string strJSON = reader.ReadToEnd();
//Parse the json string to JObject
JObject parsedJSON = JObject.Parse(strJSON);
//Deserializes the JSON to a object.
AttachmentResponse attachmentResponse = JsonConvert.DeserializeObject<AttachmentResponse>(parsedJSON.ToString());
return attachmentResponse.Attachment;
//Here is the BaseResponse class
public class BaseResponse
public BaseResponse() { }
public string Code { get; set; }
public string Status { get; set; }

//Here is the AttachmentResponse class
public class AttachmentResponse : BaseResponse
public AttachmentResponse() { }
public Attachment Attachment { get; set; }

//Here is the LinkResponse class
public class LinkResponse
public string Href { get; set; }
public string Rel { get; set; }
public string Title { get; set; }
public string Type { get; set; }

//Here is the Attachment class
public class Attachment
public Attachment() { }
public Color Color { get; set; }
public string MimeType { get; set; }
public string Name { get; set; }
public string CreationDate { get; set; }
public string ModificationDate { get; set; }
public Int32 Size { get; set; }
//Here is the Color class
public class Color
public Color() { }
public List<LinkResponse> Links { get; set; }
public int A { get; set; }
public int B { get; set; }
public int G { get; set; }
public int R { get; set; }

About Saaspose

SaaSpose is a cloud-based document generation, conversion and automation platform for developers. Using SaaSpose makes it easy for Web & Mobile Developers to work with Microsoft Word documents, Microsoft Excel spreadsheets, Microsoft PowerPoint presentations, Adobe PDFs, OpenDocument formats, and email formats and protocols in their Apps. The SaaSpose REST API enables you to quickly integrate the following into your Web: Document Assembly & Mail-Merge, Reporting, Document Conversion, Text and Image Extraction, Device Targeting, Metadata Removal, Barcode Recognition, Generation & Embedding, Email Templating & Tracking. The REST API can be called from any platform: .NET, Java, Ruby, Salesforce, Amazon etc.

More about Saaspose.Pdf

- Homepage of Saaspose.Pdf: http://saaspose.com/api/pdf

- More Technical Tips by Saaspose.Pdf: http://saaspose.com/docs/display/pdf/1.2+-+Saaspose.Pdf+Examples

- Ask technical questions/queries from Saaspose Support Team: http://saaspose.com/support/contact-us

Contact Information
Aspose Pty Ltd, Suite 163,
79 Longueville Road
Lane Cove, NSW, 2066
Phone: 1.214.329.1520
Fax: 866.810.9465

Post Code  |  Code Snippet Home

User Responses

No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts