I want to convert a color pdf to black and white pdf in specific mode I want to convert all text in red or green in black (not in gray).
gs -o output.pdf \
-sDEVICE=pdfwrite \
-dBlackText=true \
-dBlackVector=true \
-sColorConversionStrategy=Gray \
-dProcessColorModel=/DeviceGray \
input.pdf
Showing posts with label Scripts. Show all posts
Showing posts with label Scripts. Show all posts
How to convert color pdf to black and white pdf
Convert jpeg file to pdf
Step 1 - Installa the following package
sudo apt install imagemagick
Step 2 - Use the following command: convert *.jpeg my_pdf.pdf
The command above might yield an “operation not allowed” error. Fortunately, we
can easily fix it by executing:
sudo sed -i 's/^.*policy.*coder.*none.*PDF.\*//' /etc/ImageMagick-6/policy.xml
or better:
sudo gedit /etc/ImageMagick-6/policy.xml
add or change the row at end of the file (just before </policymap>) with the following:
<policy domain="coder" rights="read | write" pattern="PDF" />
PHP: How to extract emails from list file
$pattern = '/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/';
if ($file = fopen("a.vcf", "r")) {
while(!feof($file)) {
$line = fgets($file);
if (preg_match($pattern, $line, $matches)) echo $matches[0]."\n";
}
fclose($file);
} Bash GUI for QPDF (using Python)
Step 1: Create a python program called mergePDF.py
import PySimpleGUIQt as sg
import sys
import os
arg = sys.argv[1:]
current_working_directory = os.getcwd() + "/undefined.pdf"
current_working_directory = "/home/max/Scrivania" + "/undefined.pdf"
class Listbox(sg.Listbox):
def dragEnterEvent(self, e):
e.accept()
def dragMoveEvent(self, e):
e.accept()
def dropEvent(self, e):
data = window['LISTBOX'].get_list_values()
items = [str(v).replace("PySide2.QtCore.QUrl('file://", "").replace("')", "") for v in e.mimeData().urls()]
for x in items:
if (x[-4:].upper() != '.PDF'): items.remove(x)
data.extend(items)
window['LISTBOX'].update(data)
window.refresh()
def enable_drop(self):
self.Widget.setAcceptDrops(True)
self.Widget.dragEnterEvent = self.dragEnterEvent
self.Widget.dragMoveEvent = self.dragMoveEvent
self.Widget.dropEvent = self.dropEvent
file_list_column = [
[
Listbox(arg, size=(50, 10), enable_events=True, key='LISTBOX', select_mode="single"),
],
[
sg.Input(default_text=current_working_directory, key='FOLDER')
],
]
image_button_move_column = [
[sg.Button("Up")],
[sg.Button("Down")],
[sg.Button("Delete")],
]
image_button_action_column = [
[
sg.Button("Merge")
],
]
layout = [
[
sg.Column(file_list_column),
sg.VSeperator(),
sg.Column(image_button_move_column),
sg.VSeperator(),
sg.Column(image_button_action_column),
]
]
window = sg.Window("pdfMerge V1.0", layout, finalize=True, resizable=False)
window['LISTBOX'].enable_drop()
def retreive_elem_selected(element):
if element['LISTBOX']:
item = element['LISTBOX'][0]
else: item = ""
return item
def manage_up(item, mylist):
if item:
pos = mylist.index(item)
newpos = pos-1
if newpos>-1:
mylist.insert(
newpos,
mylist.pop(pos)
)
return mylist
def manage_down(item, mylist):
if item:
pos = mylist.index(item)
newpos = pos+1
mylist.insert(
newpos,
mylist.pop(pos)
)
return mylist
def manage_delete(item, mylist):
if item:
mylist.remove(item)
return mylist
def manage_merge(mylist,myfile):
if myfile:
str1 = " ".join(str("\""+x+"\"") for x in mylist)
os.system("qpdf --empty --pages "+ str1 + " -- " + myfile)
else: sg.popup('','The output field is empty')
while True:
event, values = window.read()
item_selected = retreive_elem_selected(values)
mylist = window['LISTBOX'].get_list_values()
if event == sg.WINDOW_CLOSED:
break
if event == 'Merge':
manage_merge(mylist,window['FOLDER'].get())
if event == 'Up':
window['LISTBOX'].update(manage_up(item_selected,mylist))
window['LISTBOX'].set_value(item_selected)
if event == 'Down':
window['LISTBOX'].update(manage_down(item_selected,mylist))
window['LISTBOX'].set_value(item_selected)
if event == 'Delete':
if item_selected:
pos = mylist.index(item_selected)
window['LISTBOX'].update(manage_delete(item_selected,mylist))
mylist = window['LISTBOX'].get_list_values()
if mylist:
if pos < len(mylist):
window['LISTBOX'].set_value(mylist[pos])
else: window['LISTBOX'].set_value(mylist[-1:])
window.close()
Step 2: create a bash file mergePDF.sh to run the mergePDF.py#!/bin/bash
python3 /home/max/batfile/Py/mergePDF.py "$@"
where /home/max/batfile/Py/ is the path where your python file is stored
Step 3: create a link of mergePDF.sh file into scripts folder
in my case into /home/max/.local/share/nautilus/scripts
How to extract mp3 from youtube
- Install yt-dlp_linux
from https://github.com/yt-dlp/yt-dlp go su release and download linux yt-dlp_linux,
put all into a new folder ad assign the execution permission.
- Download a specific video, i.e:
./yt-dlp_linux -x --audio-format mp3 https://www.youtube.com/watch?v=cen1SvpTsYk&ab_channel=BlackSabbath
Convert mp4 to mp3 under linux
#!/bin/bash
clear
# Example: ./mp4ToMp3.sh ~/Downloads
for entry in "$1"/*.mp4
do
ext="${entry##*.}"
filename="${entry:0:${#entry} - ${#ext}}"
mp3file="${filename}mp3"
echo "$entry ===> $mp3file"
ffmpeg -i "$entry" -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 "$mp3file"
done
Battery Status of your Visitor’s Mobile Phone
When someone visits your website, you can easily retrieve information about the charge level of their mobile or laptop’s battery through the Battery Status API.
Here the source code:
How to add a Snowstorm in your blog
If you have a blog and you want add a snowstorm in your blog the best and fast choice is the following:
How can I refresh an image without refreshing the whole page?
<script>
var reimg
window.onload=function () {
reimg=document.getElementById('re')
setInterval(function () {
reimg.src=reimg.src.replace(/\?.*/,function () {
return '?'+new Date()
})
},2000)
}
</script>
<img src="http://151.97.160.13/GetImage.cgi?CH=0" id="re">
where http://151.97.160.13/GetImage.cgi?CH=0 is the image that you ant refresh
and 2000 is the interval time in milleseconds.
Use any youtube video as your page background
You can use any youtube video as your page background in this way:
where DSLgAsrcpGQ is the ID of your youtube video.
<html> <style> #main { padding:3em 2em; //background-color:#333; position:absolute; //top:50%; //left:50%; top:0%; left:0%; //margin-top:-150px; //margin-left:-150px; //width:340px; //height:140px; width:100%; height:100%; -moz-opacity: 0.35; -khtml-opacity: 0.35; opacity: 0.35; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha"(Opacity=35); filter: progid:DXImageTransform.Microsoft.Alpha(opacity=35); filter:alpha(opacity=35); } </style> <title>Youtube background in your page</title> <body><div style="position: fixed; z-index: -99; width: 100%; height: 100%"> <iframe frameborder="0" height="100%" width="100%" src="https://youtube.com/embed/DSLgAsrcpGQ?autoplay=1&controls=0&loop=1&showinfo=0&autohide=1&wmode=transparent&hd=1"> </iframe> </div><div id="main" > <center> <img src="http://static.lulu.com/browse/product_thumbnail.php?productId=21371401&resolution=320"> </center> <!-- <iframe frameborder="0" height="100%" width="100%" src="http://www.mypage.com"> </iframe> --> </div></body> </html>
where DSLgAsrcpGQ is the ID of your youtube video.
Anti-SPAM Service
If you want to protect your email from SAPM you can use this wonderful service of google
How to build your Qr code in 5 minutes
Suppose that you want create a qr code (text) with the following message:
You can simply use the following url:
https://chart.googleapis.com/chart?cht=qr&chl=smile and the world will smile&chs=250x250&choe=UTF-8&chld=L|2
the result will be:
Now you want create a qr code with a ulr and the url is the following:
in this case you can to use:
https://chart.googleapis.com/chart?cht=qr&chl=http://next72.blogspot.com&chs=250x250&choe=UTF-8&chld=L|2
the result is the following:
If you want put a url and a message then you will use:
Message: smile and the world will smile
url: http://next72.blogspot.com
https://chart.googleapis.com/chart?cht=qr&chl=MEBKM:TITLE:smile and the world will smile;URL:http://next72.blogspot.com;&chs=250x250&choe=UTF-8&chld=L|2
the result will be the following:
"smile and the world will smile"
You can simply use the following url:
https://chart.googleapis.com/chart?cht=qr&chl=smile and the world will smile&chs=250x250&choe=UTF-8&chld=L|2
the result will be:
Now you want create a qr code with a ulr and the url is the following:
http://next72.blogspot.com
in this case you can to use:
https://chart.googleapis.com/chart?cht=qr&chl=http://next72.blogspot.com&chs=250x250&choe=UTF-8&chld=L|2
the result is the following:
If you want put a url and a message then you will use:
Message: smile and the world will smile
url: http://next72.blogspot.com
https://chart.googleapis.com/chart?cht=qr&chl=MEBKM:TITLE:smile and the world will smile;URL:http://next72.blogspot.com;&chs=250x250&choe=UTF-8&chld=L|2
the result will be the following:
Subscribe to:
Posts (Atom)













