Rotate
Rotates a page or entire Pdf document in a specific direction.
- C#
- Java
- JavaScript
- PHP
- Python
- Ruby
// create rotate object
var req = new Rotate()
{
// document
Document = new Document()
{
DocData = File.ReadAllBytes("myPdf.pdf"),
Name = "myPdf.pdf",
},
// action
RotateAction = new RotateAction()
{
RotationList = new HashSet()
{
new PdfRotate()
{
PageNr = 1,
RotationType = PdfRotateRotationType.Clockwise
},
new PdfRotate()
{
PageNr = 2,
RotationType = PdfRotateRotationType.CounterClockwise,
},
new PdfRotate()
{
PageNr = 3,
RotationType = PdfRotateRotationType.UpsideDown,
},
}
},
};
// applying rotate to the PDF
var res = Pdf4me.Instance.PdfAClient.RotateAsync(req).GetAwaiter().GetResult();
// extract the rotated PDF and writing it to disk
byte[] rotatedPdf = res.Document.DocData;
File.WriteAllBytes("rotatedPdf.pdf", rotatedPdf);
// setup the pdf4meClient
const pdf4meClient = pdf4me.createClient('YOUR API KEY')
// create rotate object
const rotateReq = {
// document
document: {
docData: fs.readFileSync(path.join(__dirname, 'myPdf.pdf')).toString('base64'),
},
// action
rotateAction: {
rotationList: [
{
pageNr: 1,
rotationType: 'clockwise',
},
{
pageNr: 2,
rotationType: 'counterClockwise',
},
{
pageNr: 3,
rotationType: 'upsideDown',
},
],
},
}
// applying rotate to the PDF
pdf4meClient
.rotate(rotateReq)
.then(function(rotateRes) {
// extracting the rotated PDF and writing it to disk
const pdfDocument = Buffer.from(rotateRes.document.docData, 'base64');
fs.writeFileSync(path.join(__dirname, 'rotatedPdf.pdf'), pdfDocument)
})
.catch(error => {
console.log(error)
})
# setup the pdfA_client
pdfA_client = PdfAClient(pdf4me_client)
# create the rotate object
create_rotate = Rotate(
# document
document=Document(
doc_data=FileReader().get_file_data('myPdf.pdf')
),
# action
rotate_action=RotateAction(
rotation_list=[
PdfRotate(
page_nr=1,
rotation_type='clockwise'
),
PdfRotate(
page_nr=2,
rotation_type='counterClockwise'
),
PdfRotate(
page_nr=3,
rotation_type='upsideDown'
)
]
)
)
# applying rotate to the PDF
res = pdfA_client.rotate(rotate=create_rotate)
# extracting the rotated PDF
rotated_pdf = base64.b64decode(res['document']['doc_data'])
# writing it to disk
with open('rotatedPdf.pdf', 'wb') as f:
f.write(rotated_pdf)
// create the rotate object
$create_rotate = [
// document
'document'=> [
'name' => 'myPdf.pdf',
'docData' => $client->getFileData('myPdf.pdf')
],
// action
'rotateAction' => [
'rotationList' => [
[
"pageNr"=> 1,
"rotationType"=> "clockwise"
],
[
"pageNr"=> 2,
"rotationType"=> "counterClockwise"
]
[
"pageNr"=> 3,
"rotationType"=> "upsideDown"
]
],
],
];
// applying rotate to the PDF
$res = $client->pdf4me()->rotate($create_rotate);
// extracting the rotated PDF
$rotatedPdf = base64_decode($res->document->docData);
// writing it to disk
file_put_contents('rotatedPdf.pdf', $rotatedPdf);