we are at the end of our knowledge.
We are using a twig template that is generating a html page which is then rendered by wkhtmltopdf as a PDF on an Ubuntu 18.04 machine.
The current issue is, that we also moved a lot of old EPS files to SVG by using Inkscape and everything works as expected. The images are shown on the PDFs.
Now all our new images are created with AI and saved as well working SVGs like this one:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 25.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 411.02 411.02" style="enable-background:new 0 0 411.02 411.02;" xml:space="preserve">
<style type="text/css">
.st0{fill:#575756;}
.st1{fill:none;stroke:#575756;stroke-width:2.8347;stroke-linejoin:round;stroke-miterlimit:3.8637;}
.st2{fill:#A8A8A7;stroke:#FFFFFF;stroke-width:0.5536;stroke-linejoin:round;stroke-miterlimit:22.9256;}
.st3{fill:none;stroke:#FFFFFF;stroke-width:0.5536;stroke-linejoin:round;stroke-miterlimit:22.9256;}
.st4{fill:#DADADA;stroke:#FFFFFF;stroke-width:0.5536;stroke-linejoin:round;stroke-miterlimit:22.9256;}
.st5{fill:#FFFFFF;}
.st6{display:none;}
.st7{display:inline;}
.st8{font-family:'HelveticaNeueLTPro-Roman';}
.st9{font-size:29.5px;}
.st10{letter-spacing:2;}
.st11{letter-spacing:-2;}
</style>
<g id="elements">
<g>
<polygon class="st0" points="368.71,103 365.16,111.5 361.62,103 368.71,103 368.71,103 "/>
<polygon class="st0" points="368.71,78.61 365.16,70.11 361.62,78.61 368.71,78.61 368.71,78.61 "/>
<line class="st1" x1="365.16" y1="75.86" x2="365.16" y2="106.24"/>
</g>
<g>
<polygon class="st0" points="368.71,324.49 365.16,332.99 361.62,324.49 368.71,324.49 368.71,324.49 "/>
<polygon class="st0" points="368.71,203.75 365.16,195.25 361.62,203.75 368.71,203.75 368.71,203.75 "/>
<line class="st1" x1="365.16" y1="200.99" x2="365.16" y2="327.73"/>
</g>
<g>
<polygon class="st0" points="81.42,345.6 72.92,342.06 81.42,338.52 81.42,345.6 81.42,345.6 "/>
<polygon class="st0" points="349.57,345.6 358.08,342.06 349.57,338.52 349.57,345.6 349.57,345.6 "/>
<line class="st1" x1="352.33" y1="342.06" x2="78.19" y2="342.06"/>
</g>
<g>
<path class="st2" d="M118.14,334.55l-40.3-3.91l-4.91-5.86v-32.87h4.68v-54.02h-4.68v-32.87l4.91-5.86l40.3-3.91h227.47
c7.75,0,14.03,6.28,14.03,14.0
...
But those SVGs do not get rendered. There is always a white space and we tried all possible embed/img/iframe/object/... methods.
I know there could be several reasons but maybe someone encountered a similiar issue. If anything else is needed as information please let me know.
Thanks!
I had the same problem, my solution is :-
Add size internally to SVG.
In your example: width="411.02px" height="411.02px"
Answer use
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="411.02px" height="411.02px" viewBox="0 0 411.02 411.02" style="enable-background:new 0 0 411.02 411.02;" xml:space="preserve">
It may be difficult to see but here is the SVG you posted. I wont repeat the snippet but for others testing, mention the last <g> needs to be changed to </g></svg> and remove unfinished last section.
Showing just the top half of each A4 page (my default)
On the Left is the way it would appear printed from Microsoft Edge.
On the right is the WkhtmltoPDF output (wkhtmltox-0.12.6-1.mxe-cross-win64 in Windows 10) from the same page but with some noticeable problems.
You are using Ubuntu 18.04 thus depending on that compiled version may get different results.
You can see on the left I asked the SVG be placed in the <centre>
But on the right WkhtmltoPDF has offset it further right
However, this may be in part due to the second problem.
The Output on the left was at 1:1 scale, however to get similar proportions in Wkhtmltopdf I had to scale the x:y value 2:1 (which value is actually more units than the notional page width) anyway here is the code for that output.
<!DOCTYPE html><html><head><style>
body {background: transparent; width=794px}
</style></head><body>Hello<center>
<img src="testing.svg" width=822px height=411px />
<br>Figure 1</center><br>World</body></html>
command line wkhtmltopdf.exe --enable-local-file-access local.htm testing.pdf
Related
I like to export my plots in .svg and to tweak colors, etc. using a svg editor after a while.
I can change the color of most elements but I cannot change the color (or line width) of markers in a scatter plot using Inkscape as I normally do.
python code would be
pl.scatter(data_x, data_y, color='C0', marker='+')
# or pl.plot(data_x, data_y, '+')
pl.savefig('myplot.svg')
The .svg part that matters is something like
<g
id="line2d_19"
style="stroke-linecap:butt;stroke-linejoin:round">
<defs
id="defs329">
<path
d="M -3,0 H 3 M 0,3 v -6"
id="mf156d26074"
style="stroke:#1f77b4;stroke-linecap:butt;stroke-linejoin:round"
inkscape:connector-curvature="0" />
</defs>
<g
clip-path="url(#p3979103b39)"
id="g337"
style="stroke-linecap:butt;stroke-linejoin:round">
<use
style="fill:#1f77b4;stroke:#1f77b4;stroke-linecap:butt;stroke-linejoin:round"
x="73.832726"
xlink:href="#mf156d26074"
y="295.48801"
id="use331"
width="100%"
height="100%" />
<!--
...
-->
<use
style="fill:#1f77b4;stroke:#1f77b4;stroke-linecap:butt;stroke-linejoin:round"
x="236.16"
xlink:href="#mf156d26074"
y="53.568001"
id="use333"
width="100%"
height="100%" />
</g>
</g>
matplotlib version: 3.1.3
Thank you,
I figured out one solution which is to delete the style tag in the definition of the mf156d26074 path object beforehand with a text editor.
so to go from
<defs
id="defs329">
<path
d="M -3,0 H 3 M 0,3 v -6"
id="mf156d26074"
style="stroke:#1f77b4;stroke-linecap:butt;stroke-linejoin:round"
inkscape:connector-curvature="0" />
</defs>
to
<defs
id="defs329">
<path
d="M -3,0 H 3 M 0,3 v -6"
id="mf156d26074"
inkscape:connector-curvature="0" />
</defs>
Afterwards, everything works as expected.
Scenario:
I have something similar
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<!-- Using g to inherit presentation attributes -->
<g fill="white" stroke="green" stroke-width="5">
<circle cx="40" cy="40" r="25" />
<circle cx="60" cy="60" r="25" />
</g>
</svg>
Hovering over svg will show a tooltip and I need to test whether tooltip is displayed and the content is correct.
Any suggestions? Tried trigger(mouseover) which in not working
cy.get(svg).trigger('focus')
worked for me
I want to create a home screen design where icons are vertically tilted (not a property stacked design). Also these navigational icons are connected by thick black connecting lines. I tried to use absolute positions but on different resolutions either icons are misaligned or those images are not reaching full screen edges. Can you please suggest how can we create such designs perfectly fit in all kind of resolutions?
You are gonna have a really fun time to do this in RN but it is possible. You can use the transform property in the style to apply a rotation.
Check here: https://facebook.github.io/react-native/docs/transforms#transform
I tried getting the screen size and positioning the each element using position absolute but it was still getting distorted in different mobiles.
If anyone still looking for an answer, I solved this using svg. (not sure if it is the best solution).
If you are not using expo then you need to use react-native-svg. It is already included in expo. Then you can create complex design as svg using sketch/adobe illustrator. Now edit svg image using any text editor and copy the code. "react-native-svg" supports most of the standard svg tags but there is slight difference (you can get that from documentation).
<Svg height={height} width={width} viewBox="150 90 650 806">
<G id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<G id="Group" transform="translate(1.000000, 0.000000)">
<Rect id="Rectangle" stroke="#000000" fill="#000000" transform="translate(400.223611, 262.930718) rotate(-45.000000) translate(-400.223611, -262.930718) " x="440.723611" y="300.930718" width="41" height="46"></Rect>
<Rect id="Rectangle" stroke="#000000" fill="#000000" transform="translate(481.794679, 552.516504) rotate(-45.000000) translate(-481.794679, -552.516504) " x="461.794679" y="525.516504" width="40" height="54"></Rect>
<Rect id="Rectangle" stroke="#000000" fill="#000000" transform="translate(486.235804, 697.148232) rotate(45.000000) translate(-486.235804, -697.148232) " x="464.735804" y="671.648232" width="43" height="51"></Rect>
<Rect id="Rectangle" stroke="#000000" fill="#000000" transform="translate(488.244426, 399.637825) rotate(45.000000) translate(-488.244426, -399.637825) " x="466.744426" y="366.637825" width="43" height="66"></Rect>
<Rect id="Rectangle" stroke="#000000" fill="#000000" transform="translate(363.430718, 723.930718) rotate(-45.000000) translate(-363.430718, -723.930718) " x="343.430718" y="704.930718" width="40" height="38"></Rect>
<Rect id="Rectangle" stroke="#000000" fill="#000000" transform="translate(498.284271, 856.748737) rotate(-45.000000) translate(-498.284271, -856.748737) " x="475.784271" y="835.248737" width="45" height="43"></Rect>
</G></G></Svg>
This was some sample code for creating those connecting lines in the image. In svg you can easily create tilted graphics and fix their positions. It will automatically become responsive as per screen resolution.
I have noticed that when I use Apache Batik to transcode SVG documents to PDF's that have an opacity set to less than one Batik will create a raster version of the SVG and place it in the pdf instead. When dealing with print this is not desirable. Is there any reason Batik does this? Is there anyway to avoid this flattening of SVG documents regardless of their opacity?
Our code to create the transcoder:
PDFTranscoder pdfTranscoder = new PDFTranscoder();
pdfTranscoder.addTranscodingHint(PDFTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER, PIXEL_CONVERSION);
pdfTranscoder.addTranscodingHint(PDFTranscoder.KEY_AUTO_FONTS, false);
We then take the SVG which is returned form element.getEncodedData() as an SVG string.
TranscoderInput input = new TranscoderInput(new ByteArrayInputStream(element.getEncodedData().getBytes()));
TranscoderOutput output = new TranscoderOutput(byteStream);
pdfTranscoder.transcode(input, output);
For opacity we edit the SVG adding a group. Consider the following svg: Note many markup tags have been removed to keep the example concise:
<svg>
<rect x="100" y="100" width="100" height="100" />
</svg>
We would edit this SVG to appear as
<svg>
<g opacity="0.5">
<rect x="100" y="100" width="100" height="100" />
</g>
</svg>
How do you declare the background of an svg script image to be transparent?
If you're viewing in a browser then the background should be transparent automatically. At least it is in FF4 and the latest version of Chrome, but not in some older browsers (e.g. http://petercollingridge.co.uk/data-visualisation/mouseover-effects-svgs).
If you want the background to be semi-transparent then fill the space with a <rect> and set its opacity to a number between 0 and less than 1.
Even easier method is to delete all the data that is used in the file content
Here is a sample before:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="24.000000pt" height="24.000000pt" viewBox="0 0 24.000000 24.000000" preserveAspectRatio="xMidYMid meet">
Here is a sample after
<g transform="translate(0.000000,24.000000) scale(0.100000,-0.100000)" fill="#ff0000" stroke="none">
<path d=""/>
</g>
</svg>
Remove all the data between