Rotate pages in a PDF
Use this action to rotate one or more pages in a PDF document.
Endpoints
POST https://api.pdfblocks.com/v1/rotate_pages
Global endpoint (default)
POST https://eu.api.pdfblocks.com/v1/rotate_pages
European-only endpoint
Parameters
The endpoint accepts multipart/form-data
request bodies with the folowing parameters:
file Required
The content of the input PDF document.
angle Required
The angle of rotation of the pages.
- Positive angles rotate the pages clockwise. Negative angles rotate the pages counter-clockwise.
- Valid values are
0
,90
,180
,270
,-90
,-180
,-270
first_page optional
Integer with the first page of the range to rotate in the PDF document.
- The minimum value is
1
- Defaults to the first page of the PDF document.
last_page optional
Integer with the last page of the range to rotate in the PDF document.
- The minimum value is
1
- Defaults to the last page of the PDF document.
Returns
If successful, the call returns a response with Content-Type: application/pdf
with the content of the PDF document with the selected pages rotated. Otherwise, this call returns an error.
Code examples
curl
curl \
-F file=@input.pdf \
-F angle=-90 \
-F first_page=2 \
-F last_page=4 \
-o rotated.pdf \
-H 'X-Api-Key: your_api_key' \
https://api.pdfblocks.com/v1/rotate_pages
Python
# pip install requests
import requests
url = 'https://api.pdfblocks.com/v1/rotate_pages'
body = {
'file' : open('input.pdf', 'rb'),
'angle' : 90,
# 'first_page' : 2,
# 'last_page' : 4,
}
headers = { 'X-Api-Key' : 'your_api_key' }
response = requests.post(url, files=body, headers=headers)
if response.status_code == 200:
with open('rotated.pdf', 'wb') as output:
for chunk in response.iter_content():
output.write(chunk)
Ruby
# gem install http
require 'http'
url = 'https://api.pdfblocks.com/v1/rotate_pages'
body = {
file: HTTP::FormData::File.new('input.pdf'),
angle: 90,
# first_page: 2,
# last_page: 4,
}
headers = { 'X-Api-Key' => 'your_api_key' }
response = HTTP.post(url, form: body, headers: headers)
if response.status.ok?
File.open('rotated.pdf', 'wb') do |output|
response.body.each { |chunk| output.write(chunk) }
end
end
C# (.NET Core)
// Using .NET Core 3.1
using System.IO;
using System.Net.Http;
class Program
{
static void Main()
{
string url = "https://api.pdfblocks.com/v1/rotate_pages";
var inputFile = new FileStream("input.pdf", FileMode.Open, FileAccess.Read);
var body = new MultipartFormDataContent();
body.Add(new StreamContent(inputFile), "file");
body.Add(new StringContent("90"), "angle");
// body.Add(new StringContent("2"), "first_page");
// body.Add(new StringContent("4"), "last_page");
var message = new HttpRequestMessage(HttpMethod.Post, url);
message.Content = body;
message.Headers.Add("X-Api-Key", "your_api_key");
var client = new HttpClient();
var response = client.SendAsync(message).Result;
if(response.IsSuccessStatusCode)
{
using var output = new FileStream("rotated.pdf", FileMode.Create, FileAccess.Write);
response.Content.CopyToAsync(output).Wait();
}
}
}
In this page: