How to rotate a single page and render new rotation using ngx-extended-pdf-viewer

Discussão em 'Angular' iniciado por cjlh94, Outubro 22, 2024.

  1. cjlh94

    cjlh94 Guest

    Using the ngx-extended-pdf-viewer (v21) package for angular (v18), i am trying to rotate specific pages instead of the whole document if i use the built in rotation functions.

    Has anyone achieved this yet?

    private _getPdfPage(pageNumber: number): PDFPageView | undefined {
    const pdfApplication = this.pdfNotificationService.onPDFJSInitSignal();

    if (pdfApplication) {
    return pdfApplication.pdfViewer._pages[pageNumber - 1];
    } else {
    return undefined;
    }
    }

    rotatePage() {
    const mostVisiblePageNumber =
    this.pdfViewerService.getCurrentlyVisiblePageNumbers()[0];

    const page = this._getPdfPage(mostVisiblePageNumber);

    if (page == undefined) {
    this.notificationService.error(
    'Page Rotation Failed',
    'Unable to access pdf page.',
    );
    } else {
    // Calculate the next angle for the rotation
    let currentAngle = page.rotation;
    let nextAngle = currentAngle + 90;

    if (nextAngle == 360) {
    nextAngle = 0;
    }

    // Set the desired rotation (0, 90, 180, 270)
    console.log(currentAngle);
    console.log(nextAngle);
    page.rotation = nextAngle;
    page.pdfPageRotate = nextAngle;

    // render the page with rotation changes
    this.pdfViewerService.renderPage(page.id - 1);

    console.log(this.pdfViewerService.addPageToRenderQueue(page.id - 1));
    }
    }


    Edit: To clarify the current issue I am having; If i add a console log and check the value of page.rotation after I have altered its value, the new value is reflected. However the page is not visually rotated within the ngx-extended-pdf-viewer.

    Continue reading...

Compartilhe esta Página