|It is currently Thu Jun 21, 2018 5:56 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka

Author
saaspose
Offline
Newbie
Newbie
USER_AVATAR

Joined: Fri Nov 23, 2012 5:42 am
Posts: 0
Blog: View Blog (2)

Archives
- February 2013

Search Blogs



Permanent LinkPosted: Wed Feb 06, 2013 7:29 am 
This technical tip allows developers to split all or specific pages of a PDF file and save each page as a new PDF or any supported format using Saaspose.Pdf REST API in your .NET applications. Input PDF file needs to be uploaded in root folder of Saaspose Storage before running this code.Saaspose.Pdf is a REST API to create, edit & manipulate PDF files. It also convert PDF file to DOC, DOCX, HTML, XPS, TIFF etc. It is platform independent REST API & working with web, desktop, mobile or cloud applications alike. Some important steps for performing this task are to build URI to split PDF pages, sign URI, further process JSON response, Parse the json string to JObject, build URI to download split pages and save split PDF pages as PDF.

Sample Code for Splitting all pages to new PDFs

vbnet code
SaasposeApp.AppSID  = "77***********************************";
SaasposeApp.AppKey = "9a*******************************";
string outputPath = "C:\\TempFiles\\";

//build URI to split PDF pages
string strURI = "http://api.saaspose.com/v1.0/pdf/4pages.pdf/split";
//sign URI
string signedURI = Utils.Sign(strURI);
StreamReader reader = new StreamReader(Utils.ProcessCommand(signedURI, "POST"));
//further process JSON response
string strJSON = reader.ReadToEnd();
//Parse the json string to JObject
JObject parsedJSON = JObject.Parse(strJSON);
SplitPDFResponse responseStream = JsonConvert.DeserializeObject<SplitPDFResponse>(parsedJSON.ToString());

foreach (LinkResponse splitPage in responseStream.Result.Documents)
{
string splitFileName = System.IO.Path.GetFileName(splitPage.Href);
//build URI to download split pages
strURI = "http://api.saaspose.com/v1.0/storage/file/" + splitFileName;
//sign URI
signedURI = Utils.Sign(strURI);
//save split PDF pages as PDF
using (Stream fileStream = System.IO.File.OpenWrite(outputPath + splitFileName))
{
Utils.CopyStream(Utils.ProcessCommand(signedURI, "GET"), fileStream);
}
}
// class definitions
public class SplitPDFResponse : Saaspose.Common.BaseResponse
{
public SplitPdfResult Result { get; set; }
}
public class SplitPdfResult
{
public LinkResponse[] Documents { get; set; }
}



Split specific pages to new PDFs


vbnet code
SaasposeApp.AppSID  = "77***********************************";
SaasposeApp.AppKey = "9a*******************************";
string outputPath = "C:\\TempFiles\\";

//build URI to split PDF pages
string strURI = "http://api.saaspose.com/v1.0/pdf/4pages.pdf/split?from=2&to=3";
//sign URI
string signedURI = Utils.Sign(strURI);
StreamReader reader = new StreamReader(Utils.ProcessCommand(signedURI, "POST"));
//further process JSON response
string strJSON = reader.ReadToEnd();
//Parse the json string to JObject
JObject parsedJSON = JObject.Parse(strJSON);
SplitPDFResponse responseStream = JsonConvert.DeserializeObject<SplitPDFResponse>(parsedJSON.ToString());

foreach (LinkResponse splitPage in responseStream.Result.Documents)
{
string splitFileName = System.IO.Path.GetFileName(splitPage.Href);
//build URI to download split pages
strURI = "http://api.saaspose.com/v1.0/storage/file/" + splitFileName;
//sign URI
signedURI = Utils.Sign(strURI);
//save split PDF pages as PDF
using (Stream fileStream = System.IO.File.OpenWrite(outputPath + splitFileName))
{
Utils.CopyStream(Utils.ProcessCommand(signedURI, "GET"), fileStream);
}
}


Split PDF pages to any supported format

vbnet code
SaasposeApp.AppSID  = "77***********************************";
SaasposeApp.AppKey = "9a*******************************";
string outputPath = "C:\\TempFiles\\";

//build URI to split PDF pages
string strURI = "http://api.saaspose.com/v1.0/pdf/4pages.pdf/split?from=2&to=3&format=tiff";
//sign URI
string signedURI = Utils.Sign(strURI);
StreamReader reader = new StreamReader(Utils.ProcessCommand(signedURI, "POST"));
//further process JSON response
string strJSON = reader.ReadToEnd();
//Parse the json string to JObject
JObject parsedJSON = JObject.Parse(strJSON);
SplitPDFResponse responseStream = JsonConvert.DeserializeObject<SplitPDFResponse>(parsedJSON.ToString());

foreach (LinkResponse splitPage in responseStream.Result.Documents)
{
string splitFileName = System.IO.Path.GetFileName(splitPage.Href);
//build URI to download split pages
strURI = "http://api.saaspose.com/v1.0/storage/file/" + splitFileName;
//sign URI
signedURI = Utils.Sign(strURI);
//save split PDF pages as PDF
using (Stream fileStream = System.IO.File.OpenWrite(outputPath + splitFileName))
{
Utils.CopyStream(Utils.ProcessCommand(signedURI, "GET"), fileStream);
}}


Last edited by msi_333 on Thu Feb 07, 2013 12:47 am, edited 1 time in total.


 Profile  
 


All times are UTC [ DST ]









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com