Python : Add Logo on top in reportlab
I am using reportlab
in python-2.7
for generating PDF. I am trying to add Logo on top-Left in PDF using this code.
Story =
logo = "logo.png"
im = Image(logo, 1 * inch, 1 * inch)
t = Story.append(im)
But its not shows logo.png
image into PDF .Can someone tell me Where am i making a mistake?
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Table, TableStyle, Image
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import cm
from reportlab.lib.units import inch
document =
doc = SimpleDocTemplate('example.pdf', pagesize=A4, rightMargin=72, leftMargin=72, topMargin=72)
styles = getSampleStyleSheet()
Story =
logo = "logo.png"
im = Image(logo, 1 * inch, 1 * inch)
t = Story.append(im)
definitions =
i, a = 1, 65
table =
for x in range(1, 10):
line =
line.append(Paragraph(str(i), styles['BodyText']))
line.append(Paragraph('Vocabulary', styles['BodyText']))
line.append(Paragraph(chr(a), styles['BodyText']))
line.append(Paragraph('Often a multi-line definition of the vocabulary. But then, sometimes something short and sweet.', styles['BodyText']))
table.append(line)
i += 1
a += 1
t = Table(table, colWidths=(1*cm, 4*cm, 1*cm, None))
t.setStyle(TableStyle([
('VALIGN', (1, 1), (-1, -1), 'TOP')
]))
document.append(t)
doc.build(document)
python-2.7 reportlab
|
show 4 more comments
I am using reportlab
in python-2.7
for generating PDF. I am trying to add Logo on top-Left in PDF using this code.
Story =
logo = "logo.png"
im = Image(logo, 1 * inch, 1 * inch)
t = Story.append(im)
But its not shows logo.png
image into PDF .Can someone tell me Where am i making a mistake?
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Table, TableStyle, Image
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import cm
from reportlab.lib.units import inch
document =
doc = SimpleDocTemplate('example.pdf', pagesize=A4, rightMargin=72, leftMargin=72, topMargin=72)
styles = getSampleStyleSheet()
Story =
logo = "logo.png"
im = Image(logo, 1 * inch, 1 * inch)
t = Story.append(im)
definitions =
i, a = 1, 65
table =
for x in range(1, 10):
line =
line.append(Paragraph(str(i), styles['BodyText']))
line.append(Paragraph('Vocabulary', styles['BodyText']))
line.append(Paragraph(chr(a), styles['BodyText']))
line.append(Paragraph('Often a multi-line definition of the vocabulary. But then, sometimes something short and sweet.', styles['BodyText']))
table.append(line)
i += 1
a += 1
t = Table(table, colWidths=(1*cm, 4*cm, 1*cm, None))
t.setStyle(TableStyle([
('VALIGN', (1, 1), (-1, -1), 'TOP')
]))
document.append(t)
doc.build(document)
python-2.7 reportlab
1
@Mawg Its not showing any error.But Its not showinglogo.png
image into PDF
– Martin
Nov 19 '18 at 13:07
1
What are you doing witht
int = Story.append(im)
? It doesn't seem to be used and is then overwritten byt = Table(table, colWidths=(1*cm, 4*cm, 1*cm, None))
- btw, get into the habit of using meaningful variables names. In 6 months time, you won't know what this does.
– Mawg
Nov 19 '18 at 13:09
1
Perhaps you needed todocument.append(t)
aftert = Story.append(im)
?
– Mawg
Nov 19 '18 at 13:11
1
@Mawg Thanks for help.But its not working.
– Martin
Nov 19 '18 at 13:14
1
@Mawg I am really sorry.It's working.Thanks alot
– Martin
Nov 19 '18 at 13:25
|
show 4 more comments
I am using reportlab
in python-2.7
for generating PDF. I am trying to add Logo on top-Left in PDF using this code.
Story =
logo = "logo.png"
im = Image(logo, 1 * inch, 1 * inch)
t = Story.append(im)
But its not shows logo.png
image into PDF .Can someone tell me Where am i making a mistake?
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Table, TableStyle, Image
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import cm
from reportlab.lib.units import inch
document =
doc = SimpleDocTemplate('example.pdf', pagesize=A4, rightMargin=72, leftMargin=72, topMargin=72)
styles = getSampleStyleSheet()
Story =
logo = "logo.png"
im = Image(logo, 1 * inch, 1 * inch)
t = Story.append(im)
definitions =
i, a = 1, 65
table =
for x in range(1, 10):
line =
line.append(Paragraph(str(i), styles['BodyText']))
line.append(Paragraph('Vocabulary', styles['BodyText']))
line.append(Paragraph(chr(a), styles['BodyText']))
line.append(Paragraph('Often a multi-line definition of the vocabulary. But then, sometimes something short and sweet.', styles['BodyText']))
table.append(line)
i += 1
a += 1
t = Table(table, colWidths=(1*cm, 4*cm, 1*cm, None))
t.setStyle(TableStyle([
('VALIGN', (1, 1), (-1, -1), 'TOP')
]))
document.append(t)
doc.build(document)
python-2.7 reportlab
I am using reportlab
in python-2.7
for generating PDF. I am trying to add Logo on top-Left in PDF using this code.
Story =
logo = "logo.png"
im = Image(logo, 1 * inch, 1 * inch)
t = Story.append(im)
But its not shows logo.png
image into PDF .Can someone tell me Where am i making a mistake?
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Table, TableStyle, Image
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import cm
from reportlab.lib.units import inch
document =
doc = SimpleDocTemplate('example.pdf', pagesize=A4, rightMargin=72, leftMargin=72, topMargin=72)
styles = getSampleStyleSheet()
Story =
logo = "logo.png"
im = Image(logo, 1 * inch, 1 * inch)
t = Story.append(im)
definitions =
i, a = 1, 65
table =
for x in range(1, 10):
line =
line.append(Paragraph(str(i), styles['BodyText']))
line.append(Paragraph('Vocabulary', styles['BodyText']))
line.append(Paragraph(chr(a), styles['BodyText']))
line.append(Paragraph('Often a multi-line definition of the vocabulary. But then, sometimes something short and sweet.', styles['BodyText']))
table.append(line)
i += 1
a += 1
t = Table(table, colWidths=(1*cm, 4*cm, 1*cm, None))
t.setStyle(TableStyle([
('VALIGN', (1, 1), (-1, -1), 'TOP')
]))
document.append(t)
doc.build(document)
python-2.7 reportlab
python-2.7 reportlab
edited Nov 19 '18 at 13:09
Martin
asked Nov 19 '18 at 13:02
MartinMartin
68218
68218
1
@Mawg Its not showing any error.But Its not showinglogo.png
image into PDF
– Martin
Nov 19 '18 at 13:07
1
What are you doing witht
int = Story.append(im)
? It doesn't seem to be used and is then overwritten byt = Table(table, colWidths=(1*cm, 4*cm, 1*cm, None))
- btw, get into the habit of using meaningful variables names. In 6 months time, you won't know what this does.
– Mawg
Nov 19 '18 at 13:09
1
Perhaps you needed todocument.append(t)
aftert = Story.append(im)
?
– Mawg
Nov 19 '18 at 13:11
1
@Mawg Thanks for help.But its not working.
– Martin
Nov 19 '18 at 13:14
1
@Mawg I am really sorry.It's working.Thanks alot
– Martin
Nov 19 '18 at 13:25
|
show 4 more comments
1
@Mawg Its not showing any error.But Its not showinglogo.png
image into PDF
– Martin
Nov 19 '18 at 13:07
1
What are you doing witht
int = Story.append(im)
? It doesn't seem to be used and is then overwritten byt = Table(table, colWidths=(1*cm, 4*cm, 1*cm, None))
- btw, get into the habit of using meaningful variables names. In 6 months time, you won't know what this does.
– Mawg
Nov 19 '18 at 13:09
1
Perhaps you needed todocument.append(t)
aftert = Story.append(im)
?
– Mawg
Nov 19 '18 at 13:11
1
@Mawg Thanks for help.But its not working.
– Martin
Nov 19 '18 at 13:14
1
@Mawg I am really sorry.It's working.Thanks alot
– Martin
Nov 19 '18 at 13:25
1
1
@Mawg Its not showing any error.But Its not showing
logo.png
image into PDF– Martin
Nov 19 '18 at 13:07
@Mawg Its not showing any error.But Its not showing
logo.png
image into PDF– Martin
Nov 19 '18 at 13:07
1
1
What are you doing with
t
in t = Story.append(im)
? It doesn't seem to be used and is then overwritten by t = Table(table, colWidths=(1*cm, 4*cm, 1*cm, None))
- btw, get into the habit of using meaningful variables names. In 6 months time, you won't know what this does.– Mawg
Nov 19 '18 at 13:09
What are you doing with
t
in t = Story.append(im)
? It doesn't seem to be used and is then overwritten by t = Table(table, colWidths=(1*cm, 4*cm, 1*cm, None))
- btw, get into the habit of using meaningful variables names. In 6 months time, you won't know what this does.– Mawg
Nov 19 '18 at 13:09
1
1
Perhaps you needed to
document.append(t)
after t = Story.append(im)
?– Mawg
Nov 19 '18 at 13:11
Perhaps you needed to
document.append(t)
after t = Story.append(im)
?– Mawg
Nov 19 '18 at 13:11
1
1
@Mawg Thanks for help.But its not working.
– Martin
Nov 19 '18 at 13:14
@Mawg Thanks for help.But its not working.
– Martin
Nov 19 '18 at 13:14
1
1
@Mawg I am really sorry.It's working.Thanks alot
– Martin
Nov 19 '18 at 13:25
@Mawg I am really sorry.It's working.Thanks alot
– Martin
Nov 19 '18 at 13:25
|
show 4 more comments
1 Answer
1
active
oldest
votes
You need to append your logo to the document
from which you will build()
.
Add document.append(im)
after im = Image(logo, 1 * inch, 1 * inch)
.
There is a good tutorial here
Please can you tell me how to set logo into Left align?
– Martin
Nov 19 '18 at 13:35
1
That's anew question, Martin. We like to keep it to one question and one answer, otherwise it gets messy. Post a new question, but you can link to this one if you want to. Be sure to post your code, though - and tell where the logo is appearing at the moment? RIght aligned, centre?
– Mawg
Nov 19 '18 at 13:51
1
It really should be a new question, but this example makes it look like you want toim.hAlign = 'LEFT'
– Mawg
Nov 19 '18 at 14:26
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375254%2fpython-add-logo-on-top-in-reportlab%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to append your logo to the document
from which you will build()
.
Add document.append(im)
after im = Image(logo, 1 * inch, 1 * inch)
.
There is a good tutorial here
Please can you tell me how to set logo into Left align?
– Martin
Nov 19 '18 at 13:35
1
That's anew question, Martin. We like to keep it to one question and one answer, otherwise it gets messy. Post a new question, but you can link to this one if you want to. Be sure to post your code, though - and tell where the logo is appearing at the moment? RIght aligned, centre?
– Mawg
Nov 19 '18 at 13:51
1
It really should be a new question, but this example makes it look like you want toim.hAlign = 'LEFT'
– Mawg
Nov 19 '18 at 14:26
add a comment |
You need to append your logo to the document
from which you will build()
.
Add document.append(im)
after im = Image(logo, 1 * inch, 1 * inch)
.
There is a good tutorial here
Please can you tell me how to set logo into Left align?
– Martin
Nov 19 '18 at 13:35
1
That's anew question, Martin. We like to keep it to one question and one answer, otherwise it gets messy. Post a new question, but you can link to this one if you want to. Be sure to post your code, though - and tell where the logo is appearing at the moment? RIght aligned, centre?
– Mawg
Nov 19 '18 at 13:51
1
It really should be a new question, but this example makes it look like you want toim.hAlign = 'LEFT'
– Mawg
Nov 19 '18 at 14:26
add a comment |
You need to append your logo to the document
from which you will build()
.
Add document.append(im)
after im = Image(logo, 1 * inch, 1 * inch)
.
There is a good tutorial here
You need to append your logo to the document
from which you will build()
.
Add document.append(im)
after im = Image(logo, 1 * inch, 1 * inch)
.
There is a good tutorial here
answered Nov 19 '18 at 13:31
MawgMawg
14.4k73235437
14.4k73235437
Please can you tell me how to set logo into Left align?
– Martin
Nov 19 '18 at 13:35
1
That's anew question, Martin. We like to keep it to one question and one answer, otherwise it gets messy. Post a new question, but you can link to this one if you want to. Be sure to post your code, though - and tell where the logo is appearing at the moment? RIght aligned, centre?
– Mawg
Nov 19 '18 at 13:51
1
It really should be a new question, but this example makes it look like you want toim.hAlign = 'LEFT'
– Mawg
Nov 19 '18 at 14:26
add a comment |
Please can you tell me how to set logo into Left align?
– Martin
Nov 19 '18 at 13:35
1
That's anew question, Martin. We like to keep it to one question and one answer, otherwise it gets messy. Post a new question, but you can link to this one if you want to. Be sure to post your code, though - and tell where the logo is appearing at the moment? RIght aligned, centre?
– Mawg
Nov 19 '18 at 13:51
1
It really should be a new question, but this example makes it look like you want toim.hAlign = 'LEFT'
– Mawg
Nov 19 '18 at 14:26
Please can you tell me how to set logo into Left align?
– Martin
Nov 19 '18 at 13:35
Please can you tell me how to set logo into Left align?
– Martin
Nov 19 '18 at 13:35
1
1
That's anew question, Martin. We like to keep it to one question and one answer, otherwise it gets messy. Post a new question, but you can link to this one if you want to. Be sure to post your code, though - and tell where the logo is appearing at the moment? RIght aligned, centre?
– Mawg
Nov 19 '18 at 13:51
That's anew question, Martin. We like to keep it to one question and one answer, otherwise it gets messy. Post a new question, but you can link to this one if you want to. Be sure to post your code, though - and tell where the logo is appearing at the moment? RIght aligned, centre?
– Mawg
Nov 19 '18 at 13:51
1
1
It really should be a new question, but this example makes it look like you want to
im.hAlign = 'LEFT'
– Mawg
Nov 19 '18 at 14:26
It really should be a new question, but this example makes it look like you want to
im.hAlign = 'LEFT'
– Mawg
Nov 19 '18 at 14:26
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375254%2fpython-add-logo-on-top-in-reportlab%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
@Mawg Its not showing any error.But Its not showing
logo.png
image into PDF– Martin
Nov 19 '18 at 13:07
1
What are you doing with
t
int = Story.append(im)
? It doesn't seem to be used and is then overwritten byt = Table(table, colWidths=(1*cm, 4*cm, 1*cm, None))
- btw, get into the habit of using meaningful variables names. In 6 months time, you won't know what this does.– Mawg
Nov 19 '18 at 13:09
1
Perhaps you needed to
document.append(t)
aftert = Story.append(im)
?– Mawg
Nov 19 '18 at 13:11
1
@Mawg Thanks for help.But its not working.
– Martin
Nov 19 '18 at 13:14
1
@Mawg I am really sorry.It's working.Thanks alot
– Martin
Nov 19 '18 at 13:25