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

Documentation of proper way to write a plugin #3236

Closed
risacher opened this issue Aug 23, 2021 · 4 comments · May be fixed by #3237
Closed

Documentation of proper way to write a plugin #3236

risacher opened this issue Aug 23, 2021 · 4 comments · May be fixed by #3237

Comments

@risacher
Copy link
Contributor

I've written a plugin for jsPDF, and I've got it working for my test case, but I have zero confidence that it will work for all the situations that jsPDF works. I haven't found documentation on how to properly write a plugin for current jsPDF, and I'd like to do it right.

Currently, I load 2.3.1/jspdf.umd.min.js before the plugin or the render code, and the plugin does this:

;(function(API) {                                                                                                                                                                        
                                                                                                                                                                                         
  var embedPage = API.embedPage = function (sourcePage, options) {                                                                                                                       
  //do stuff
  }
})(window.jspdf.jsPDF.API);

What's the proper way to write a plugin, and where is it documented?

@HackbrettXXX
Copy link
Collaborator

You're doing it right. You can add methods to the jsPDF API by extending the jsPDF.API object. You can also hook into events that are raised at certain points, e.g. this.internal.events.subscribe("putResources", () => {...}). AFAIK, this is not documented anywhere, so you probably will have to read through the source code. A pull request that adds documentation for this would be appreciated.

@risacher
Copy link
Contributor Author

Thanks @HackbrettXXX . The particular thing I'm concerned about is the right way to reference the jsPDF object - I formerly added my method to jsPDF.API, but loading 2.3.1 (using a script tag from a CDN) I found that jsPDF was undefined, and I had to access it as window.jspdf.jsPDF. If someone were using one of the module formats, I assume that would be wrong. I've not yet figured out how to use any of those other module formats (es, node, umd), or how a plugin would be invoked there.

@risacher
Copy link
Contributor Author

risacher commented Aug 23, 2021

I think if there were an example plugin (even one that did nothing) in the main repo, that would go a long way. I'd be happy to put a pull request together if I knew that I was doing it right. [edit: when I started writing my plugin, I was looking at an old release. I now see there is such an example, but the way it was invoked didn't work for me. Pull request generated.]

@github-actions
Copy link

This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.

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

Successfully merging a pull request may close this issue.

2 participants