Forum Bugs

SVG to PDF An unknown shading type was encountered

adrianbj
Wondering if you can look into this problem for me. I actually get the same problem with Inkscape, rsvg-convert, scribus, uniconveror etc, so not sure what is going on, but this SVG results in:
"An unknown shading type was encountered" error message when opening in Illustrator. There is also a clipping mask applied to the entire image and editing is not possible, although it is still completely scalable.

<linearGradient
   id="path1581_2_"
   gradientUnits="userSpaceOnUse"
   x1="-169.4004"
   y1="287.6299"
   x2="-126.9098"
   y2="330.1205"
   gradientTransform="matrix(1.202 0.6427 0.4359 -0.8152 75.4094 356.3559)">
	<stop offset="0" style="stop-color:#927A62" id="stop7" />
	<stop offset="1" style="stop-color:#93866F" id="stop9" />
</linearGradient>
<path
   id="path1581_1_"
   fill="url(#path1581_2_)"
   d="M60.804,0.023c-0.958-0.163-4.029,0.558-7.365,1.317  C50.11,2.095,48.038,4.425,45.762,5.2s-15.721,1.957-26.415,4.912c-9.763,2.684-17.372,6.094-18.044,6.414  c-1.454,0.686-1.78,2.303-0.523,2.452c1.263,0.149,12.283-4.857,17.378-6.196c5.088-1.359,18.371-5.271,24.152-5.625  c3.478-0.189,9.402-0.516,14.967-0.509c3.743,0.014,7.154,0.285,10.204,0.394c-0.903-0.836-6.298-0.666-9.267-1.154  C55.271,5.398,48.2,6.152,48.2,6.152s2.364-2.908,4.722-3.817C55.273,1.409,61.795,0.187,60.804,0.023z" />
</svg>



If this could be rectified, it would make Prince the only SVG->PDF converter that would actually work properly, other than Illustrator itself, but that is not an option since I need to script this on the server.

Even just noticed that adobe distiller (print from Inkscape) can't do it properly - why is it so hard? The especially weird thing is that the SVG was originally created by saving from an Illustrator file.

Thanks,
Adrian
mikeday
I don't know about Illustrator, but I can successfully load the SVG you've posted in Firefox, Inkscape, and Prince (after adding the root svg element at the beginning).
adrianbj
Sorry, maybe I wasn't clear enough - the SVG is fine. I am trying to convert it to PDF. It is the converted PDF that is the problem. As I mentioned, I have tried several tools and all result in that same error message. The file still opens and looks fine, but can't be edited properly.

Oh and just to qualify, my SVG does have the initial root element - I just left it off for the sake of brevity.

Thanks
mikeday
Oh, Illustrator is complaining about the generated PDF file. This sounds like a bug in Illustrator. Have you tried raising the problem with Adobe? They have a support forum that can be helpful.
adrianbj
Well I tried opening and editing the resulting PDF in Inkscape - it appears to open fine, but the gradient doesn't show properly and there is a clip applied to the drawing. Clicking the shape with the edit path tool shows that there is a gradient - shown at the bottom left of the window - as the linear gradient fill, but the drawing itself only has one color visible in the fill. Also if you try to move one of the nodes, you can see the clip preventing the rest from showing and it doesn't seem to matter how many times I try to release the clip, it doesn't improve.

Looking at the XML of the imported PDF in Iknscape gives me a better idea of what is happening - if I delete the clip group, the clip disappears and the shape is properly editable again, but the linear gradient is still not showing, even though the defined id matches what is being used in the fill.

Anyway, I don't think it is an Illustrator issue - I could be wrong, but it seems like something is being messed up.
adrianbj
I have narrowed things down further.

There are two circumstances that result in problems for me.

1) A gradient with only 2 stops.

In the following example I have duplicated the offset="0" stop which fixes things if I convert the SVG to PDF with either Inkscape or rsvg-convert (cairo) - the resulting shape that is filled with this gradient works fine, but still not with Prince, so in this situation prince seems to be behind. Without the duplicate declaration, the gradient is converted to an un-editable image with a clipping mask when the PDF is viewed in Illustrator, no matter what converter I use.

      <linearGradient id="ian_symbols_b8a58aafc1f12e74492e9e865b7f569b" gradientUnits="userSpaceOnUse" x1="113.7275" y1="136.9414" x2="197.0259" y2="136.9414">
        <stop offset="0" style="stop-color:#927A62" id="stop1472" />
        <stop offset="0" style="stop-color:#927A62" id="stop1472_dup" />
        <stop offset="1" style="stop-color:#93866F" id="stop1474" />
      </linearGradient>


2) A shape that has an opacity that is less than "1". I don't know how to fix this one and still maintain the look of the original. I understand that there are some issues with transparency and the PDF format, but obviously the full AI version of the PDF format these days supports transparency.

So, could prince handle these conversions better, or is there something I can do with the original SVG code to make the opacity work ok in the final PDF?

Thanks
mikeday
Strange, I'm not sure what the problem is with the multiple stops. Thanks for the detailed test case, we will investigate this issue! :)
adrianbj
I have created some simple examples for each problem in Illustrator. I have been using rsvg-convert because it is at least working with the duplicated stop, but thought this might help you diagnose the problem that is happening with PrinceXML.

1) I saved each one directly to PDF1.4 (transparency_original.pdf and two-color-gradient_original.pdf)
2) Then I saved each one to SVG from Illustrator (transparency.svg and two-color-gradient.svg)
3) Then I used rsvg-convert to make transparency_converted.pdf and two-color-gradient_converted.pdf

You'll notice that both the original PDFs and SVGs open in Illustrator fine. However, both the converted PDFs have problems. The two-color-gradient example has the "An unknown shading type was encountered." error and when it opens up, the shape is no longer an editable vector.

4) Then I manually edited the SVG and duplicated the first stop in the gradient (two-color-gradient-with-dup-stop.svg)
5) Then converted this with rsvg-convert to two-color-gradient-with-dup-stop.pdf

You'll notice that this new PDF opens up fine in Illustrator and the shape and gradients are fully editable.

As for the transparency example - the converted PDF loads without error, but the transparency is no longer applied and there is a clipping mask on it.

Hopefully these examples will help you debug what is going on.

Thanks,
Adrian
  1. therest.zip153.5 kB
  2. twocolorgrad.zip153.6 kB
mikeday
Thanks for the detailed testing! :)
adrianbj
Any breakthroughs on fixing this?

Thanks,
Adrian
mikeday
So far we've had trouble narrowing it down to some aspect of Prince behaviour that we can actually change. Is there some way we can reproduce the shading problem outside of Illustrator?
ontic
I came across the same error message when converting this SVG document (http://apike.ca/media/svg/exampleClip2.svg) to a PDF file, then opening with Adobe Illustrator.
hallvord
Prince gives me a warning saying "warning: svg: clipPath: union of clip paths not well supported." on that file.
It does indeed contain gradients with stops, similar to the earlier examples in this thread:
        <radialGradient id="myFillGrad" r="100%" spreadMethod="reflect">
            <stop offset="5%" stop-color="blue" stop-opacity="0.5" />
            <stop offset="95%" stop-color="midnightblue" />
        </radialGradient>

Announcement: repos for tests/utils

mikeday
Opacity in gradients is not supported yet and will be ignored, and yes unions of multiple clip paths is also a bit questionable in some cases.

However Adobe Illustrator does not promise to open any PDF file unless it was also generated from Illustrator; it is not a general purpose PDF viewing or editing tool.