I've noticed this strange "bug" on my website. Sometimes some svgs aren't loaded correctly. Some images are loaded just fine, some svgs get loaded but not fully. (some parts aren't shown)
Here are examples:
Loaded fully, working fine - https://i.imgur.com/IsZcqwl.png
After closing page and opening it up for few times - https://i.imgur.com/3ManRbR.png
Actual SVG image - https://www.dropbox.com/s/i1ln1a0diko0a12/parrothandshake.svg?dl=0
You svg image: is a base64 converted png.
You can see it in the tag attribute here: xlink:href="data:img/png;base64,iVB[...]
I would not recommend using base64 at all. Even more so in a image tag inside an svg image. (This is debatable and opinion based)
I would recomend using Inkscape to convert png images to svg. There is a build in function for converting in the editor. Its also free and a handy tool to have when working with svg images.
Related
SK is supposed to be able to support vector artwork as long as it's in valid PDF format. But what the heck is "valid"?
I found a simple SVG and converted it to PDF using convert.io. I put it in an xcassets, set the scale to Single Scale, and off it went.
Then I got another SVG, converted it to PDF using convert.io, put it into the same xcassets, set the scale to Single Scale and got:
Error loading image resource: "tank"
The PDF seems perfectly ok, it loads fine in Preview and Gapplin and I can't see any difference between it any the one that does work.
Does anyone know how to debug this?
I'm trying to create a small PDF file, embedding one optimized PNG image displayed as a header and footer on a 3 page PDF (same image must appear 6x in the PDF)
My optimized PNG image is only 2.3KB. It looks very sharp.
Failed with libreoffice
When I insert just one instance of the 2.3KB PNG image into a Libreoffice Writer doc containing only text, then export as PDF I can see that the image gets re-compressed to JPG and the resulting PDF file grows by about 40KB after adding the image. It also loses quality, the PNG also gets JPG fuzzy edges.
If I right click the image and select compression, there is no way to disable recompressing the image (it's already optimized better than libreoffice could do it) I've tried setting a compression level of 0,1,9 etc. Choosing JPG, no resize, lossless, etc but there was no improvement.
Failed with wkhtmltopdf
I also tried making a test page and used wkhtml2pdf but it did the same thing. Adding the low quality flag made no difference.
PDF Spec suggests PNG is supported?
From skimming the PDF spec, it looks like PNG images are supported.
Even plain text PDF files are surprisingly large
The disappointing thing is also when I take a 7KB HTML file which is basically just <html><body><p>foo...</p><p>bar...</p> (only about 15 paragraphs) with no CSS. The resulting 2 page PDF file is 30KB. Why should a 7kb (almost plain text) file become 30kb as a PDF?
Suggestions?
Can someone please suggest how to make a small PDF file in Linux?
I need to include 7KB of text and repeat one PNG image 6 times.
Manually or programatically. I'll take whatever I can get at this point.
PDF Spec suggests PNG is supported?
PNG isn't supported per se; PDF allows embedding JPEG images as-is, but not PNG images. PDF does borrow a set of features of the PNG format, however.
rinohtype (full disclosure: I'm the author) tries to embed as much as possible from PNG images as-is into the PDF. This does involve some bit-juggling to separate the alpha channel from the color data for example, but no reencoding of the image is performed. It does not (yet) support interlaced PNGs.
rinohtype should be able to do what you want to achieve. But please note that it currently is in a beta stage, so you might encounter some bugs.
Even plain text PDF files are surprisingly large
To keep the PDF size as small as possible, make sure not to embed/subset any of the fonts. Use only the fonts from the base 14 PDF fonts which are provided by PDF readers.
What you want is certainly achievable. Regarding the image quality, I would recommend making your image twice the size that you want it to actually display at in the PDF to keep it looking sharp.
As to the size, I've just modified a test in my PDF writer module (WIP..) to include a 7.2K png, 200px x 70px, in a PDF twice and the PDF came out at 6.8K 8). There's not much text included, but more text will only add what it's worth + a small percentage.
You can see the module and original test here.. https://github.com/DoccaPDF/docca-pdf-writer/blob/master/src/tests/writer.js#L40
That test adds ~112K of images to the PDF and results in a 103K PDF.
Of course not all images are created equal so you milage may vary..
*the images are only actually added to the PDF once, but are displayed multiple time.
I’ve been using the PDFConverter for years with no issues. And there are still no issues converting a large HTML form to PDF, except certain images aren’t showing.
I programmatically fill an HTML img element with a base64 string, like so:
imgSignature.Src = "data:image/jpg;base64," + Convert.ToBase64String(SignatureImage);
where SignatureImage is a byte[] array.
I've observed that if the byte[] array size is more than around 7K (not sure exactly the threshold), the image will not render to PDF (at least it’s not visible anyway). Anything under that displays fine. Note: the image displays in HTML just fine. It's when converting to PDF that it disappears if the byte array is too large
I've tried adjust the size of the img, the container it's in, everything I can think of.
Currently still going through Winnovative support docs but no luck so far.
Thanks for any advice.
Just in my case, I changed all images formats from jpeg to png, and it works for me. It's worth mentioning that my images are between 6kb to 8 kb (the images are Bar Codes)
I'm working on a Raphael project that draws vector graphics with repeating PNG fill elements. To minimise file requests and maintainence, I'm storing these PNGs as base 64 strings in the JS. IE8 needs to be supported, sadly.
On SVG, this works fine. In VML on IE8, it doesn't work, despite the fact that a) VML supports image fills and b) IE8 supports base 64 images.
Is there any way I can get my PNG data into my VML without needing to upload actual PNG files?
Here's an example of how the string that is passed to Raphael's .attr('fill'); is being defined:
"url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADpJREFUeNpi/P//PwMMnDp1whRI8bMwoAIxIHZgPHnyOLKgBBD/BqkEawHiPUD8AiTDBNXijqwcIMAANW4Lseujok0AAAAASUVORK5CYII=)"
Same problem with single quotes inside the url():
"url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADpJREFUeNpi/P//PwMMnDp1whRI8bMwoAIxIHZgPHnyOLKgBBD/BqkEawHiPUD8AiTDBNXijqwcIMAANW4Lseujok0AAAAASUVORK5CYII=')"
Debugging VML is always a nightmare, but using the trick here and hacking my way to the VML shape's outerHTML property, I can see that the above is being applied to the fill element's src property:
<rvml:fill class=rvml firebug-1432221487827="1566" rotate = "t" src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAEJJREFUeNpiPHnyOAMUZANxPRA/ZGFAAFkgFgVhkGAcEPMDMRsQ7wTiHyDBhVCVE4DYA8RgAuLXQPwNiF/CzAEIMABgqgriagn8AQAAAABJRU5ErkJggg==" type = "tile" position = "13861519f,3859415f"></rvml:fill>
I opened one PNG file in Inkscape and exported it as SVG. When I opened that file with notepad I came to know that the PNG file is embedded within it. If the conversion happened then the resulting file should have only SVG related tags. It shouldn't embed the image within it. Or Am I doing anything wrong.
Note: Save as option also producing the same kind of file. I am using Inkscape version 0.48 in Windows 7 - 64 bit.
This is a bit of an old thread, but it comes up early in Google so I thought I'd contribute something.
In Inkscape, you must do a trace to change the image into SVG. Look at the Path | Trace bitmap menu item and play with the options on that screen.
After creating the trace, you can remove your source image and have a pure svg in your saved file.
I've found it helpful to create layers in Inkscape and move the source image to one layer and put the trace on another layer to let me make quick comparisons using the 'hide layer' buttons.
BTW, your source image can be anything - bmp, jpg, png, etc.
A .png file is a raster image file. In order to convert it to a vector graphic based format like .svg and have it be "native" svg rather than an included image you are going to either have to use a program that can rasterize it or in Inkscape trace the bitmap and turn it into paths. Inkscape provides information on tracing: http://inkscape.org/doc/tracing/tutorial-tracing.html