Graphviz: <img/> not displayed in 'svg' output image - python

I am using Pygraphviz library with python 2.7. I'm generating 'svg' output images. What I like to do is to use an 'svg' image as the label of my graphs. To do that, I am using the html tag (http://www.graphviz.org/doc/info/shapes.html#html).
Here is the part of my code that is responsible to do that:
dot = Digraph(comment=zone)
dot.graph_attr['label'] = "\
<\
<TABLE>\
<TR>\
<TD><IMG SRC=\"/path/to/svg/image\"/></TD>
</TR>
</TABLE>
>"
The svg output image is created but my svg logo is not displayed; the table is empty)
Any ideas?

I know this is a very old question, but as this is the first result on google and I stumbled over this as well I thought I'd share:
You can open the *.svg with a text editor to check that the links are there and point to the correct location xlink:href="/path/to/svg/image" (which was the case for me)
Make sure to open it with an application that actually loads the images (e.g. firefox, chrome, inkscape). The default image viewer in gnome, GIMP, Krita, etc. open the image just fine, but don't load the images by default, resulting in an empty table/node.

Related

cairosvg renders pngs wierdly in python

I am working on a small image comparison script and I am using Cairosvg to transform my source data(svg) into png. However this gets rendered wierd, like spaces between objects get removed. Does anybody have an idea why?
original:
https://prnt.sc/70Gw5shayPtT
rendered
https://prnt.sc/Dqk_nIiCHplQ
Edit: it also moves Objects to different Locations inside the canvas

want to over-write or manipulate page size of PDF

Reference Image
This is a snapshot for reference, here and I want to resize the default size of the PDF that I have marked with a rectangle box. I can do it manually with any media editor but I want to do it with Python or with command-line with the help of the editor like Inkscape.

Jupiter: nbconvert does convert HTML image to LaTex

I love using jupyter notebooks to document topics for my physics course, so I am having my students use CoCalc and either Markdown or Jupyter notebook to write their lab reports. I have a problem.
In a jupyter notebook, the Markdown way to insert an image is ![Two slit](twoSlit1.png), for example. However you can not control the size, location and wrapping. Stack Exchange helpfully has many suggestions [here] to control the size 1.
However, when I try to convert it to pdf, the images get lost if they are inserted using HTML. For example
![Two slit](twoSlit1.png)
converted with jupyter nbconvert Example.ipynb --to html works fine, but with no control over image size of placement. I can then print this to pdf, but it does not have a good "document" look. But
<img align="right" src="twoSlit1.png" width="200" />
converted with jupyter nbconvert Example.ipynb --to pdf gives a pdf rendering, but the images are missing. I tried many different HTML image codings, but none work with nbconvert --to pdf
The CoCalc File -> Download as PDF via LaTex (.pdf)... does note render the images either.
I get similar results on CoCalc if I create a Markdown document and use pandoc Example1.md -o Example1.pdf to create a pdf file.
BTW, both render the equations perfectly.
I also get the same results on my Mac running jupyter locally (Anaconda distribution, python 3.7)
I got prompt answers William Stein and Harald Schilly at CoCalc when I posted a support request. Here is my answer.
The issue is that the Markdown (and probably the jupyter notebook Markdown cells) Preview pane is rendered in the frontend, not using pandoc in the backend, so when I used pandoc from the terminal I got a different result.
I could get HTML that looks reasonable by putting a HTML <style> tag at the beginning of the Markdown document and putting CSS code in the <style> tag. Then I put my image in an HTML <div> that used the CSS to set its size, float it right, add a caption, etc. I also reduced the size of the header fonts, set the font-family to serif, etc in the CSS file. Then the Preview looked OK, but there were still problems when I printed the Preview and saved it as pdf. So:
Just use Markdown and use HTML for just a few things: a) A <div class="center"> to center the title, author, ... b) <blockquote> to style the abstract. c) A <div class=figure width="280px"> to insert floating figures.
Create a file style.css and run pandoc from the commandline using
pandoc Example.md -s --css="style.css" --mathjax -o Example.html
Open Example.html in CoCalc and use the print icon in the rendered pane and save the pdf file.
I am satisfied. The students can get decent reports without the extra labor of working with LaTeX and with a minimum of HTML. I give them the CSS file.

TextColor set to invisible in python generated pdf after filling fields from a pdf template with pdfrw

After following these instructions I ended up with a working script that generates a pdf as I desire. Unfortunately, the text is only visible upon clicking the filled fields! (this only happens when using adobe reader, not when viewing the page through web browsers)
Seeing as users of the module aren't experiencing this issue I'm fairly certain it has something to do with the example script.
If I reassign the black text color in the generated pdf the text shows up as I want. So I'm assuming the issue has something to do with the textColor of the filled fields.
Any ideas how to solve this? (Can I assign field text color through pdfrw as a workaround?)

Saving Ipython Notebook with html figures as pdf?

I am using Ipython Notebook and I would like to save the notebook as pdf. When a notebook contains html figures in markdown mode I cannot export them
In example:
<img src='http://draftingmanuals.tpub.com/14262/img/14262_140_2.jpg'>
represents the following:
However, when I download the notebook as PDF via LaTeX (pdf) the result is without the figure:
Is this a bug or can I avoid this somehow?
This is not really a bug, but a known limitation. Actually there are two issues in your example:
the raw html <img> tag gets stripped when the markdown cells are converted by pandoc to latex (see pandoc docu).
you link to a remote image, which is (currently) not downloaded prior to the conversion.
Thus, it is a bit tricky to get what you desire. The first issue may be overcome by means of a custom filter and custom template. For the second, you may need a custom preprocessor.
Alternatively, you could use python with urllib (e.g. Downloading a picture via urllib and python) and matplotlib to display this image. Such embedded images are converted fine.

Categories

Resources