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

Making file on output #15

Open
Scorpovi4 opened this issue Mar 29, 2019 · 2 comments
Open

Making file on output #15

Scorpovi4 opened this issue Mar 29, 2019 · 2 comments

Comments

@Scorpovi4
Copy link

How to save returned to callback to file with custom name? And how plugin upload images, does need set the path as "base" for it or not?

@joehiggs
Copy link
Contributor

Changing the filename depends where you are downloading the file from. I'm adding an html example to the /example folder right now, should be up very soon. If you are downloading to a local file system, however, use the path option for puppeteer's page.pdf function. More on that can be found here. As a reminder, the args for the page.pdf function are passed through the options parameter of pdf-puppeteer's convertHTMLToPDF function.

For your other question, I'm not quite sure what you're asking... Could you rephrase?

@Scorpovi4
Copy link
Author

Scorpovi4 commented Apr 1, 2019

How I try to convert and what I have on output.

const gulp = require("gulp");
const path = require('path');
const fs = require('fs');
const fsPath = require('fs-path');
const forEach = require('foreach');
const glob = require("glob");
const convertHTMLToPDF = require("pdf-puppeteer");

module.exports = () => {
	return gulp.task('pdf', () => {
		options = {};
		return glob($.outputFolder + 'html/*.html', options, function (er, files) {
			forEach (files, function (file) {
				const html = fs.readFileSync(file, 'utf8');
				const upLevelDir = path.join(__dirname, '../' );
				const name = path.basename(file, '.html');

				const callback = function (pdf) {					
					fsPath.writeFile($.outputFolder + 'pdf/' + name + '.pdf', pdf, function(err){
						if(err) throw err;
					});
				}
				convertHTMLToPDF(html, callback, null, null, false).catch(err => {
					console.log(err);
				});
			});
			console.log('PDF done!');
		});
	});
}

Output

The same result on regular fs method stream to file... I used this module to convert and it makes pdf but with differences between browser print mode and pdf...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants