Skip to content
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

Incorporate "Open" Package to Refresh PDF Viewers for PDF #11

Open
revdavethompson opened this issue Apr 25, 2023 · 0 comments
Open

Incorporate "Open" Package to Refresh PDF Viewers for PDF #11

revdavethompson opened this issue Apr 25, 2023 · 0 comments
Labels
dev mode 🕶️ Related to the Development Mode "dev" enhancement 👍 New feature or request

Comments

@revdavethompson
Copy link
Collaborator

Is your feature request related to a problem? Please describe.
It's tiresome to constantly reload the built pdf into a pdf viewer for each build.

Describe the solution you'd like
It would be great to combine Nodemon and the Open package so that the pdf viewer is automatically updated with the most recently built version of the pdf.

HOW TO SET IT UP:

  1. If you don't have Node.js installed, download the installer from the official website (https://nodejs.org/) and follow the installation instructions.

  2. Open Terminal and install nodemon and open libraries globally with the following command:

npm install -g nodemon open
  1. Create a JavaScript file, for example, refreshPreview.js, and open it with your preferred text editor.

  2. Paste the following JavaScript code into the file:

const open = require('open');
const filePath = process.argv[2];

if (!filePath) {
  console.error('Please provide a file path as an argument.');
  process.exit(1);
}

(async () => {
  console.log(`File ${filePath} changed. Reloading Preview...`);

  // Close the current Preview instance
  await open(filePath, { app: 'Preview', wait: true }).catch(() => {});

  // Reopen the file with Preview
  await open(filePath, { app: 'Preview' });
})();
  1. Save the file and close the text editor.

  2. Now you can run nodemon with the path to the file you want to watch as an argument. Open Terminal and navigate to the folder containing the refreshPreview.js script, then run:

nodemon --watch /path/to/your/file.pdf --exec "node refreshPreview.js /path/to/your/file.pdf"

With this command, nodemon will watch the specified file for changes, and the Preview window will automatically refresh the file whenever it's updated, even if it's in the background. To stop the script, press Control + C in Terminal.

Please note that this solution uses Node.js and won't work directly in a web browser. If you're looking for a solution that works within a web browser, you may consider building a web-based PDF or image viewer using JavaScript libraries such as PDF.js or Viewer.js.

@revdavethompson revdavethompson added enhancement 👍 New feature or request dev mode 🕶️ Related to the Development Mode "dev" labels Apr 25, 2023
@revdavethompson revdavethompson added this to the v1.0.0 (Gilgamesh) milestone Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev mode 🕶️ Related to the Development Mode "dev" enhancement 👍 New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant