rotate Method

Summary

Rotates this page by the specified angle.

Syntax
TypeScript
JavaScript
DocumentPage.prototype.rotate = function( 
   angle 
) 
rotate( 
   angle: number 
): void; 

Parameters

angle

Rotation angle in degrees. Positive values will rotate the page clockwise and negative values will rotate the page counter-clockwise. Must be an increment of 90 degrees.

Remarks

This method changes the value of viewPerspective based on the previous value and angle.

Refer to Document Page Transformation for more information.

Example

This example loads a document, rotates it and then flips a couple of pages before exporting it to a new PDF.

Start with the example from LEADDocument and replace all the code inside the example function (search for the "// TODO: add example code here" comment) with the following code:

TypeScript
JavaScript
var url = "https://demo.leadtools.com/images/pdf/leadtools.pdf"; 
log("Loading document..."); 
var loadDocumentOptions = new lt.Document.LoadDocumentOptions(); 
lt.Document.DocumentFactory.loadFromUri(url, loadDocumentOptions) 
   .done(function (doc) { 
      log("Loaded, converting..."); 
      // LEADDocument is read-only by default, so: 
      doc.isReadOnly = false; 
      // Rotate the first page by 90 
      var docPage = doc.pages.item(0); 
      docPage.rotate(90); 
      // Flip the second page vertically 
      docPage = doc.pages.item(1); 
      docPage.flip(); 
      // Save it to the cache 
      lt.Document.DocumentFactory.saveToCache(doc) 
         .done(function () { 
            // Convert it to PDF 
            var jobData = new lt.Document.DocumentConverterJobData(); 
            jobData.documentFormat = lt.Document.Writer.DocumentFormat.pdf; 
            jobData.rasterImageFormat = lt.Document.RasterImageFormat.unknown; 
            // Set document options 
            var docxOptions = new lt.Document.Writer.DocxDocumentOptions(); 
            docxOptions.textMode = lt.Document.Writer.DocumentTextMode.auto; 
            jobData.documentOptions = docxOptions; 
            doc.convert(jobData) 
               .done(function (result) { 
                  // This is generic code, we know the result is in "document" since DOCX supports that 
                  // But this code checks if the results have been archived into a ZIP file if this 
                  // example was converting to, say SVG 
                  var resultDocument = result.document != null ? result.document.url : result.archive.url; 
                  var link = document.createElement("a"); 
                  var url = lt.Document.DocumentFactory.serviceUri + "/" + resultDocument; 
                  link.href = url; 
                  link.innerHTML = url; 
                  link.target = "_default"; 
                  log("Converted: " + url, url); 
                  output.insertBefore(link, output.firstChild); 
               }) 
               .fail(showServiceError); 
         }) 
         .fail(showServiceError); 
   }) 
   .fail(showServiceError); 
class LEADDocument_RotateExample { 
    public constructor() { 
        lt.RasterSupport.setLicenseUri("https://demo.leadtools.com/licenses/v200/LEADTOOLSEVAL.txt", "EVAL", null); 
    } 
 
    public run(buttonID: string) { 
        document.getElementById(buttonID).onclick = this.rotatePage; 
    } 
 
    rotatePage = () => { 
        const url = "https://demo.leadtools.com/images/pdf/leadtools.pdf";; 
        const loadDocumentOptions = new lt.Document.LoadDocumentOptions(); 
 
        log("Loading document..."); 
        lt.Document.DocumentFactory.loadFromUri(url, loadDocumentOptions) 
        .done((doc) => { 
           log("Loaded, converting..."); 
           // LEADDocument is read-only by default, so: 
           doc.isReadOnly = false; 
           // Rotate the first page by 90 
           let docPage = doc.pages.item(0); 
           docPage.rotate(90); 
           // Flip the second page vertically 
           docPage = doc.pages.item(1); 
           docPage.flip(); 
           // Save it to the cache 
           lt.Document.DocumentFactory.saveToCache(doc) 
              .done(() => { 
                 // Convert it to PDF 
                 const jobData = new lt.Document.DocumentConverterJobData(); 
                 jobData.documentFormat = lt.Document.Writer.DocumentFormat.pdf; 
                 jobData.rasterImageFormat = lt.Document.RasterImageFormat.unknown; 
                 // Set document options 
                 const docxOptions = new lt.Document.Writer.DocxDocumentOptions(); 
                 docxOptions.textMode = lt.Document.Writer.DocumentTextMode.auto; 
                 jobData.documentOptions = docxOptions; 
                 doc.convert(jobData) 
                    .done((result) => { 
                       // This is generic code, we know the result is in "document" since DOCX supports that 
                       // But this code checks if the results have been archived into a ZIP file if this 
                       // example was converting to, say SVG 
                       const resultDocument = result.document != null ? result.document.url : result.archive.url; 
                       const link = document.createElement("a"); 
                       const url = lt.Document.DocumentFactory.serviceUri + "/" + resultDocument; 
                       link.href = url; 
                       link.innerHTML = url; 
                       link.target = "_default"; 
                       log("Converted: " + url, url); 
                    }) 
                    .fail(showServiceError); 
              }) 
              .fail(showServiceError); 
        }) 
        .fail(showServiceError); 
    } 
} 

Requirements

Target Platforms

Help Version 20.0.2019.3.11
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2019 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Document Assembly