Important alert: (current site time 7/16/2013 7:33:35 AM EDT)
 

VB icon

Select Attachment in PDF & Download Selected Attachment Using REST API

Email
Submitted on: 8/16/2012 10:59:58 AM
By: aspose_seo 
Level: Intermediate
User Rating: Unrated
Compatibility: C#, VB.NET
Views: 1482
 
     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.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Select Attachment in PDF & Download Selected Attachment Using REST API
// Description: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.
// By: aspose_seo
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=8829&lngWId=10//for details.//**************************************

//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);
}
responseStream.Close();
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; }
} 


Other 16 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.