-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
addImage produces an blur or too low quality image in the pdf #762
Comments
I'm seeing the same thing. I just migrated to 1.2.61 from 1.0.272 (I didn't change anything else in my code) and images and texts drawn on canvas get very blurred when it gets pushed to pdf. This seems different then my previous results. The pixel mapping from canvas to pdf seems off a bit. Oh, and for reference: each of those top 'tick' marks is spaced exactly 1" from each other. Don't get me wrong, this is an awesome product, and I'm more than grateful. I will say with this many open issues, I'm feeling mighty guilty for not pitching in and trying to close out an item or two. I will say I found this product pretty confusing on the code side. And for reference, here's the actual site. Its something custom bike frame manufacturers or custom off-road hobbyists would use. http://dogfeatherdesign.com/ttn_js |
Same problem here when adding an image from a canvas. I can confirm that image quality looks good in 1.0.272, but is very poor in 1.2.61. I see the issue for both PNG and JPG. |
I'm too getting the same issue. |
Same issue here, good quality on 1.0.272 and average/low quality on 1.2.61, both JPG as PNG. |
in prerelease 1.1.135, the quality is ok |
Same issue on 1.2.61 |
+1 Same issue for me |
Use below code, it will help you in clearing blur image: $scope.doc.internal.scaleFactor = 1.55; |
@bhavik4748 tested with the line, the image quality is slightly improved, but still very poor(aliasing), can not be used in production. Anyway many thanks. |
same issue for me on 1.2.61 |
try scalefactor of 1.7 or 1.8, image will be small be would be more precise. |
Still getting the same problem even after using the scaling line |
@Sketched360 , notice that you should set right mimetype for the images ("image/jpeg" , "image/png") |
I debugged versions 1 and 2 side by side, and came to the conclusion that this is caused by an undocumented change to the jsPDFAPI.arrayBufferToBinaryString function (line 4267 in the jspdf.debug.js). In this function, the following lines have been added: |
@jalgithub Nice find. Thanks! |
@jalgithub thx. Work fine |
@bhavik4748 where do I insert that line of code? in jspdf.debug.js or in my own code? |
@burtontanner Read my comment above to properly restore the old working. |
@jalgithub Those lines are commented out in the version of jspdf that I have and the final image is still blurry. I am just searching to see if there is anything else that I can do. |
@burtontanner Mmm, that's weird, especially since it worked for me and two others at least. Must be something else then... The line @bhavik4748 is talking about (the scaling factor) can be in your code. |
v1.3.2 of jsPDF has been updated with the lines @jalgithub mentioned commented out, so you don't have to manually change it. Increasing the scaleFactor does improve text quality, although things such as radio buttons still appear a bit blurred. any updates on a viable solution? |
Still looking for Solution |
I have the same error, quality is really poor, i tried the code, always the same. is there any other solutions? |
any news about it ? |
Still having trouble. It doesn't look like anyone is actively working on this though. We have taken out the code from: jsPDFAPI.arrayBufferToBinaryString and tried the other scaleFactor items without success. |
@CaptBli - I'm not sure what you have tried exactly, but removing line 4268-4271 (debug version) worked for us, which is this code:
The only other change we made seems non-related, viz. lines 9481-9485 caused an exception on the require, so we removed those as well. It's this code:
(Dunno why the catch didn't work, it's quite a while ago and I'm no JavaScript expert.) |
In addition to adding the StarCityGames decksheet format, a number of under-the-covers changes occurred to facilitate generalizing the codebase to allow multiple decksheet layouts. Some of these changes are as follows: - Decklist parsing (decklist.js) has been fully re-written. All new functions accept parameters (usually optional to resemble previous behavior as much as possible) and utilize return values rather than modifying global variables to allow more predictable behavior, better compatibility between decksheets (individual decksheets can utilize the return value as needed), and improve ease of testing. The primary reason for rewriting parsing was to utilize full card objects (like those stored in the global `cards` array) in decklist layout rather than simple name-quantity arrays. - All extraeneous global variables have been removed. The only two that remain are necessary for the validation and PDF update timers to function. - The page layout has been updated to include a second radio selection above the decklist preview with options for layouts. Additionally, both radio selection lists have had their `name` attributes updated for ease of selection. - Both SCG and WotC PDF layout functions have been re-ordered such that copy-pasting text from PDFs displays in a more sane format - `eslint` directives have been added to main.js and decklist.js to minimize errors - Extra js files have been removed - (incidental) A font sizing bug in the WotC decklist layout has been fixed. (previously if no last name was set, font size was too small) - (incidental) Centered text is now actually centered in the WotC decklist layout With all that said, there are some other possible features that have not been included in this PR, such as: - Section overflow looping. Currently, the SCG decklist caps each section at 15 cards, and does not push overflow into further (or previous) sections. - Adding handling of a new GET parameter to select decklist. As there was no handling for deck sorting, similarly support was not added for decklist choice in this PR. - Disabling of unused fields in specific layouts. The SCG decksheet layout does not use all of the same fields which are used in the WotC format. (specifically, it does not make use of the Event Date, Event Location, and Deck Designer fields) Current behavior is to simply ignore the value of these fields while parsing, but allow further changes to the fields. - Smooth out added images. For some reason, they show up rather jagged, despite being downscaled from their source images. This may be related to parallax/jsPDF#762 Closest example?: parallax/jsPDF#762 (comment) - Utilize the full-resolution StarCityGames.com logo. Currently, for load time consideration, a low-resolution version of the StarCityGames.com logo is loaded, though a higher-resolution copy is available in the repository. Ideally, this image and others should no longer be loaded as base64 strings, but loaded via FileReader or some other API. Ref: https://stackoverflow.com/a/20285053 Finally, due to the update to parsing, there are some changes to existing behavior--primarily small changes in behavior of how unrecognized cards are sorted in lists. As much as possible, the new parsing code behaves similarly to existing code, with the caveat that sorting is not necessarily stable, which likely explains the previously-mentioned sorting discrepancies. Closes april#8 Fixes april#38 Supersedes april#35 Supersedes april#39 Supersedes april#40
When i click my download link for the code below:
I get the following message in my web developer console and no pdf:
Please Help me!!! What am i doing wrong???!!! |
Hi Ira, |
I did stipulate that I'm getting a blurry PDF in my 2nd comment above & i hoped to get some help, i tweaked up my code & did not get anything that's when i posted the "please help me" comment but thanks anyway. |
TBH I tried to cut out the canvas code out of addimage.js and have direct file actions. Thus avoiding the problems we have here. If you do a build of the snapshot you will maybe have no blurry images anymore. I will do some final changes this weekend and then post a snapshot of the build to test. |
Did necessary changes to avoid the internal use of canvas, #2140. Canvas is now used if the supplied imagedata is a canvas element or if the file you want to load can not be loaded by the file loading algorythm. But if you anyway cant load the file with the file loading algorythm, you will get anyway a tainted canvas error. If you use canvas element to supply images, to jsPDF you should increase the dpi/scale and then supply the jpeg-dataurl from the canvas to addImage. Will supply later a snapshot build. |
@irathegod |
Thanks alot, nice one mate, solved my problem after weeks of struggling! |
Hello @irathegod It seems like that your problems described have nothing to do with the problem discussed in this issue. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises Please stop hijacking this thread, which is about addimage issues and not about the lack of basic JavaScript knowledge, which can be googled in 5 minutes. |
Thank you Mr @arasabbasi for your cordiality and courtesy, I wish you all the best in all your life endeavors taking into consideration your overwhelming knowledge & understanding in all things, your etiquette will take you far & beyond I promise! |
Hello @irathegod I understand the sarcasm of your post. If you think I violated the code of conduct of this project, you are free to report me to James. Fact is that a good amount of people have subscribed this thread and want to be informed about the progress. From now on off-topic will be deleted. Tonight I will finally supply a snapshot build and I hope soms people will test it. |
@jalgithub And all others who maybe still interested in the issue: Here is a snapshot/nightly build of the dist files. Can you test if it works for you? |
Changes released in v. 1.5.2 |
I am using jspdf version 1.5.3 and the problem persists. |
On my side, it looked like the presisting problem was with the canvas I used, not with jsPDF itself. When I set the scale to 5 in the canvas generation with html2canvas, I get a very crisp image in the PDF. However, the PDF file gets substancially larger so I figured 3 was a good tradeoff. see #762 (comment) Don't expect this to be "one line / one minute" fix. Since the default scale is 1 (on my device that is), and I specify 3 for the scale, 1 px on the screen does not equal 1 px on the canvas anymore so some additional calculations were needed to adjust positions and sizes. Hope this helps. |
Here is my code, and I got the same problem with version 1.5.3 too:
|
Same issue
|
Same issue still available on 2.1.1 |
any update? |
|
Worked for me. Thanks |
Hello ! I am encountering blur issues when using addImage. Seeing the last comments I see that people were still using workarounds, but this was back in 2021. I am not quite used to unit conversions and canvas manipulations, so maybe the problem is on me, but I just wanted to make sure. |
The last version of jsPDF seems to be from around that time, so it's not really actively maintained, unfortunately. |
please help me |
Help you with what? |
I convert html to pdfjs but open file pdf error front character ( ư ụ ủ v.v ) |
That has nothing to do with this issue. This is a bugtracker, and the specific topic is blurry images. Please open a new bug for your problem. Also, you can't ask for help: you need to report a bug. This is not a forum. |
I am using the latest version of jsPDF 1.2.61, While adding an image it adds an blur image even though the image is of high quality, if I the same base64 in on-line decoder it produces the perfect image as the original, but the base64 produces low quality when I use addImage functionality of jsPDF.
Snippet:
var doc = new jsPDF('landscape');
var Imagebase64=null;
doc.setFontSize(20);
doc.text(35, 25, "GoodYear");
var Imagebase64='data:image/jpeg;base64,/';
doc.addImage(imagePath, 'jpeg',0, 5, 210, 35);
doc.save("mypdf.pdf");
The text was updated successfully, but these errors were encountered: