forked from jywarren/image-sequencer
-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Save as PDF option #1349
Merged
Merged
Add Save as PDF option #1349
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,8 @@ window.onload = function () { | |
} | ||
else if (dropDownValue == 'save-seq') { | ||
saveSequence(); | ||
} else if(dropDownValue == 'save-pdf') { | ||
savePDF(getLastImage()); | ||
} | ||
}); | ||
|
||
|
@@ -207,6 +209,44 @@ window.onload = function () { | |
}); | ||
} | ||
|
||
/** | ||
* Get the data URL for the last image in the sequence. | ||
* @return {string} The data URL for the last image in the sequence. | ||
*/ | ||
function getLastImage() { | ||
// Get the image from the last step. | ||
let imgs = document.getElementsByClassName('step-thumbnail'); | ||
let lastStepImage = imgs[imgs.length-1]; | ||
return lastStepImage.getAttribute("src"); | ||
} | ||
|
||
/** | ||
* Download the given image URL as a PDF file. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should use the * @description Download..... |
||
* @param {string} imageDataURL - The data URL for the image. | ||
*/ | ||
function savePDF(imageDataURL) { | ||
sequencer.getImageDimensions(imageDataURL, function(dimensions) { | ||
// Get the dimensions of the image. | ||
let pageWidth = dimensions.width; | ||
let pageHeight = dimensions.height; | ||
|
||
// Create a new pdf with the same dimensions as the image. | ||
const pdf = new jsPDF({ | ||
orientation: pageHeight > pageWidth ? "portrait": "landscape", | ||
unit: "px", | ||
format: [pageHeight, pageWidth] | ||
}); | ||
|
||
// Add the image to the pdf with dimensions equal to the internal dimensions of the page. | ||
pdf.addImage(imageDataURL, 0, 0, pdf.internal.pageSize.getWidth(), pdf.internal.pageSize.getHeight()); | ||
|
||
// Save the pdf with the filename specified here: | ||
pdf.save("index.pdf"); | ||
}); | ||
} | ||
|
||
|
||
|
||
function downloadGif(image) { | ||
download(image, 'index.gif', 'image/gif');// downloadjs library function | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove full stop from phrases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it a complete sentence?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the JSDoc examples usually look like this (they use imperative sentences).