Skip to content

feature: added generate_pdf_from_html string alternative#1

Open
pecampelo wants to merge 10 commits intoMassimiliano-solutiontech:mainfrom
pecampelo:main
Open

feature: added generate_pdf_from_html string alternative#1
pecampelo wants to merge 10 commits intoMassimiliano-solutiontech:mainfrom
pecampelo:main

Conversation

@pecampelo
Copy link
Copy Markdown

@pecampelo pecampelo commented Nov 8, 2023

This PR derived from a need that came about from a project I am currently building, through which I desired to generate a pdf from a html string, without accessing the disk. I only took the generate_pdf function and exchanged the html_path for the string that can come from an AWS S3 download or something in the liking.

I would like to get your input, @Massimiliano-solutiontech, whether you feel the idea makes sense to this package :)

@Massimiliano-solutiontech
Copy link
Copy Markdown
Owner

Massimiliano-solutiontech commented Nov 9, 2023

@pecampelo thanks for the PR (that feature was planned so your contribution is very welcome!). I'll review it on the weekend

cheers

@pecampelo pecampelo marked this pull request as draft November 9, 2023 23:35
@pecampelo
Copy link
Copy Markdown
Author

pecampelo commented Nov 9, 2023

Putting it as draft since I would like to test the feature a bit.

@pecampelo
Copy link
Copy Markdown
Author

I have made a fully functional application using it, it has proven to be a good alternative opposite to reading from disk. Making it ready for review, would appreciate your input

@pecampelo pecampelo marked this pull request as ready for review November 18, 2023 01:39
@Massimiliano-solutiontech
Copy link
Copy Markdown
Owner

Ok then I hope to find some time today to review it.
I keep you posted

## Quick Start

In order to have a template you must create struct with `PdfTemplate` derive:
In order to have a template you must create struct with `PdfTemplate` or `PdfTemplateForHtml` derive:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

You should even add an usage example and update the test_suite as well

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Makes sense! I will be sure to do that in due time

chromiumoxide = { version = "0.5.1", features = [
"tokio-runtime",
], default-features = false }
chromiumoxide = { version = "0.5.1", features = ["tokio-runtime", "fetcher"], default-features = false }
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The fetcher feature should be added only when is stable on the chromiumoxide crate, maybe you can add as an optional feature as well in this crate

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed it!

options
};
let options = options.build().expect("Invalid browser options.");
let options =
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The no_sandbox flag is useful in containered contexts such as LXC and Docker (when the container is unprivileged but you have only the root user inside the container), it should therefore be left as it is

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

altered it back to how it was

}

pub async fn generate_pdf(
pub async fn generate_pdf_from_html(
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

A &str is more correct because the parameter isn't mutable. If you prefer you can leave it as is and I will change it before the release

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I would appreciate it if you could

SimplePdfGeneratorError::BrowserError(format!("Cannot inject the js: {}", e))
})?;

if !template.tables.is_empty() {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why you removed the tables feature if in the derive is still present? I would like to keep this feature in order to have a more coherent behavior across the library

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That makes sense! I removed it to make it work in my tests, but forgot to readd it. Will be readding it

@Massimiliano-solutiontech
Copy link
Copy Markdown
Owner

I added the comments, feel free to reach me out (even via email: massimiliano@solutiontech.tech) if you need to discuss more the changes

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.

2 participants