Rotate

Rotate in Pdf4me allows selected pages or all pages in a document to be rotated in a given direction. Each page can also be rotated in different directions. The rotation directions available are clockwise, anti-clockwise and upside-down.


FeatureParameterResponseActionDescriptionLinks
rotateRotateRotateResRotateActionRotates a page or entire Pdf document in a specific direction.Swagger
Sample
rotatePagepageNr, rotationType, file
file streamRotates a particular pages in a Pdf document.Swagger
Sample
rotateDocumentrotationType, filefile stream Rotates an entire Pdf document.
Swagger
Sample

Samples

Rotate

  • curl
  • C#
  • Java
  • JavaScript
  • PHP
  • Python
  • Ruby
curl No Sample
// 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)
  })
// 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);
# 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)

RotatePage

  • curl
  • C#
  • Java
  • JavaScript
  • PHP
  • Python
  • Ruby
curl https://api.pdf4me.com/PdfA/RotatePage ^
-H "Authorization: Basic DEV-KEY" ^
-F pageNr=2 ^
-F rotate=upsideDown ^
-F "file=@./myPdf.pdf" ^
-o ./rotatedpagePdf.pdf
// rotating second page upside down (rotate: UpsideDown)
var res = Pdf4me.Instance.PdfAClient.RotatePageAsync(File.ReadAllBytes("myPdf.pdf"),"2", PdfRotateRotationType.UpsideDown).GetAwaiter().GetResult();

// and writing the rotated PDF to disk
File.WriteAllBytes("rotatedpagePdf.pdf", res);
// setup the pdf4meClient
const pdf4meClient = pdf4me.createClient('YOUR API KEY')

// rotate
pdf4meClient.rotatePage('2', 'upsideDown', fs.createReadStream(path.join(__dirname, 'myPdf.pdf')))
  .then(pdf => {
    // and writing the resulting PDF to disk
    fs.writeFileSync(path.join(__dirname, 'rotatedpagePdf.pdf'), pdf)
  })
  .catch(error => {
    console.error(error)
  })
// rotating second page upside down (rotate: UpsideDown)
$res = $client->pdf4me()->rotatePage(
    [
        "pageNr" => "2",
        "rotate" => "upsideDown",
        "file" => 'myPdf.pdf'
    ]);
    
// and writing the rotated PDF to disk
file_put_contents('rotatedpagePdf.pdf', $res);

# setup the pdfA_client
pdfA_client = PdfAClient(pdf4me_client)

# rotating the PDF
rotated_pdf = pdfA_client.rotate_page(
        page_nr='2',
        rotate='upsideDown',
        file=FileReader().get_file_handler(path='myPdf.pdf')
    )
# writing the generated PDF to disk
with open('rotatedpagePdf.pdf', 'wb') as f:
    f.write(rotated_pdf)
    

RotateDocument

  • curl
  • C#
  • Java
  • JavaScript
  • PHP
  • Python
  • Ruby
curl https://api.pdf4me.com/PdfA/RotateDocument ^
-H "Authorization: Basic DEV-KEY" ^
-F rotate=upsideDown ^  
-F "file=@./myPdf.pdf" ^
-o ./rotatedDocPdf.pdf
// rotating the document upside down (rotate: UpsideDown)
var res = Pdf4me.Instance.PdfAClient.RotateDocumentAsync(File.ReadAllBytes("myPdf.pdf"), PdfRotateRotationType.UpsideDown).GetAwaiter().GetResult();

// and writing the rotated PDF to disk
File.WriteAllBytes("rotatedDocPdf.pdf", optimizedPdf);
// setup the pdf4meClient
const pdf4meClient = pdf4me.createClient('YOUR API KEY')

// rotate
pdf4meClient.rotateDocument('upsideDown', fs.createReadStream(path.join(__dirname, 'myPdf.pdf')))
  .then(pdf => {
    // and writing the resulting PDF to disk
    fs.writeFileSync(path.join(__dirname, 'rotatedDocPdf.pdf'), pdf)
  })
  .catch(error => {
    console.error(error)
  })
// rotating the document upside down (rotate: UpsideDown)
$res = $client->pdf4me()->rotateDocument(
    [
        "rotate" => "upsideDown",
        "file" => 'myPdf.pdf'
    ]);
    
// and writing the rotated PDF to disk
file_put_contents('rotatedDocPdf.pdf', $res);
# setup the pdfA_client
pdfA_client = PdfAClient(pdf4me_client)

# rotating the PDF
rotated_pdf = pdfA_client.rotate_document(
        rotate='upsideDown',
        file=FileReader().get_file_handler(path='myPdf.pdf')
    )
# writing the generated PDF to disk
with open('rotatedDocPdf.pdf', 'wb') as f:
    f.write(rotated_pdf)

Model

Rotate

Name Type Description Notes
document Document
rotateAction RotateAction
jobId String [optional]
jobIdExtern String [optional]
integrations [String] [optional]

RotateAction

Name Type Description Notes
pageNr [Integer] Pages to be rotated [Optional]
rotationType String Rotate the document in the specified direction by an angle of 180 degrees. Supported values: "clockwise", "counterClockwise", "upsideDown", "noRotation"
[Optional]

RotateRes

Name Type Description Notes
document Document Rotated document.

Document

Name Type Description Notes
jobId String JobId of Documents WorkingSet.
documentId String Document Id
name String Filename inlcuding filetype.
docStatus String Status of the Document, e.g. Stamped.
pages Page Description of pages.
docData [byte] Document bytes.
docMetadata DocMetadata Document metadata such as title, pageCount et al.
docLogs DocLog Logging information about the request, e.g. timestamp.

Page

Name Type Description Notes
documentId String Globally unique Id.
pageId String Globally unique Id.
pageNumber Integer PageNumber, starting with 1.
rotate double By how much the page was rotated from its original orientation.
thumbnail byte Thumbnail representing this particular page.
sourceDocumentId String Id of the document it was created from, e.g. in case of an extraction, the result's sourceDocumentId is the Id of the PDF the pages have been extracted from.
sourcePageNumber Integer Page number of the original page in the original document, e.g. let's assume document B consists of page number 4 of document A (extraction).
Thus, document B's only page's sourcePageNumber is number 4.

DocMetadata

Name Type Description Notes
title String Title of document.
subject String Subject of document.
pageCount long Number of pages.
size long Number bytes of the document.
isEncrypted boolean If the document is Encrypted
pdfCompliance String Pdf Compliance, e.g. PDF/A.
isSigned boolean If the document is Encrypted
uploadedMimeType String Uploaded MimeType, e.g. application/bson.
uploadedFileSize long Uploaded file size.

DocLog

Name Type Description Notes
messageType String MessageType, e.g. PdfALog.
message String Message itself, e.g. a warning.
timestamp dateTime Timestamp.
docLogLevel String Type of message. Supported Values :
"verbose", "info", "warning", "error", "timing"
durationMilliseconds long Timing for requested log information [ms].

How can we help?