0

I created a desktop application with Electron that allows users to enter information about applicants in a program. My application needs the ability to create and save that information to a .pdf file. I have created the .pdf successfully, but I'm running into a problem concerning where to save them. I would like to create an applicantPDF folder on the user's desktop. I don't necessarily know where the user will keep the application, or where the actual files will be located once the users installs the application. Any ideas on how to set up the file path to go to any user's desktop? I currently just have it going one level out of the application. Code included below.

let content = document.getElementById('finalPageContainer').outerHTML
    let fileName = applicant["Personal Information"]["Last Name"] + applicant["Personal Information"]["Identification Number"] + ""
    let pdf = require('html-pdf');
    pdf.create(content).toFile('../applicantPDF/' + fileName + '.pdf', function(err) {
        if (err) return console.log(err);
    })

Thank you so much for your help.

David D.
  • 21
  • 1
  • 4

1 Answers1

0

You have a lot of options for accessing default paths using app.getPath(name) so:

let desktop = app.getPath('desktop');

Alternately, you could show a dialog asking the user where to save the info, etc.

spring
  • 18,009
  • 15
  • 80
  • 160
  • Thanks. That helped a lot. I also ended up having to store app.getPath('desktop') in a global variable so that I could access it out of my main process. _in app.js_ `global.desk = app.getPath('desktop')` _in index.js_ `let desktop = remote.getGlobal('desk');` – David D. Dec 26 '19 at 19:16