Home > Code > C# > How to Get Specific Attachment from PDF File Using C#, Java & PHP in Cloud

How to Get Specific Attachment from PDF File Using C#, Java & PHP in Cloud

by sher azam   on Apr 01, 2015   Category: C#   |  Views: 640    |  Points: 25   |  Gold 


This tutorial shows how developers can get a specific attachment from a PDF using Aspose.Pdf for Cloud API in your applications. Developers can use Aspose REST API with any language: .NET, Java, PHP, Ruby, Rails, Python, jQuery and many more. Aspose for Cloud is a cloud-based document generation, conversion and automation platform for developers that offer a unique suite of APIs to work with Word documents, Excel spreadsheets, PowerPoint presentations, PDFs, and email formats and protocols.

[C# Code Sample]

//build URI to get selected attachment
string strURI = "http://api.aspose.com/v1.1/pdf/input.pdf/attachments/1";
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());
Attachment tempAttachment = 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; }
}

[PHP Code Sample]

use Aspose\Cloud\Common\AsposeApp;
use Aspose\Cloud\Common\Utils;

AsposeApp::$appSID = "...";
AsposeApp::$appKey = "...";

$method = "GET";
$base_url = "http://api.aspose.com/v1.1";
$request_url = "$base_url/pdf/Document1.pdf/attachments/1";
$signed_url = Utils::sign($request_url);

$response = Utils::processCommand($signed_url, $method, "", "");
$response = json_decode($response);
var_dump($response);



[Java Code Sample]

//build URI to get selected attachment
String strURI = "http://api.aspose.com/v1.1/pdf/input.pdf/attachments/1";
String signedURI = Sign(strURI);
InputStream responseStream = ProcessCommand(signedURI, "GET");
String strJSON = StreamToString(responseStream);
Gson gson = new Gson();
//Parse and Deserializes the JSON to a object.
AttachmentResponse attachmentResponse = gson.fromJson(strJSON,AttachmentResponse.class);
Attachment TempAttachment = attachmentResponse.getAttachment();

//Here is the BaseResponse class
public class BaseResponse
{
public BaseResponse() { }
private String Code;
private String Status;
public String getCode(){return Code;}
public String getStatus(){return Status;}
public void setCode(String temCode){ Code=temCode;}
public void setStatus(String temStatus){ Status=temStatus;}
}

//Here is the AttachmentResponse class
public class AttachmentResponse extends BaseResponse
{
public AttachmentResponse() { }
private Attachment Attachment;
public Attachment getAttachment(){return Attachment;}
}

//Here is the Attachment class
public class Attachment
{
public Attachment() { }
private Color Color;
private String MimeType;
private String Name;
private String CreationDate;
private String ModificationDate;
private int Size;
public Color getColor(){return Color;}
public String getMimeType(){return MimeType;}
public String getName(){return Name;}
public String getCreationDate(){return CreationDate;}
public String getModificationDate(){return ModificationDate;}
public int getAttachmentSize(){return Size;}
}

//Here is the Color class
public class Color
{
public Color() { }
private int A;
private int B;
private int G;
private int R;
public int getA(){return A;}
public int getB(){return B;}
public int getG(){return G;}
public int getR(){return R;}
}


To view other code samples please click here: http://www.aspose.com/docs/display/pdfcloud/Get+a+Specific+Attachment+from+a+PDF

Overview: Aspose for Cloud

Aspose for Cloud is a cloud-based document generation, conversion and automation platform for developers that offer a unique suite of APIs to work with Word documents, Excel spreadsheets, PowerPoint presentations, PDFs, and email formats and protocols. It supports all features for file processing, document scanning, barcodes creation and recognition, and allows extracting text or images too. You can also work with SaaSpose APIs using REST SDKs that can be called from .NET, Java, PHP and Ruby etc

- Learn More about Aspose.Pdf for Cloud: http://www.aspose.com/cloud/pdf-api.aspx

- Download Aspose. Pdf for Cloud SDKs: http://www.aspose.com/docs/display/pdfcloud/Available+SDKs




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