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

cannot force contentType in addPage #169

Closed
Naouak opened this issue May 30, 2016 · 8 comments
Closed

cannot force contentType in addPage #169

Naouak opened this issue May 30, 2016 · 8 comments

Comments

@Naouak
Copy link

Naouak commented May 30, 2016

When using addPage, the system uses a regex to determine what type of content the input is. If your content is malformed but still valid for webkit, it will use the input as a filename instead of saving it to a file.

addPage needs a way to tell whether it' s a filename or content given.

Example :

$pdf->addPage("<h1>TEST</h1>");

Will try to render the file "

TEST

" instead of rendering HTML.

@mikehaertl
Copy link
Owner

That's correct and there's not really a simple way to fix this. So you should make sure, that your HTML strings always contain a <html> tag somewhere.

@Naouak
Copy link
Author

Naouak commented May 30, 2016

It's simple to fix this, permit to pass an override to the function. Here is a gist how I could do it easily (which could be easily backported to lib):
https://gist.github.com/Naouak/98b2afc88386dbfafc4d97c09f86be49

@mikehaertl
Copy link
Owner

I'm not sure, what you try to achieve. How is this related to the content type? Can't you simply set that in your HTML string?

@Naouak
Copy link
Author

Naouak commented May 30, 2016

I'm building a middleware for rendering a webpage in pdf in a framework. I don't know what kind of html I will receive. Webkit can perfectly parse some HTML without the doctype or even the tag, I want to be able to have a pdf when those are absent without checking myself first. It's stupid to run twice the regexp when I already know what it's supposed to be.

@mikehaertl
Copy link
Owner

Ok, seems to make sense. I've added your suggestion to master. Note, that you should use Pdf::TYPE_HTML. Could you help testing?

@mikehaertl mikehaertl reopened this May 31, 2016
mikehaertl added a commit that referenced this issue Jun 2, 2016
@mikehaertl
Copy link
Owner

@Naouak I've just release 2.2.0 with your suggested changes.

@Naouak
Copy link
Author

Naouak commented Jun 3, 2016

Thanks. Sorry I couldn't help you test it.

On Thu, Jun 2, 2016 at 10:08 AM Michael Härtl [email protected]
wrote:

@Naouak https://github.com/Naouak I've just release 2.2.0 with your
suggested changes.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#169 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAJKxpyijy9nIOyqDUFlZS42h0QGifTcks5qHo97gaJpZM4IppUR
.

@mikehaertl
Copy link
Owner

Feedback is still welcome, so it would be great to let me know if the change now works for you.

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

No branches or pull requests

2 participants