# \[p5.js\] Is there another way to print to Excel (or pdf)?

**URL:** <https://discourse.processing.org/t/p5-js-is-there-another-way-to-print-to-excel-or-pdf/34007>\
**Category:** Coding Questions\
**Created:** [December 8, 2021, 7:34pm UTC](https://discourse.processing.org/t/p5-js-is-there-another-way-to-print-to-excel-or-pdf/34007 "2021-12-08T19:34:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [December 8, 2021, 7:34pm UTC](https://discourse.processing.org/t/p5-js-is-there-another-way-to-print-to-excel-or-pdf/34007/1 "2021-12-08T19:34:53Z")

</div>

1. You can find out how to print through ‘JS’ (JAVA Script) by searching ‘Google’.

1. excel  
[Export html table data to Excel using JavaScript / JQuery is not working properly in chrome browser - Stack Overflow](https://stackoverflow.com/questions/22317951/export-html-table-data-to-excel-using-javascript-jquery-is-not-working-properl?rq=1)
2. pdf  
[jspdf - Generate pdf from HTML in div using Javascript - Stack Overflow](https://stackoverflow.com/questions/18191893/generate-pdf-from-html-in-div-using-javascript)

1. Is there a way to print ‘pdf’ or ‘excel’ among the methods provided by ‘P5’?  
Or should it be implemented in ‘JAVA Script’?

---

<div class="post-metadata">

**Author:** ![KumuPaul](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kumupaul/32/13072_2.png) [@KumuPaul](https://discourse.processing.org/u/KumuPaul)\
**Post date:** [December 8, 2021, 11:16pm UTC](https://discourse.processing.org/t/p5-js-is-there-another-way-to-print-to-excel-or-pdf/34007/2 "2021-12-08T23:16:22Z")

</div>

FYI, the programming language in question is usually referred as “JavaScript” with no space, or sometimes “ECMAScript.” This is to avoid confusion with the programming language “Java.”

I’m not sure what printing has to do with Excel or why you would associate p5js with Excel in any way.

That said, the simplest way to print in JavaScript is just to call the built in `window.print()` function (not to be confused with the p5js [`print()`](https://p5js.org/reference/#/p5/print) function. This will open the browser’s print dialog and allow the user to select how they would like to print (either to an actual printer, or saving as a PDF). Here’s an example:

```javascript
function setup() {
  createCanvas(400, 400);
  background(220);
}

function draw() {
  circle(mouseX, mouseY, 30)
}

function doubleClicked() {
  window.print();
}

```

The only native function that p5js includes that relates would be the [`save()`](https://p5js.org/reference/#/p5/save) function which saves the content of the canvas as a PNG image and initiates a download.

```javascript
function setup() {
  createCanvas(400, 400);
  background(220);
}

function draw() {
  circle(mouseX, mouseY, 30)
}

function doubleClicked() {
  // The file name here can be whatever you want, but it should end in .png
  // The user can choose to save the file with a different name if they want.
  save("DefaultFileName.png");
}

```

---

<div class="post-metadata">

**Author:** ![GWAK](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@GWAK](https://discourse.processing.org/u/GWAK)\
**Post date:** [December 9, 2021, 3:19am UTC](https://discourse.processing.org/t/p5-js-is-there-another-way-to-print-to-excel-or-pdf/34007/3 "2021-12-09T03:19:53Z")

</div>

Dear KumuPaul

Good!

Thank you.
