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

Add templating feature #56

Closed
wants to merge 4 commits into from
Closed

Conversation

alFReD-NSH
Copy link

This is a nice feature that we can build static parts of a PDF file before, save them, and then later on we put them on the dynamic content for everypage. Though the way I implemented it may not be the best(for example you can switch pages, which you should not, or maybe the fonts may not work), but at the moment it basically works:

I added these functions to public API:

  • startTemp() -> starts the templating mode
  • endTemp() -> ends the templating mode
  • outputTemp() -> which will outputs the template

I added an argument to the end of the constructor function:

  • constructor: (@options = {}, temp) in which temp is object that is returned by outputTemp()

Beside that 3 variables:

  • haveTemp: false
  • isTemp: false
  • temp -> which holds the template object

But this is just a work in progress. I'm thinking of adding features such as, building on a pre-built file, or having multiple templates.

@alFReD-NSH
Copy link
Author

This is the example:

var pdf = require('./index.js');

var doc = new pdf();
doc.startTemp();
doc.text('im a template!');
doc.endTemp();

var temp = JSON.parse(JSON.stringify( doc.outputTemp() )); // To ensure nothing happens when it is saved

var doc2 = new pdf({}, temp);
doc2.text('hi2');
doc2.addPage();
doc2.text('hi3');
doc2.write('tess.pdf');

@alexandre1985
Copy link

Since this feature was introduce long time ago, I would like to now if this feature can now build on a pre-built file, I mean using one file as template?
Thank you

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

Successfully merging this pull request may close these issues.

None yet

3 participants