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 PDF generation feature #29

Closed
wants to merge 1 commit into from
Closed

Add PDF generation feature #29

wants to merge 1 commit into from

Conversation

yusefes
Copy link

@yusefes yusefes commented Oct 26, 2024

Fixes #19

Add feature to save Medium articles as PDFs.

  • Backend Changes:

    • Add a new endpoint generate_pdf in web/server/handlers/post.py to handle PDF generation requests.
    • Import WeasyPrint for rendering HTML to PDF.
    • Update the render_medium_post_link function to support PDF generation.
  • Template Changes:

    • Ensure compatibility with PDF rendering by adjusting styles in web/server/templates/post.html.
    • Add a hidden div with the article content for PDF generation.
  • Frontend Changes:

    • Add a "Save as PDF" button in new-web/src/routes/[slug]/+page.svelte to trigger the PDF generation.
    • Implement a function to call the new PDF generation endpoint.
  • Documentation:

    • Update README.md to include instructions for the new PDF generation feature.

For more details, open the Copilot Workspace session.

Fixes #19

Add feature to save Medium articles as PDFs.

* **Backend Changes:**
  - Add a new endpoint `generate_pdf` in `web/server/handlers/post.py` to handle PDF generation requests.
  - Import `WeasyPrint` for rendering HTML to PDF.
  - Update the `render_medium_post_link` function to support PDF generation.

* **Template Changes:**
  - Ensure compatibility with PDF rendering by adjusting styles in `web/server/templates/post.html`.
  - Add a hidden div with the article content for PDF generation.

* **Frontend Changes:**
  - Add a "Save as PDF" button in `new-web/src/routes/[slug]/+page.svelte` to trigger the PDF generation.
  - Implement a function to call the new PDF generation endpoint.

* **Documentation:**
  - Update `README.md` to include instructions for the new PDF generation feature.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/Freedium-cfd/web/issues/19?shareId=XXXX-XXXX-XXXX-XXXX).
@ZhymabekRoman
Copy link
Member

Hey. Thanks for the PR.
For now I see only one problem - PDF download functionality would be awaiable on the new frontend which is not ready yet. Please, can you patch template files to make it integrate with current using version?

from html5lib import serialize
from html5lib.html5parser import parse
from async_lru import alru_cache
from loguru import logger
from medium_parser import medium_parser_exceptions
from weasyprint import HTML
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add weasyprint as a dependency

@@ -114,3 +114,10 @@ <h1 class="font-bold font-sans break-normal text-gray-900 dark:text-gray-100 pt-
cursor: pointer;
}
</style>
<div id="pdf-content" style="display: none;">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't understand what is this

return HTMLResponse(serialized_rendered_post)


async def generate_pdf(path: str):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see endpoint registration

@@ -68,6 +68,19 @@ Stay tuned for more exciting updates as we continue to revolutionize the world o
contentLoaded = true;
}, 500);
});

async function saveAsPDF() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nahhh, this should be definetly refactored

@ZhymabekRoman
Copy link
Member

Closed with no response.

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.

Feature request: Save the article as a PDF
2 participants