-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from ..converter import KnowledgePostConverter | ||
|
||
from .html import HTMLConverter | ||
|
||
|
||
class PDFConverter(KnowledgePostConverter): | ||
''' | ||
Use this as a template for new KnowledgePostConverters. | ||
''' | ||
_registry_keys = ['pdf'] | ||
|
||
@property | ||
def dependencies(self): | ||
# Dependencies required for this converter on top of core knowledge-repo dependencies | ||
return ['weasyprint'] | ||
|
||
def from_file(self, filename, **opts): | ||
raise NotImplementedError | ||
|
||
def from_string(self, filename, **opts): | ||
raise NotImplementedError | ||
|
||
def to_file(self, filename, **opts): | ||
with open(filename, 'wb') as f: | ||
f.write(self.to_string()) | ||
|
||
def to_string(self, **opts): | ||
from weasyprint import HTML | ||
html = HTMLConverter(self.kp).to_string() | ||
return HTML(string=html).write_pdf() |