I am trying to create PDF which should contain image, but does not. The xhtml that is converting to PDF contains img tag with correct base64 data, because when I try it in any html I see correct content. I am using core-renderer R8 version. I kinda suspect that might be a problem because it is 8 years old.
This is the sample that is correctly set in xhtml content.
<tr>
<span>Some info text...</span>
<img alt="some QR Code" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASIAAAEmAQAAAADuVKANAAADV0lEQVR42u2aPW7bQBCFh2CxLgSwTUfkBi5TWVdJbuAuLoiQAIHwWkvoIssbbBcCITiZN0sHMS3SAhIguwlVyBL0SfLTzps/ifiGi6WDOqh/jfK0e8kD9W3/hb4f1EH915QVrxg105lblj810xl3sxSoXrSYGX7PfFWanptSnlTrAwlQnkpji2nJeT0A9hWZdKhe5AFwSLkOatOiEFXcOpazKiW+kqEQXzY8VgtVtLwVhRFS6u1ejfHL1dUMECG1dCA5j5k8ppK3sm+EFPQYNfNMYpG5mErtpUwSlJWAEmUN0YPcElsvVh/PKVDsc6kK8MRMtZNbWhWqlcZYqR75qPe5g6MdDM6ilt06A8RJSTkrRV6OvKo1TaoCMuz6HOOkcEKiZ1pqgaUKvQVKXAqU5lCCUJwVIi0E2UuN0VIij2EMOZdG6zDOairHLAVq1nzEkw7F5fiAvCrZylESlORQGmEHeghtHNAr8RUnBVtLDp1oJOQjqxm20GNKgNK236IWWA0yKWfIqzwmQcHMOBz1BGlrJ09iR2lQokw9IfJCYRN56Oo4BQqjozZCWpFxVqTjpEmCYm6lhdYSDJdn0AjJY5YEhZqG9kf76BFqQ8ydU6Dg6BBkWdj6YP+DUZ5ToLR5UyDTWey5n0iDssihGRoIzO6IqlAkkqFckMeso2MdHLOeAuKk+kWehFaoBVPYHKZChdByOgDw8/z4qo+OlJLmjbUgsMYXtj6WkqHQ+9uQmSbto3H31XYlUirsrMKuJw97EwwF6ykzUkr1zPhmIltWhaXeWk34kVLLrjYsZ5FhG8zBUyqUrtgYSQlbQi3QVstyMpSV0VG3V0Ej6tx6+o2Zwug4h74orG7LVxvdOCltIMLU2Cx9NEl6uhKFEVLqbd3yU+ijJc3OuOIUqON794M6qN+gsG9/eWmu/Orpb/5mq5M557xNjYUzbMs3KG9cztZ0PFY7lMtdxjZ/g+r7YeBL+wbVDqAuXeZP7325RXV+6EGRP5Evtin57+UdH5+q+89mhzLQOD5VH+puhyqkE+2sUNXOaw36qZJQj2ZHY8sX/non1Mdu5/PqQb0T6lO3/dn/pO6HTcrngwNF1Ymc2Y6JwdcX7u6+nHK/+Vpc3BSFdBPV3ETZP+GOH1khlTts3E3LAAAAAElFTkSuQmCC" />
</tr>
You can check by yourself in any html doc that it generates picture of QR code.
ok guys, solution is simple, so if you are using prehistoric core-renderer R8 rather update to flying-saucer renderer which solved my problem
Related
I am using the following code to insert an image in Jupyter notebook which is compatible with html conversion:
from IPython.display import Image
Image(filename="picture.jpg")
This works nicely except the fact that it is left aligned and I need it centre/middle aligned.
Is there any method that I can set it to be aligned correctly?
This works for me:
<center><img src="picture.jpg"/></center>
You can set the cell as markdown and use this content:
<img src="picture.jpg" width="240" height="240" align="center"/>
Then run it.
Edit1
Alternatively, you can use a code cell with this code:
from IPython.display import HTML
html1 = '<img src="picture.jpg" width="240" height="240" align="center"/>'
HTML(html1)
Many browsers (Chrome, Firefox) are only supporting HTML 5, so this syntax no longer works, even within the notebook itself.
<img src="picture.jpg" align="center"/>
because align="center" has been deprecated. Now you should use CSS style properties and the various margin definitions.
<img src="picture.jpg" style="margin-left:auto; margin-right:auto"/>
or
<img src="picture.jpg" style="margin:auto"/>
See here for more discussion around this. This makes it look properly centered while being displayed in your Notebook. But frustratingly doesn't work (still left justified) when you export your notebook to HTML. Inspecting the HTML that is generated you find that the <img> is embedded in a <p> element and this throws the whole thing off. So you have to add an additional display=block property, making the whole thing
<img src="picture.jpg" style="display=block; margin:auto"/>
This will center the image in your notebook, exported HTML, and exported Markdown files. Thanks to these guys for the tip on the display=block bit.
To get a centered bit of text underneath the image (like a figure title) I throw in a
<p style="text-align: center">
<b>Figure N. My Cool Figure</b>
</p>
afterwards. The whole setup is then
<img src="picture.jpg" style="display=block; margin:auto"/>
<p style="text-align: center">
<b>Figure N. My Cool Figure</b>
</p>
I am using Tinymce as an email editor. When inserting an embedded image as attachment, the images are inserted as:
<img src="cid:mycid#sth" />
This works for the email sending part - but of course not for the editor. The image is not displayed...
Question: Is there a "content" and "display" layer in Tinymce where I can hook into?
My goal is to save the content as
<img src="cid:mycid#sth" />
and transform it in the editor window as
<img src="/mypreview/image/2000" />
I am using Tinymce 4.
The editor relies on the browser for the rendering of HTML so anything like your <img src="cid:mycid#sth" /> won't render in the editor - its simply not valid HTML.
What you can do is rely on data-xxx attributes in HTML to store the data you really want and transform the HTML when you go to load it into TinyMCE.
For example...
When someone inserts the image you could create the following HTML
<img data-src="cid:mycid#sth" src="/mypreview/image/2000" />
...this would allow the editor to actually render an image while you still keep the data you need. When you save the content you can strip out the existing src data and copy the data-src content back into the src if that is what your app needs for its server side processing.
If someone edits the content you can just reverse the process and change the src back to HTML that TinyMCE can render.
Consider the following code:
from xhtml2pdf import pisa
if __name__=="__main__":
source_HTML = """<html>
<body>
<a href="http://www.stackoverflow.com">
<img src="http://i.stack.imgur.com/uQFNA.png"/>
</a>
<a href="http://www.stackoverflow.com">
<p>Stackoverflow</p>
</a>
</body>
</html>"""
output_filename = "output.pdf"
# open output file for writing (truncated binary)
result_file = open(output_filename, "w+b")
# convert HTML to PDF
pisa.CreatePDF(
source_HTML,
dest=result_file)
result_file.close()
The html should render both an hyperlink image and a hyperlink text, but xhtml2pdf renders the image without the hyperlink and the text with the hyperlink. Is this an issue with the code above or a limitation/bug with the library? Thanks in advance for any help with the above issue.
I found a way to get this too work but it is not very good.
You can add a before and after the img inside the A tag. And then set the font-size on the A tag to be the height of the image and then also set text-decoration to none.
So like I said this works but is not a great solution. I searched issues on xhtml2pdf's github page and cannot find anyone else with this issue.
I'd like to ask you which img tag is right:
<img src="http://i.imgur.com/r5wwImhb.jpg">
or
<img src="http://i.imgur.com/r5wwImhb.jpg"/>
Thank you.
It depends on if you are using HTML or XHTML. The first one is correct in HTML and the second one in XHTML.
According to the first search result for <img> tag on w3schools:
In HTML the <img> tag has no end tag.
In XHTML the <img> tag must be properly closed.
I am creating an email template which has to display images from external website. I had placed some <img> tags for rendering the images and there are some <td> tags with background-image property set in inline css of the elements.
Now, when an email is received in outlook, the images are not displayed (this is expected as the images are not embedded). And I click the download images to see the images properly. The images in <IMG> tag are only shown and the background-image for the <TD> is not rendered.
Any views on solving this problem?
Thanks!
At last I found the answer.
Outlook 2007 does not use the Internet Explorer's rendering engine for loading HTML content. Instead it uses Word 2007 HTML and CSS capabilities.
Because of this CSS attributes such as background-image is not supported. And hence it's not possible to set a background image for HTML elements in outlook using standard CSS tags.
More info is available at http://msdn.microsoft.com/en-us/library/aa338201(v=office.12).aspx
Background images are not supported in Outlook. As a best practice, you should never use background images in HTML emails. If you must have a background, you can use and image PLUS a solid color. Those with email clients that support background images will get the images, and those that don't support it will fall back to the solid color.
There is actually a method to use background images in HTML emails in Outlook.
As Chaitanya mentions it can't be done with CSS, but it can be done via VML.
The technique is a bit more involved than using background: url(....) and I don't use it as frequently as I would use the CSS technique (if it worked in Outlook). But it is very useful.
I've used it successfully on a number of campaigns.
Full instructions here: including a list of email clients that support this technique.
http://www.campaignmonitor.com/forums/viewtopic.php?pid=14197
Also, here's a guide from Campaign Monitor: http://www.campaignmonitor.com/css/ which proved super helpful for me.
There is a way of displaying HTML images.
Right html emails rendered as MSWord document in outlook.
I got the solution from this https://stackoverflow.com/a/12693917/413032 post.
So we need an alternate.
In fact you may open your html email in MSWORD and finding what seems wrong and considering what can be an alternate gives idea.
Here is what I did ;
Added v namespace to html tag
< html xmlns:v="urn:schemas-microsoft-com:vml"
Added v's style to head block
< head >
<style type="”text/css”">
v\:* { behavior: url(#default#VML); display:inline-block}
</style>
In table or where you need add your MSWord alternate
<table style="background-image: url('https://e-telesaglik.com/images/email/canvas-bg.jpg');background-repeat:no-repeat;" cellpadding="0" width="960">
<!--[if gte vml 1]>
<v:shape
stroked='f'
style='position:absolute;margin-left:-90pt;margin-top:-1.55pt;
z-index:-503306481;
visibility:visible;
width:720pt;
height:475pt;
top:0;
left:0;
border:0;
'>
<v:imagedata src="https://e-telesaglik.com/images/email/canvas-bg.jpg"/>
</v:shape>
<![endif]-->
<tbody> ....
That is all.
Sure it will be a MSWord render. And more, as you notice we use absolute positioning...
Anyway this is a workaround and solves the issue in a way.
We hope one day MS-Outlook renders html e-mails with a web browser not with MS-Word.
This works in Gmail,
I tried this to show div with image in email newsletter, try inline css, sending email guidelines here