Skip to content

Commit 54cd934

Browse files
committed
Resolve error for the image in pdf
1 parent bd7af66 commit 54cd934

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ app.set("view engine", "ejs");
1313
app.use(bodyParser.urlencoded({ extended: true }));
1414
app.use(express.static("public"));
1515

16-
const apiKey = "c7d40af634094a53a02a542268b9f073";
16+
const apiKey = "f8f19f5552fe4a64a5bd79038933bb05";
1717

1818
// All the get request to render differrent page.
1919

views/planMeals.ejs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,19 +221,19 @@
221221
referrerpolicy="no-referrer"
222222
></script>
223223

224-
<script>
225-
window.onload = function () {
226-
const btn = document.getElementById("downloadBtn");
227-
btn.addEventListener("click", () => {
228-
const menu = this.document.getElementById("result");
229-
const options = {
230-
filename: "menu.pdf",
231-
image: { type: "jpeg", quality: 0.98 },
232-
jsPDF: { format: "letter", orientation: "landscape" },
233-
};
234-
html2pdf().from(menu).set(options).save();
235-
});
236-
};
237-
</script>
224+
<script>
225+
window.onload = function () {
226+
const btn = document.getElementById("downloadBtn");
227+
btn.addEventListener("click", () => {
228+
const menu = this.document.getElementById("result");
229+
const options = {
230+
filename: "menu.pdf",
231+
image: { type: "jpeg", quality: 0.98 },
232+
jsPDF: { format: "letter", orientation: "landscape" },
233+
};
234+
html2pdf().from(menu).set(options).save();
235+
});
236+
};
237+
</script>
238238
</body>
239239
</html>

views/recipe.ejs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,17 @@
193193
></script>
194194

195195
<script>
196+
useCORS: true;
197+
196198
window.onload = function () {
197199
const btn = document.getElementById("downloadBtn");
198200
btn.addEventListener("click", () => {
199201
const recipe = this.document.getElementById("meals");
200202
const options = {
203+
margin: 0,
201204
filename: "recipe.pdf",
202205
image: { type: "jpeg", quality: 0.98 },
206+
html2canvas: { scale: 2, useCORS: true },
203207
jsPDF: { format: "letter", orientation: "landscape" },
204208
};
205209
html2pdf().from(recipe).set(options).save();

0 commit comments

Comments
 (0)