how to convert wechat official account articles with images to pdf - python-3.x

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

Related

Nuxtjs including images from assets using the content module

I am trying to use the nuxt.js Nuxt.js content module. Is there a way to display images we refer to in our blogpost.md file? I know that we can put images in the front matter, but I want the create of the articles to put images inside their created .md file. Lets say we have a file:
-- start of .md file --
# some text
some description
![Image of test](../../assets/images/test.jpg)
![Image of Yaktocat](https://octodex.github.com/images/yaktocat.png)# some text
some description
-- end of .md file --
I end up seeing the image that is linked using https. But the other image is not displayed?? When checking the page I see an <img> tag is created, but no image to be seen...
When I check the structure using any other markdown editor, I see the image.
Including links to images does display images. But I need to include locally stored images.
any help greatly appreciated
Partially solving the issue, some images can be added using metadata (like cover images), those cannot be added within the content itself, just above or bellow actual content.
---
title: Sample
image: test.jpg
---
Here the markdown (without images)
In the view you can render that image after or before the content using something like:
<img :src="require(`~/assets/images/${ page.image }`)">
<nuxt-content :document="page"/>

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

Image from url to PDF

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

downloading images from webpage with different links

I am trying to download all the images from a webpage. The images are included as follows:
How should I parametrize my wget command to specify that I only want the images where the link starts with "https://alwaysSamePart.com/"? because what follows varies avery time so I cant just specify a hardcoded link.
Ideally I should scrape all the urls af all the images out of the html code. Surf to each link individually and save each image individually.

Display image in a packagedapp/extension after selecting from Google Drive

My packaged app gets images from google drive and then display them on the side. But I can't get the images to be displayed. I am trying to get the url of the image so that I can put that url in an image source. The image url that I am getting is actually an html page rather than jpeg, png etc. I have looked at the reference guide for google picker but nothing seems to work.
I am using this
function pickerCallback(data) {
if (data.action == google.picker.Action.PICKED) {
var fileId = data.docs[0].id;
fileName = data.docs[0].name;
imgURL = data.docs[0].url;
}
I want to use imgURL as the source for image selection but imgURL is not something like "https//:www.example.com/image.jpg. It is rather an html page I want something that ends with file type only then it will be able to display the image. Please let me know how can I get the image to be displayed in html page of my packaged app after selecting it from google drive.
You should fetch the metadata of the image, then use the webContentLink of the image, then the user can view it in a logged in browser. See the documentation on downloads for more information.

Resources