I am trying to rename my hyperlink to place in a pdf file. Thus, I do not want to give to the user a massive long link.
Let's say my link is like:
https://www.google.com/search?q=images+of+dogs&rlz=1C1OKWM_esES969ES969&sxsrf=AOaemvJFDb3FKdXO1Yqb3A1BdjWNfw0Edg:1632237403618&tbm=isch&source=iu&ictx=1&fir=D5X9VdSPli-xYM%252CHUMB4Zy1hHwFaM%252C_&vet=1&usg=AI4_-kShuarwW69ikZrP2YUHRVOpRHKKfQ&sa=X&ved=2ahUKEwiPs4aVrpDzAhUR1RoKHQiNAZIQ9QF6BAgPEAE&biw=2133&bih=1013&dpr=0.9#imgrc=D5X9VdSPli-xYM
And I want it to appear in the pdf like:
"Link to picture"
My code:
texto_body=f"Hi,<br> <br> This is a test with a link {link} <br> <br> Thanks,"
body=f"""\
<html>
<body>
<p style="color:black;"> {texto_body}</p>
<img src="cid:image1" alt="Logo" style="width:90px;height:90px;"><br>
</body>
</html>
"""
Solved. I found that text of the link
is the way to set up hyperlinks with a given name
Related
Apologies if this question has already been asked. I'm new to HTML and I'm not familiar with the words I should use to find help with.
I'm using Flask and HTML to make a website.
My code:
<!DOCTYPE html>
<html>
<body>
<h3>Click the result you want to investigate</h3>
{% for r in results %}
<p id=r["links"] onclick="myFunction(id)"> {{r["title"]}} ({{r["address_snippet"]}}) </p>
{% endfor %}
<script>
function myFunction(id) {
document.getElementById(id).innerHTML = "CLICKED HERE";
}
</script>
</body>
</html>
I'm trying to print out a list of names, and etc to the screen. The user will click one name, this name will then be returned to a Python function for further analysis.
As a first attempt, I just want to change the text from the name to "CLICKED HERE". However, regardless of which name I click, only the first entry changes.
I can't figure out how to set the id from the container. Any help would be appreciated!
You need to update your code like this, so you get the actual value from the variable r["links"], by adding the brackets {{r["links"]}}
<p id="{{r["links"]}}" onclick="myFunction('{{r["links"]}}')"
below is the index.html file inside my workspace/projectname/templates/appname
<!DOCTYPE html>
<html>
<head>
<title>my news</title>
</head>
<body>
<h1>look below for news</h1>
{%if categories%}
<ul>
{%for category in categories%}
<li>{{category.name}}</li>
{%endfor%}
</ul>
{%endif%}
{%if headings%}
<p>
{%for heading in headings%}
{{heading.title}}
<br>
{{heading.content}}
{%endfor%}
</p>
{%endif%}
</body>
</html>
the problem is <ul> and <li> tags are working and displaying the list as it should do.the <a> tag is also displaying a hyperlink,but the <p> tag and <br> tags are not being rendered and are being displayed as a text,cant think what might be the problem.i am fairly new to django.
Try using {{heading.content|safe}} or turn autoescape off (See docs).
Although, the other answer accurately solves your problem, but that approach is not safe everytime.
If you know that only trustworthy people are going to write that article/post, then you can simply turn Django's autoescaping off (as pointed in the other answer).
But if you want to display HTML from an untrustworthy source, you are prone to XSS attacks. In that case you should use applications like django-bleach. It will escape specific HTML tags like <script> and any other tags that you want to escape.
Hello all
I work for an estate agents and I am looking for a way of easily creating window cards for the properties (similar to this: http://www.inhabit.com.au/scr/windowcard1.png)
I am interested in creating a program that takes the text and images of the property and places them in the correct positioning (so a lamen can use it). It would then need to be printed.
I am fimiliar with graphic software such as Inkscape to create a template but I won't be the only one using it.
Would anybody have any idea of where to start creating an automated program that would create a window card?
Much oblidged
David
You can use weasyprint and python to create a such software.
You create first the HTML of the document, this is a template it won't move, so you only have to do it once, here is a basic template:
<html>
<body>
<h1>Trademark</h1>
<div id="container">
<div id="photos">
<img src="photo.jpg">
</div>
<div id="text">
{{ text }}
</div>
</div>
</body>
</html>
This script will write a file called input.html with the the {{ text }} area replaced by content of the text file. Mind the fact that you can add support for bold, italic even tables using markdown.
with open('card.html') as f:
card = f.read()
with open('text.txt') as f:
text = f.read()
with open('input.html', 'w') as f:
f.write(card.replace('{{ text }}', text))
Once you have a photo.jpg and the text you can execute the above script followed by the following command:
weasyprint -f png -s styles.css input.html output.png
This will generate something similar to:
This requires better design, but you get the idea.
Does anyone have any idea how to use the tag so the table of content comes onto the 1st page and all text is coming behind. This is what i've got so far, it generates the table of content behind my text...
pdf.html
<htmL>
<body>
<div>
<pdf:toc />
</div>
<pdf:nextpage>
<br/>
<h1> test </h1>
<h2> second </h2>
some text
<h1> test_two </h1>
<h2> second </h2>
some text
</body>
</html>
I can't seem to get everything in the right position, even with the it doesn't seem to work... any help or documentation somewhere? The PISA docs are rly crappy with details actually...
Btw 1 more extra thing, is it possible to make this table of content jump to the right page? If yes how does this works?
Regards,
I found I couldn't get that pagebreak to work for me, so I used inline CSS and, specifically, the page-break property to fix it.
In your case, this should do the trick:
<div style="page-break-after:always;>
<pdf:toc />
</div>
<h1> test </h1> ...etc...
As far as the links are concerned, there may be a way to automatically generate them, but I found it easier to manually create a table of contents using links and anchors:
<h1>Table of Contents</h1>
<ul>
<li><a href="section1">The name of section 1</li>
<li><a href="section2">The name of section 2</li>
</ul>
<h2>The name of section 1</h2>
<a name="section1"></a>
<h2>The name of section 2</h2>
<a name="section2"></a>
There's obviously some duplication, but I haven't found it difficult to maintain for my documents. It depends how long or complicated you expect yours to became.
The bigger downside is that this option won't include page numbers.
Steve's comment about the page-break property is correct. I personally used a separate CSS file with
h2 {
page-break-before:always;
}
so that all of my sections would start on a new page.
I have a multiple html files in one file:
<html>
<body>
</body>
</html>
<html>
<body>
</body>
</html>
<html>
<body>
</body>
</html>
and the result is that I get a messed up html file. How to correct this without removing tags from the rest. I am using python to generate the html file. If I use the self.response.out.write(function(query)) I get a nice html page.
If I use it a second time self.response.out.write(function(query2)) then the page gets distorted.
Have one HTML file per file. Anything else is invalid and won’t be processed properly.
If you’re not sure if your HTML files are valid, the W3C’s validator will tell you.