Image from url to PDF - python-3.x

How can I convert images saved on cloudinary to pdf using their url with python3 + django?
I tried using pdfkit but it's not fetching the image from url and creates a blank pdf.

You can just set the format to pdf, like this:
https://res.cloudinary.com/demo/f_pdf/bike.jpg
Python:
CloudinaryImage("bike.jpg").image(fetch_format="pdf")

Thank you all for the helpful answers.
I used urllib.request.urlretrieve(url, filename) to download the images from the urls to local system and then with the help of PyFPDF converted them to the pdf file.
Link: https://pyfpdf.readthedocs.io/en/latest/Tutorial/index.html

Related

Nodejs muhammara insert SVG to pdf, or read exist PDF with PDFmake content and save it as other

I am using NodeJS and I want to modify uploaded PDF file by add svg.
I tried to use Muhammara/Hummus and it is great to edit but it can not handle SVG, only JPEG.
I also Tried PDFmake, but as far i know, I can not read PDF with this tool, just create PDF from documentData obj.
Is there any possibility accomplish mentioned goal in Nodejs?
Regards

get just an image from a url, using xpath

Hello to the whole community, I wanted to know how to get an image through xpath. I have the following code to download an image using the link of the jpg file
import requests
url = 'https://www.elesquiu.com/u/portadas/tapas/7349.jpg'
myfile = requests.get(url)
open('ESQUIU.jpg', 'wb').write(myfile.content)
The problem that arises here, is that the file 7349.jpg is randomly renamed, and for that reason is that I need to go directly through xpath, can someone help me with this? Grateful
webpage info "https://www.elesquiu.com"

How to download embedded content-id images from outlook using selenium python

I am trying to download embedded images in outlook using selenium python. I have tried to run the following code to download such images but it failed. The code can be used to download attachments but not embedded images. Anyone has any ideas how to download images to folder in python? Thanks so much.
The code i used was (it only works for attached images):
imgs = driver.find_elements_by_xpath(xpath)
for i, img in enumerate(imgs):
src = img.get_attribute('src')
urllib.request.urlretrieve(src, f"img {i}.png")

Node.js how to download webp image

It´s very easy to download images via the request module. But this is only working for me when then end of the url contains .jpg or .png
But how can you download as example this image?
https://lh3.googleusercontent.com/VpoWDgQ2I_RlTNM1Srlo5Q0VQglr-gdbzJ48TwYRXM2U4iF75PMrv76rBiu5c3l1UJs=s180-rw
Does anybody know a method to download the image as .jpg?
I found a solution on howtogeek
"Click the URL bar, delete the last three characters in the address (the “-rw”), and then press “Enter.” The same image will be displayed again, but this time it’s rendered in its original format, usually JPEG or PNG."

how to convert wechat official account articles with images to pdf

for general html, when use pdfkit to convert html to pdf,images in the html can be saved in pdf.
while for wechat official account articles, I found images in urls was lost. the following code is an instance.
how to save wechat official account articles with images to pdf?
import pdfkit
url='https://mp.weixin.qq.com/s?__biz=MzA3NDMyOTcxMQ==&mid=2651249314&idx=1&sn=5338576a80a4145b9808ff06cc980c14'
path_wkthmltopdf = 'C:/Anaconda3/Lib/site-packages/wkhtmltopdf/bin/wkhtmltopdf.exe'
pdfkit.from_url(url=url,output_path='c:/test.pdf',configuration=pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf))'
I think one of the solution is rolling down the url to load all images, then convert it to pdf. how to rolling down to load all images in pdfkit?
The following should work without modifying the windows environment variables:
import pdfkit
path_wkthmltopdf = r'C:\Python27\wkhtmltopdf\bin\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
url = 'https://mp.weixin.qq.com/s?timestamp=1515570589&src=3&ver=1&signature=xsZdozV1JPS2K8SuXJ8TKeqfuczP2z78*LCVu32ljt1NSa8oF41X88W0JYguTbLUwHHyt0ksUy8l9ljM5*uGOSH-GBjlVipz4a1aIeg9xNQgwlxuCV*9dURcg-U8UvR78C2RV6B5CIeA0n1jIaiFiqrQTIuel5IW-HYAcQsOT0g='
pdfkit.from_url(url, "out.pdf", configuration=config)
Assuming the path is correct (e.g. in my case it is r'C:\Program Files (x86)\wkhtmltopdf\bin\wkhtmltopdf.exe').
Result:
Loading page (1/2)
Printing pages (2/2)
Done
PDF Link

Resources