polytext 0.1.1__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. {polytext-0.1.1 → polytext-0.1.2}/PKG-INFO +1 -1
  2. {polytext-0.1.1 → polytext-0.1.2}/polytext/generator/pdf.py +20 -8
  3. {polytext-0.1.1 → polytext-0.1.2}/polytext.egg-info/PKG-INFO +1 -1
  4. {polytext-0.1.1 → polytext-0.1.2}/setup.py +1 -1
  5. {polytext-0.1.1 → polytext-0.1.2}/LICENSE +0 -0
  6. {polytext-0.1.1 → polytext-0.1.2}/README.md +0 -0
  7. {polytext-0.1.1 → polytext-0.1.2}/polytext/__init__.py +0 -0
  8. {polytext-0.1.1 → polytext-0.1.2}/polytext/converter/__init__.py +0 -0
  9. {polytext-0.1.1 → polytext-0.1.2}/polytext/converter/pdf.py +0 -0
  10. {polytext-0.1.1 → polytext-0.1.2}/polytext/exceptions/__init__.py +0 -0
  11. {polytext-0.1.1 → polytext-0.1.2}/polytext/exceptions/base.py +0 -0
  12. {polytext-0.1.1 → polytext-0.1.2}/polytext/generator/__init__.py +0 -0
  13. {polytext-0.1.1 → polytext-0.1.2}/polytext/loader/__init__.py +0 -0
  14. {polytext-0.1.1 → polytext-0.1.2}/polytext/loader/text.py +0 -0
  15. {polytext-0.1.1 → polytext-0.1.2}/polytext.egg-info/SOURCES.txt +0 -0
  16. {polytext-0.1.1 → polytext-0.1.2}/polytext.egg-info/dependency_links.txt +0 -0
  17. {polytext-0.1.1 → polytext-0.1.2}/polytext.egg-info/not-zip-safe +0 -0
  18. {polytext-0.1.1 → polytext-0.1.2}/polytext.egg-info/requires.txt +0 -0
  19. {polytext-0.1.1 → polytext-0.1.2}/polytext.egg-info/top_level.txt +0 -0
  20. {polytext-0.1.1 → polytext-0.1.2}/pyproject.toml +0 -0
  21. {polytext-0.1.1 → polytext-0.1.2}/setup.cfg +0 -0
  22. {polytext-0.1.1 → polytext-0.1.2}/tests/test_extract_text_from_file.py +0 -0
  23. {polytext-0.1.1 → polytext-0.1.2}/tests/test_get_customized_pdf_from_markdown.py +0 -0
  24. {polytext-0.1.1 → polytext-0.1.2}/tests/test_get_document_text.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: polytext
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Python utilities to simplify document files management
5
5
  Home-page: https://github.com/docsity/polytext
6
6
  Author: Matteo Senardi
@@ -9,17 +9,20 @@ from weasyprint.text.fonts import FontConfiguration
9
9
  logger = logging.getLogger(__name__)
10
10
 
11
11
 
12
- def get_customized_pdf_from_markdown(input_markdown):
12
+ def get_customized_pdf_from_markdown(input_markdown, output_file=None, use_custom_css=True):
13
13
  """
14
14
  Convenience function to convert Markdown content to a PDF with custom styling.
15
15
 
16
16
  Args:
17
17
  input_markdown: The Markdown content to convert.
18
+ output_file: Optional; if provided, the PDF will be saved to this file.
19
+ use_custom_css (bool, optional): Whether to use custom CSS for styling. Defaults to True.
20
+
18
21
  Returns:
19
22
  A byte string containing the generated PDF.
20
23
  """
21
24
  generator = PDFGenerator()
22
- return generator.get_customized_pdf_from_markdown(input_markdown)
25
+ return generator.get_customized_pdf_from_markdown(input_markdown, output_file, use_custom_css)
23
26
 
24
27
 
25
28
  class PDFGenerator:
@@ -184,15 +187,20 @@ class PDFGenerator:
184
187
  """
185
188
  return css_template
186
189
 
187
- def get_customized_pdf_from_markdown(self, input_markdown, output_file=None):
190
+ def get_customized_pdf_from_markdown(self, input_markdown, output_file=None, use_custom_css=True):
188
191
  """
189
192
  Convert Markdown content to a PDF with custom styling.
190
193
 
191
194
  Args:
192
195
  input_markdown: The Markdown content to convert.
193
196
  output_file: Optional; if provided, the PDF will be saved to this file.
197
+ use_custom_css (bool, optional): Whether to use custom CSS for styling. Defaults to True.
198
+
194
199
  Returns:
195
200
  A byte string containing the generated PDF.
201
+
202
+ Raises:
203
+ Exception: If an error occurs during PDF generation.
196
204
  """
197
205
  try:
198
206
  html_content = markdown.markdown(input_markdown, extensions=['extra', 'codehilite', 'toc'])
@@ -200,11 +208,15 @@ class PDFGenerator:
200
208
  # Generate PDF from HTML with Custom Styles
201
209
  pdf_buffer = BytesIO()
202
210
 
203
- custom_css = self.generate_custom_css()
204
- font_config = FontConfiguration()
205
- html = HTML(string=html_content)
206
- css = CSS(string=custom_css, font_config=font_config)
207
- html.write_pdf(pdf_buffer, stylesheets=[css], font_config=font_config)
211
+ if use_custom_css:
212
+ custom_css = self.generate_custom_css()
213
+ font_config = FontConfiguration()
214
+ html = HTML(string=html_content)
215
+ css = CSS(string=custom_css, font_config=font_config)
216
+ html.write_pdf(pdf_buffer, stylesheets=[css], font_config=font_config)
217
+ else:
218
+ html = HTML(string=html_content)
219
+ html.write_pdf(pdf_buffer)
208
220
 
209
221
  pdf_value = pdf_buffer.getvalue()
210
222
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: polytext
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Python utilities to simplify document files management
5
5
  Home-page: https://github.com/docsity/polytext
6
6
  Author: Matteo Senardi
@@ -50,7 +50,7 @@ def get_requirements(*requirements_file):
50
50
 
51
51
 
52
52
  setup(name='polytext',
53
- version='0.1.1',
53
+ version='0.1.2',
54
54
  url='https://github.com/docsity/polytext',
55
55
  # download_url='https://github.com/pualien/py-polytext/archive/0.1.23.tar.gz',
56
56
  license='MIT',
File without changes
File without changes
File without changes
File without changes
File without changes