Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rvilarl committed Nov 27, 2021
1 parent 19a73f1 commit df20f00
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
7 changes: 3 additions & 4 deletions .appveyor.yml
@@ -1,10 +1,9 @@
image: Visual Studio 2017
environment:
timeout: 30000
timeout: 15000
matrix:
# - nodejs_version: "8"
# - nodejs_version: "10"
- nodejs_version: "12"
# - nodejs_version: "12"
- nodejs_version: "16"
platform:
# - x86
- x64
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -5,7 +5,7 @@ node_js:
# - '10' # fails on Travis since upgrading to Vexflow 1.2.90 (still passes on AppVeyor), for Mxl_Test. Node 12 works.
- '12'
env:
- timeout=30000
- timeout=15000
notifications:
email: false
slack:
Expand Down
31 changes: 20 additions & 11 deletions demo/index.js
@@ -1,6 +1,6 @@
import { OpenSheetMusicDisplay } from '../src/OpenSheetMusicDisplay/OpenSheetMusicDisplay';
import { BackendType } from '../src/OpenSheetMusicDisplay/OSMDOptions';
import * as jsPDF from '../node_modules/jspdf-yworks/dist/jspdf.min';
import * as jsPDF from '../node_modules/jspdf/dist/jspdf.es.min';
import * as svg2pdf from '../node_modules/svg2pdf.js/dist/svg2pdf.umd.min';
import { TransposeCalculator } from '../src/Plugins/Transpose/TransposeCalculator';

Expand Down Expand Up @@ -832,7 +832,7 @@ import { TransposeCalculator } from '../src/Plugins/Transpose/TransposeCalculato
* Creates a Pdf of the currently rendered MusicXML
* @param pdfName if no name is given, the composer and title of the piece will be used
*/
function createPdf(pdfName) {
async function createPdf(pdfName) {
if (openSheetMusicDisplay.backendType !== BackendType.SVG) {
console.log("[OSMD] createPdf(): Warning: createPDF is only supported for SVG background for now, not for Canvas." +
" Please use osmd.setOptions({backendType: SVG}).");
Expand All @@ -858,20 +858,29 @@ import { TransposeCalculator } from '../src/Plugins/Transpose/TransposeCalculato

const orientation = pageHeight > pageWidth ? "p" : "l";
// create a new jsPDF instance
const pdf = new jsPDF(orientation, "mm", [pageWidth, pageHeight]);
const scale = pageWidth / svgElement.clientWidth;
const pdf = new jsPDF.jsPDF({
orientation: orientation,
unit: "mm",
format: [pageWidth, pageHeight]
});
//const scale = pageWidth / svgElement.clientWidth;
for (let idx = 0, len = backends.length; idx < len; ++idx) {
if (idx > 0) {
pdf.addPage();
}
svgElement = backends[idx].getSvgElement();

// render the svg element
svg2pdf(svgElement, pdf, {
scale: scale,
xOffset: 0,
yOffset: 0
});

if (!pdf.svg && !svg2pdf) { // this line also serves to make the svg2pdf not unused, though it's still necessary
// we need svg2pdf to have pdf.svg defined
console.log("svg2pdf missing, necessary for jspdf.svg().");
return;
}
await pdf.svg(svgElement, {
x: 0,
y: 0,
width: pageWidth,
height: pageHeight,
})
}

pdf.save(pdfName); // save/download the created pdf
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -92,7 +92,6 @@
"jquery": "^3.6.0",
"jsdom": "^18.1.1",
"jspdf": "^2.4.0",
"jspdf-yworks": "^2.1.1",
"karma": "^6.3.9",
"karma-base64-to-js-preprocessor": "^0.1.0",
"karma-chai": "^0.1.0",
Expand Down

0 comments on commit df20f00

Please sign in to comment.