Fixing addHTML crop math so PDFs are not blurry. Fixes issue #339 #397
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If you used addHTML with the pagesplit option enabled, you likely had blurry images / text. There were a couple issues happening.
1st, in the previous line 1863
var args = [canvas, x,cy?0:y,canvas.width/K,canvas.height/K, format,null,'SLOW']
it was passing a recently created canvas toaddImage()
. addImage can take either a canvas or an image. addHTML takes in an object that can be either as well. If it is an image, it calls thecrop()
method. If it is a canvas, it creates an image from the canvas an then callscrop()
. Basically you're either going Image -> canvas -> Image, or canvas -> Image -> Canvas -> Image depending on what was passed into addHTML(). Having the canvas draw the image again was reducing the image quality slightly.2nd, the math to crop the image was slightly off. Unless your browser width was just right, the image would either be squished or stretched. This made a significant "blurry image" look especially with text.
The code I modified now does not need the extra canvas -> image step to crop the image for each page. It also fixes the math so that the image is never squished or stretched.
The issue that I opened awhile ago is #339
Sorry it took me so long getting around to submitting a pull request :)