How to create pdf from downloaded photos (python)
**I want to create pdf after downloading photos,it's not save pdf file. Where have error?
**
from fpdf import FPDF
import random
import urllib.request
for i in range(1,10):
def image(url):
name=random.randrange(1,80)
fullname=str(name)+"."+"jpg"
a=urllib.request.urlretrieve(url,'/Users/Dato/Desktop/python/photo/{}.jpg'.format(name))
image("https://img.yumpu.com/54761731/{}/950x950/7uhbctpd0.jpg".format(random.randrange(1, 80)))
pdf = FPDF()
pdf.add_page()
pdf.image('{}'.format(a), x=0, y=0)
pdf.output("1.pdf",)
python pdf download
add a comment |
**I want to create pdf after downloading photos,it's not save pdf file. Where have error?
**
from fpdf import FPDF
import random
import urllib.request
for i in range(1,10):
def image(url):
name=random.randrange(1,80)
fullname=str(name)+"."+"jpg"
a=urllib.request.urlretrieve(url,'/Users/Dato/Desktop/python/photo/{}.jpg'.format(name))
image("https://img.yumpu.com/54761731/{}/950x950/7uhbctpd0.jpg".format(random.randrange(1, 80)))
pdf = FPDF()
pdf.add_page()
pdf.image('{}'.format(a), x=0, y=0)
pdf.output("1.pdf",)
python pdf download
1
What error? If you are getting an error message, please post it in your question.
– mypetlion
Nov 23 '18 at 17:03
Do not write a mistake. I want how to save this pdf
– kkwebba
Nov 23 '18 at 17:10
It just writes Process finished with exit code 0
– kkwebba
Nov 23 '18 at 17:11
add a comment |
**I want to create pdf after downloading photos,it's not save pdf file. Where have error?
**
from fpdf import FPDF
import random
import urllib.request
for i in range(1,10):
def image(url):
name=random.randrange(1,80)
fullname=str(name)+"."+"jpg"
a=urllib.request.urlretrieve(url,'/Users/Dato/Desktop/python/photo/{}.jpg'.format(name))
image("https://img.yumpu.com/54761731/{}/950x950/7uhbctpd0.jpg".format(random.randrange(1, 80)))
pdf = FPDF()
pdf.add_page()
pdf.image('{}'.format(a), x=0, y=0)
pdf.output("1.pdf",)
python pdf download
**I want to create pdf after downloading photos,it's not save pdf file. Where have error?
**
from fpdf import FPDF
import random
import urllib.request
for i in range(1,10):
def image(url):
name=random.randrange(1,80)
fullname=str(name)+"."+"jpg"
a=urllib.request.urlretrieve(url,'/Users/Dato/Desktop/python/photo/{}.jpg'.format(name))
image("https://img.yumpu.com/54761731/{}/950x950/7uhbctpd0.jpg".format(random.randrange(1, 80)))
pdf = FPDF()
pdf.add_page()
pdf.image('{}'.format(a), x=0, y=0)
pdf.output("1.pdf",)
python pdf download
python pdf download
asked Nov 23 '18 at 16:57
kkwebba
13
13
1
What error? If you are getting an error message, please post it in your question.
– mypetlion
Nov 23 '18 at 17:03
Do not write a mistake. I want how to save this pdf
– kkwebba
Nov 23 '18 at 17:10
It just writes Process finished with exit code 0
– kkwebba
Nov 23 '18 at 17:11
add a comment |
1
What error? If you are getting an error message, please post it in your question.
– mypetlion
Nov 23 '18 at 17:03
Do not write a mistake. I want how to save this pdf
– kkwebba
Nov 23 '18 at 17:10
It just writes Process finished with exit code 0
– kkwebba
Nov 23 '18 at 17:11
1
1
What error? If you are getting an error message, please post it in your question.
– mypetlion
Nov 23 '18 at 17:03
What error? If you are getting an error message, please post it in your question.
– mypetlion
Nov 23 '18 at 17:03
Do not write a mistake. I want how to save this pdf
– kkwebba
Nov 23 '18 at 17:10
Do not write a mistake. I want how to save this pdf
– kkwebba
Nov 23 '18 at 17:10
It just writes Process finished with exit code 0
– kkwebba
Nov 23 '18 at 17:11
It just writes Process finished with exit code 0
– kkwebba
Nov 23 '18 at 17:11
add a comment |
2 Answers
2
active
oldest
votes
Your code doesn't do much. Here's what happens when your code runs:
from fpdf import FPDF
import random
import urllib.request
for i in range(1,10):
Here you import your packages and then you start a for
loop. The code in the loop will be run once for each loop, and will have access to variable i
which will change each time the loop runs.
def image(url):
...
The rest of your code consists of a function definition inside a for
loop. The function you define can be called image("example.com")
but you never do this. So the for
loop runs and defines a function many times but never calls it. The function never runs.
Edit: to actually run the code, you could just delete the function definition and supply the URLs directly. The code would run if it wasn't in a function definition.
Can you write the exact code?
– kkwebba
Nov 23 '18 at 17:07
How to work correctly
– kkwebba
Nov 23 '18 at 17:07
Edited my answer
– Charles Landau
Nov 23 '18 at 17:08
add a comment |
With the def
statement, you are defining a function. It is just building the structure of what that particular piece of code should do. It is not actually executing it.
With the def
inside the for
loop, you are building the struture again and again, but never actually executing that piece of code.
If you'd insist on using functions, you can define the function outside the loop (once), and then call it using function_name()
inside the for
loop.
Or, you can eliminate the use of function altogehter, and simply remove the def portion nside the loop, and let the instructions be executed directly.
I had a very similar project way back which made use of similar pdf concepts. If some issue still exists, I hope it can guide you further: GitHub Link.
very thank you!
– kkwebba
Nov 23 '18 at 17:28
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%2f53450496%2fhow-to-create-pdf-from-downloaded-photos-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your code doesn't do much. Here's what happens when your code runs:
from fpdf import FPDF
import random
import urllib.request
for i in range(1,10):
Here you import your packages and then you start a for
loop. The code in the loop will be run once for each loop, and will have access to variable i
which will change each time the loop runs.
def image(url):
...
The rest of your code consists of a function definition inside a for
loop. The function you define can be called image("example.com")
but you never do this. So the for
loop runs and defines a function many times but never calls it. The function never runs.
Edit: to actually run the code, you could just delete the function definition and supply the URLs directly. The code would run if it wasn't in a function definition.
Can you write the exact code?
– kkwebba
Nov 23 '18 at 17:07
How to work correctly
– kkwebba
Nov 23 '18 at 17:07
Edited my answer
– Charles Landau
Nov 23 '18 at 17:08
add a comment |
Your code doesn't do much. Here's what happens when your code runs:
from fpdf import FPDF
import random
import urllib.request
for i in range(1,10):
Here you import your packages and then you start a for
loop. The code in the loop will be run once for each loop, and will have access to variable i
which will change each time the loop runs.
def image(url):
...
The rest of your code consists of a function definition inside a for
loop. The function you define can be called image("example.com")
but you never do this. So the for
loop runs and defines a function many times but never calls it. The function never runs.
Edit: to actually run the code, you could just delete the function definition and supply the URLs directly. The code would run if it wasn't in a function definition.
Can you write the exact code?
– kkwebba
Nov 23 '18 at 17:07
How to work correctly
– kkwebba
Nov 23 '18 at 17:07
Edited my answer
– Charles Landau
Nov 23 '18 at 17:08
add a comment |
Your code doesn't do much. Here's what happens when your code runs:
from fpdf import FPDF
import random
import urllib.request
for i in range(1,10):
Here you import your packages and then you start a for
loop. The code in the loop will be run once for each loop, and will have access to variable i
which will change each time the loop runs.
def image(url):
...
The rest of your code consists of a function definition inside a for
loop. The function you define can be called image("example.com")
but you never do this. So the for
loop runs and defines a function many times but never calls it. The function never runs.
Edit: to actually run the code, you could just delete the function definition and supply the URLs directly. The code would run if it wasn't in a function definition.
Your code doesn't do much. Here's what happens when your code runs:
from fpdf import FPDF
import random
import urllib.request
for i in range(1,10):
Here you import your packages and then you start a for
loop. The code in the loop will be run once for each loop, and will have access to variable i
which will change each time the loop runs.
def image(url):
...
The rest of your code consists of a function definition inside a for
loop. The function you define can be called image("example.com")
but you never do this. So the for
loop runs and defines a function many times but never calls it. The function never runs.
Edit: to actually run the code, you could just delete the function definition and supply the URLs directly. The code would run if it wasn't in a function definition.
edited Nov 23 '18 at 17:09
answered Nov 23 '18 at 17:04
Charles Landau
1,9241215
1,9241215
Can you write the exact code?
– kkwebba
Nov 23 '18 at 17:07
How to work correctly
– kkwebba
Nov 23 '18 at 17:07
Edited my answer
– Charles Landau
Nov 23 '18 at 17:08
add a comment |
Can you write the exact code?
– kkwebba
Nov 23 '18 at 17:07
How to work correctly
– kkwebba
Nov 23 '18 at 17:07
Edited my answer
– Charles Landau
Nov 23 '18 at 17:08
Can you write the exact code?
– kkwebba
Nov 23 '18 at 17:07
Can you write the exact code?
– kkwebba
Nov 23 '18 at 17:07
How to work correctly
– kkwebba
Nov 23 '18 at 17:07
How to work correctly
– kkwebba
Nov 23 '18 at 17:07
Edited my answer
– Charles Landau
Nov 23 '18 at 17:08
Edited my answer
– Charles Landau
Nov 23 '18 at 17:08
add a comment |
With the def
statement, you are defining a function. It is just building the structure of what that particular piece of code should do. It is not actually executing it.
With the def
inside the for
loop, you are building the struture again and again, but never actually executing that piece of code.
If you'd insist on using functions, you can define the function outside the loop (once), and then call it using function_name()
inside the for
loop.
Or, you can eliminate the use of function altogehter, and simply remove the def portion nside the loop, and let the instructions be executed directly.
I had a very similar project way back which made use of similar pdf concepts. If some issue still exists, I hope it can guide you further: GitHub Link.
very thank you!
– kkwebba
Nov 23 '18 at 17:28
add a comment |
With the def
statement, you are defining a function. It is just building the structure of what that particular piece of code should do. It is not actually executing it.
With the def
inside the for
loop, you are building the struture again and again, but never actually executing that piece of code.
If you'd insist on using functions, you can define the function outside the loop (once), and then call it using function_name()
inside the for
loop.
Or, you can eliminate the use of function altogehter, and simply remove the def portion nside the loop, and let the instructions be executed directly.
I had a very similar project way back which made use of similar pdf concepts. If some issue still exists, I hope it can guide you further: GitHub Link.
very thank you!
– kkwebba
Nov 23 '18 at 17:28
add a comment |
With the def
statement, you are defining a function. It is just building the structure of what that particular piece of code should do. It is not actually executing it.
With the def
inside the for
loop, you are building the struture again and again, but never actually executing that piece of code.
If you'd insist on using functions, you can define the function outside the loop (once), and then call it using function_name()
inside the for
loop.
Or, you can eliminate the use of function altogehter, and simply remove the def portion nside the loop, and let the instructions be executed directly.
I had a very similar project way back which made use of similar pdf concepts. If some issue still exists, I hope it can guide you further: GitHub Link.
With the def
statement, you are defining a function. It is just building the structure of what that particular piece of code should do. It is not actually executing it.
With the def
inside the for
loop, you are building the struture again and again, but never actually executing that piece of code.
If you'd insist on using functions, you can define the function outside the loop (once), and then call it using function_name()
inside the for
loop.
Or, you can eliminate the use of function altogehter, and simply remove the def portion nside the loop, and let the instructions be executed directly.
I had a very similar project way back which made use of similar pdf concepts. If some issue still exists, I hope it can guide you further: GitHub Link.
answered Nov 23 '18 at 17:17
thegravity
6225
6225
very thank you!
– kkwebba
Nov 23 '18 at 17:28
add a comment |
very thank you!
– kkwebba
Nov 23 '18 at 17:28
very thank you!
– kkwebba
Nov 23 '18 at 17:28
very thank you!
– kkwebba
Nov 23 '18 at 17:28
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53450496%2fhow-to-create-pdf-from-downloaded-photos-python%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
What error? If you are getting an error message, please post it in your question.
– mypetlion
Nov 23 '18 at 17:03
Do not write a mistake. I want how to save this pdf
– kkwebba
Nov 23 '18 at 17:10
It just writes Process finished with exit code 0
– kkwebba
Nov 23 '18 at 17:11