Skip to content

Commit

Permalink
Duplicate pull 206 from upstream - attempt to fix chunyenHuang#205 - …
Browse files Browse the repository at this point in the history
…TypeError: this.page.startContext is not a function
  • Loading branch information
easyTree committed Aug 19, 2022
1 parent 7825f50 commit 88c88e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/Recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ class Recipe {
src = new muhammara.PDFRStreamForBuffer(this.src);
}
const pdfReader = muhammara.createReader(src, this.encryptOptions);
const pageCount = pdfReader.getPagesCount();
if (pageCount == 0) {
const pages = pdfReader.getPagesCount();
if (pages == 0) {
// broken or modify password protected
throw 'HummusJS: Unable to read/edit PDF file (pages=0)';
}
const metadata = {
pageCount
pages
};
for (var i = 0; i < pageCount; i++) {
for (var i = 0; i < pages; i++) {
const info = pdfReader.parsePage(i);
const dimensions = info.getMediaBox();
const rotate = info.getRotate();
Expand Down
9 changes: 6 additions & 3 deletions lib/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ exports.createPage = function createPage(pageWidth, pageHeight, margins) {
}
}
// from 0
this.metadata.pageCount += 1;
const pageNumber = this.metadata.pageCount;
this.metadata.pages += 1;
const pageNumber = this.metadata.pages;
const dimensions = [0, 0, pageWidth, pageHeight];
const layout = (pageWidth > pageHeight) ? 'landscape' : 'portrait';
this.metadata[pageNumber] = {
Expand Down Expand Up @@ -196,9 +196,12 @@ exports.pauseContext = function pauseContext() {
};

exports.resumeContext = function resumeContext() {
if (!this.isNewPDF && this.page) {
if (!this.isNewPDF && this.page && this.page.startContext) {
this.pageContext = this.page.startContext().getContext();
this._resumePageRotation();
} else if (!this.isNewPDF && this.page) {
this.pageContext = this.writer.startPageContentContext(this.page);
this._resumePageRotation();
}
};

Expand Down

0 comments on commit 88c88e0

Please sign in to comment.