How to create pdf from downloaded photos (python)












-1














**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",)









share|improve this question


















  • 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














**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",)









share|improve this question


















  • 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








-1







**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",)









share|improve this question













**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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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














  • 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












2 Answers
2






active

oldest

votes


















0














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.






share|improve this answer























  • 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



















0














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.






share|improve this answer





















  • very thank you!
    – kkwebba
    Nov 23 '18 at 17:28











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
});


}
});














draft saved

draft discarded


















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









0














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.






share|improve this answer























  • 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
















0














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.






share|improve this answer























  • 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














0












0








0






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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








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


















  • 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













0














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.






share|improve this answer





















  • very thank you!
    – kkwebba
    Nov 23 '18 at 17:28
















0














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.






share|improve this answer





















  • very thank you!
    – kkwebba
    Nov 23 '18 at 17:28














0












0








0






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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 17:17









thegravity

6225




6225












  • 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




very thank you!
– kkwebba
Nov 23 '18 at 17:28


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks