Rabu, 02 Maret 2011

Merubah scanned pdf menjadi teks html


           Ketika mencari sumber referensi, saya mendapatkan file pdf yang contentnya/teks berupa gambar. Akibatnya saya tidak bisa mengcopy tulisannya(wkwkwk... kebiasaan buruk). Ada salah satu cara untuk merubah scanned pdf menjadi html, dengan menggunakan fasilitas google. Jika mendapatkan hasil pencarian file pdf, maka google akan menampilkan opsi untuk menampilkannya dalam bentuk html. Cara ini hanya berguna jika file pdfnya terindeks semua dan google hanya menampilkan 20 halaman pertamanya saja. 

         Ada satu cara lain, yaitu mengkonversi file pdf tersebut menjadi kumpulan gambar(.png, .jpg), lalu kemudian menscan gambar tersebut dengan OCR, lalu untuk outputnya berupa HTML atau file teks. Karena saya(penulis) menggunakan operating system GNU/linux ubuntu, maka cara dibawah ini hanya berlaku untuk OS GNU/linux saja( untuk yang versi windows, tanya ke orang lain saja yaaa!).

Langsung saja....
Pertama-tama install terlebih dahulu xpdf, imagemagick, dan ocropus


sudo apt-get install xpdf imagemagick ocropus

gunakan script dibawah ini untuk menkonversi. Simpan dengan nama "pdf2txt"(tanpa tanda kutip).


#! /bin/sh
# Simple wrapper to recognize PDF files
#
# This script is based on ocropdf by Christian Mahnke
# original script can be downloaded from http://groups.google.com/group/ocropus/attach/e3cd3c9c36dfce87/ocropdf?part=2
#
# I just modify it, to achieve my requirement
#
#Usage:
#pdf2html input.pdf > hocr-output.html
#
#The following environment variables are recognised:
#- PDFIMAGES: Path to 'pdfimages' if it's not in your path
#- CONVERT: Path to 'pdfimages' if it's not in your path
#- OCROSCRIPT: Path to 'ocroscript' if it's not in your path or this script is not #placed in the ocropus source tree (in the 'ocrocmd' directory)
#- tesslanguage: The language tesseract should use.
#
#
#Known problems:
# - Doesn't work with file names containing spaces.
# - Only works with a singe PDF file.
#
#Possible improvements
# - reimplement it as Lua script.
# - Use this approach (imagemagick) to be able to recognise TIFF and other file formats.
#
# By Alvin from orangunix.blogspot.com
if test -z "$PDFIMAGES" ; then
PDFIMAGES=`which pdfimages`
fi
if test -z "$CONVERT" ; then
CONVERT=`which convert`
fi
if test -z "$PDFIMAGES" ; then
echo "'pdfimages' not found in PATH (it's part of the xpdf package)"
fi
if test -z "$PDFIMAGES" ; then
echo "'convert' not found in PATH (it's part of the imagemagick package)"
fi
if test -z "$OCROSCRIPT" ; then
OCROSCRIPT=`which ocroscript`
if test -z "$OCROSCRIPT" ; then
DIR=`dirname $0`/../ocroscript
OCROSCRIPT="$DIR/ocroscript"
if test -z "$OCROSCRIPTS" ; then
OCROSCRIPTS=$DIR/scripts
fi
fi
fi
if test -z "$1" ; then
echo "Usage: ./pdf2txt input.pdf > hocr-output.html"
exit 1
fi
TMP_DIR=`tempfile -p pdf2txt`
rm -f $TMP_DIR
mkdir $TMP_DIR
echo $TMP_DIR
PDFIMAGES_CMD="$PDFIMAGES $1 $TMP_DIR/pdf2txt"
echo $PDFIMAGES_CMD
$PDFIMAGES_CMD
echo $TMP_DIR
for FILE in `ls $TMP_DIR`
do
#echo $FILE
CONVERT_CMD="$CONVERT $TMP_DIR/$FILE $TMP_DIR/$FILE.jpg"
$CONVERT_CMD
if test $? != 0 ; then
echo "'convert' failed"
exit 2
fi
FILES="$FILES $TMP_DIR/$FILE.jpg"
#rm -f $TMP_DIR/$FILE
done
$OCROSCRIPT recognize `ls $TMP_DIR | grep .pbm.jpg`
#if test -z "$tesslanguage" ; then
# OCROSCIPT_CMD="$OCROSCRIPT rec-tess $FILES"
#else
# OCROSCIPT_CMD="$OCROSCRIPT rec-tess --tesslanguage=$tesslanguage $FILES"
#fi
#
#$OCROSCIPT_CMD
#rm -r $TMP_DIR


Cara penggunaan :
Misalnya anda ingin menkoversi "makalah.pdf" ke dalam file html, gunakan perintah :

./txt2pdf makalah.pdf > makalah.html

perintah diatas akan menkonversi "makalah.pdf" dan outputnya "makalah.html".

oleh : Alvin

READ MORE - Merubah scanned pdf menjadi teks html

Minggu, 27 Februari 2011

Manajemen Bandwidth dengan Squid


Squid merupakan software proxy server/cache server yang free dan opensource. Squid biasanya dijalankan di sistem operasi GNU/Linux. Squid juga memiliki kelebihan mengatur dan membatasi bandwidth berdasarkan extension, misalnya sebuah server di konfigurasi untuk membatasi client hanya menggunakan bandwidth 100kbps untuk mendownload file berekstensi .flv, .avi, dan sebagainya.

Langsung saja ke tahap-tahap instalasi :
  • Saya sarankan menginstall squid dari source, sehingga dapat dikonfigurasi saat compile, karena secara default squid tidak mendukung fitur delay pool sebagai pengatur bandwidth.

  • Untuk mendapatkan performa maksimum, buatlah partisi tersendiri dengan ukuran kira-kira 300MB, beri nama partisi "/cache"(tanpa kutip).

  • Tambahkan/buat user "squid" ke dalam sistem :
useradd -d /cache/ -r -s /dev/null squid >/dev/null 2>&1
  • Download source squid menggunakan link di bawah ini(saat tulisan ini dibuat, rilis squid terbaru adalah versi 3.1.11) :
http://www.squid-cache.org/Versions/v3/3.1/squid-3.1.11.tar.gz
  • Extract file .tar.gz :
tar xzpf squid-3.1.11.tar.gz
  • compile dan install squid, folder instalasi adalah /opt
./configure --prefix=/opt/squid --exec-prefix=/opt/squid --enable-delay-pools --enable-cache-digests --enable-poll --disable-ident-lookups --enable-truncate --enable-removal-policies

make all

make install
  • konfigurasi file squid.conf(terletak di /opt/squid/etc/squid.conf)
#
# Recommended minimum configuration:
#
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
#acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
#acl localnet src fc00::/7 # RFC 4193 local private network range
#acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines

acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
#acl Safe_ports port 70 # gopher
#acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
#acl Safe_ports port 280 # http-mgmt
#acl Safe_ports port 488 # gss-http
#acl Safe_ports port 591 # filemaker
#acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT

#
# Recommended minimum Access Permission configuration:
#
# Only allow cachemgr access from localhost
http_access allow manager localhost
http_access deny manager

# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
http_access deny to_localhost

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#

# squid as an httpd accelerator
#httpd_accel_host virtual
# port you want to act as a proxy
#httpd_accel_port 80
# Squid act as both a local httpd accelerator and as a proxy
#httpd_accel_with_proxy on
# Header is turned on which is the hostname from the URL
#httpd_accel_uses_host_header on

# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost

# And finally deny all other access to this proxy
http_access deny all

# Squid normally listens to port 3128
http_port 3128

# We recommend you to use at least the following line.
hierarchy_stoplist cgi-bin ?

# set who user and group that squid will run, note : must run with root first!
cache_effective_user squid
cache_effective_group squid
#Memory the Squid will use. Well, Squid will use far more than that.
cache_mem 16 MB

# Uncomment and adjust the following to add a disk cache directory.
cache_dir ufs /cache 250 16 256

# Leave coredumps in the first cache dir
coredump_dir /opt/squid/var/cache

#Places where Squid's logs will go to.
cache_log /var/log/squid/cache.log
access_log /var/log/squid/access.log
cache_store_log /var/log/squid/store.log
cache_swap_log /var/log/squid/swap.log
#How many times to rotate the logs before deleting them.
#See the FAQ for more info.
logfile_rotate 10

# Add any of your own refresh_pattern entries above these.
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320

#all our LAN users will be seen by external web servers
#as if they all used Mozilla on windows xp sp2. :)
#anonymize_headers deny User-Agent
#fake_user_agent Mozilla/5.0 (compatible; U;windows xp sp2; en-US)

### DELAY POOLS ###

#This is the most important part for shaping incoming traffic with Squid
#For detailed description see squid.conf file or docs at http://www.squid-cache.org

#kita ingin membatasi bandwidth untuk mendownload file jenis yang disebutkan di bawah ini
#tulis semua dalam satu baris
acl magic_words url_regex -i ftp .exe .mp3 .vqf .tar.gz .gz .rpm .deb .zip .rar .avi .mpeg .mpe .bin .sh .tar.bz2 .pdf .mkv .ogg .mpg .qt .ram .rm .iso .raw .wav .mov .wmv .flv .mp4 #kita tidak membatasi .html, .gif, .jpg dan file lain yang sejenis
#karena tidak terlalu memboroskan bandwidth

#We have two different delay_pools
#View Squid documentation to get familiar
#with delay_pools and delay_class.
delay_pools 2

#First delay pool
#We don't want to delay our local traffic.
#There are three pool classes; here we will deal only with the second.
#First delay class (1) of second type (2).
delay_class 1 2

#-1/-1 mean that there are no limits.
#The numbers here are values in bytes;
#we must remember that Squid doesn't consider start/stop bits
#5000/150000 are values for the whole network
#5000/120000 are values for the single IP
#after downloaded files exceed about 150000 bytes,
#(or even twice or three times as much)
#they will continue to download at about 5000 bytes/s

delay_parameters 1 20000/150000 20000/120000
delay_access 1 allow magic_words


  • konfigurasi folder squid
mkdir /var/log/squid/
chown squid:squid /var/log/squid/
chmod 770 /var/log/squid/
chown -R squid:squid /opt/squid/
chown -R squid:squid /opt/squid/

  • karena pertama kali squid dijalankan, perintahkan squid untuk membuat terlebih dahulu folder cache
/opt/squid/bin/squid -z
  • jalankan squid
/opt/squid/bin/squid
Squid akan berjalan pada port 3128.

READ MORE - Manajemen Bandwidth dengan Squid

Jumat, 25 Februari 2011

Komponen pada Handphone Beserta Fungsi-Fungsinya


Handphone merupakan perangkat komunikasi yang telah luas digunakan oleh masyarakat di seluruh dunia. Handphone memiliki ukuran kecil sehingga mudah dibawa-bawa dan ringan. Sampai saat ini teknologi yang digunakan pada handphone meningkat dan handphone tidak hanya digunakan untuk komunikasi saja tetapi juga sebagai sarana hiburan dan manajemen personal sang pengguna. Terlepas dari fitur dan teknologi handphone yang bermacam-macam, dalam tulisan ini akan dijelaskan secara singkat komponen yang sering terdapat pada handphone. 

Pada handphone terdapat rangkaian utama yaitu :
  1. Rangkaian Transmisi(Tx)
  2. adalah rangkaian yang berfungsi untuk mentransmisikan/mengirimkan sinyal radio ke operator. Dalam rangkaian ini terdapat TX Filter, RF power amp, ANT switch, dll.
  3. Rangkaian Receiver(Rx)
  4. berfungsi untuk menerima sinyal dan penyaring sinyal yang diterima ponsel dari BTS. Dalam rangkaian ini terdapat Frequency Synthesizer, RX-VCO, dan Intermediate Frequency(IF) Module.
  5. IC power supply
  6. berfungsi untuk menyediakan daya pada seluruh komponen yang ada di handphone, sesuai dengan kebutuhan daya masing-masing komponen. IC ini juga memiliki fitur automatic charging, dan memutus aliran listrik ke baterai ketika baterai sudah full charge. Kebutuhan daya pada masing-masing bagian diatur menggunakan sinyal PWM.
  7. IC Power Amplifier
  8. Berfungsi sebagai penguat sinyal dan pengirim data ke operator yang menandakan bahwa nomor ringtone telah aktif. Berfungsi juga sebagai power transmit, yakni mengirimkan energi gelombang elektromagnetik ke operator sekaligus mengunci agar tetap tersambung. IC ini bekerja saat handphone dihidupkan dan saat melakukan panggilan. IC ini membutuhkan daya yang besar untuk menguatkan sinyal.
  9. Antena
  10. berfungsi untuk menangkap gelombang radio yang dipancarkan oleh operator.
  11. Switch antena(duplexer)
  12. berfungsi sebagai pengirim dan penerima gelombang elektromagnetik. Dengan teknologi full duplexer berupa switch antena pada handphone, kita dapat melakukan komunikasi dua arah. Duplexer merupakan penyesuai antara antena dan RF/PA.
  13. IF IC(RF Processor)
  14. Merupakan komponen pengolah sinyal yang masuk atau yang keluar dan memperkuat sinyal pada selisih frekuensi. Fungsi lain IF IC adalah sebagai mikser dan detektor. Sebagai mikser, IF IC mencampurkan sinyal operator dengan sinyal ponsel. Sebagai detektor, IF IC memangkas sinyal pembawa dan sinyal audio yang kemudian dialirkan ke IC audio sehingga terjadi selisih. Selisih tersebut diperkuat oleh IF IC sebagai detektor untuk memangkas sinyal pembawa dan sinyal audio yang kemudian dialirkan ke IC audio. Jika komponen ini rusak, ponsel tidak dapat menerima sinyal.
  15. IC audio
  16. Berfungsi memperbesar gelombang suara serta mengubah getaran dari digital ke analog atau sebaliknya. Fungsi IC audio adalah sebagai Pulse Code Modulation(PCM). Kerusakan pada IC audio dapat menyebabkan suara menjadi kecil.
KOMPONEN PROCESSOR
  1. Central Processing Unit(CPU)
  2. Merupakan pusat pengolahan data untuk menginstruksikan proses penyimpanan data ke memory. CPU bertugas untuk mengendalikan seluruh perangkat yang ada, dan memerintahkan perangkat spesifik untuk bekerja berdasarkan dengan instruksi yang tersimpan dalam memori atau via input user.
  3. EEPROM(Electrically Erasable Programmable Read Only Memory)
  4. Merupakan IC memori yang berisi data sistem operasi hp seperti program pada ponsel yang berisi gambar grafik, logo, dan nada dering.
  5. Random Access Memory(RAM)
  6. Merupakan IC memory yang digunakan CPU untuk menyimpan instruksi dan data. RAM bersifat volatile yaitu jika aliran listriknya putus maka data yang ada di dalamnya akan hilang.
  7. Digital Signal Processor
  8. Merupakan IC yang dirancang khusus untuk mengolah sinyal digital ke analog maupun dari sinyal analog ke digital.
  9. Multimode Adaptor(MMA) atau User Interface(UI)
  10. Merupakan IC yang mengatur komponen lain untuk berhubungan dengan output hp seperti buzzer/ringer, lampu, dan vibra(motor).
  11. Flash ROM
  12. Merupakan IC memori berisi data yang dapat diisi ulang dengan bantuan program komputer seperti ROM dan EEPROM. Data ini tetap ada walaupun hp dalam keadaan mati.
  13. 26 MHz Crystal Oscillator(Frequency Shynthesizer)
  14. Merupakan IC pembangkit sinyal frrekuensi di ponsel agar ponsel dapat menerima dan mentransmisikan data.
KOMPONEN INPUT
  1. Keypad
  2. Komponen masukan untuk membuat kombinasi alphanumeric yang tersambung ke CPU. Berfungsi membangkitkan getaran dual tonemulty frequency yang merupakan kode digital alphanumeric berupa huruf, angka, dan tanda baca. Sinyal tersebut merupakan terjemahan yang berdasarkan standar kode ASCII.
  3. Mikrofon
  4. Alat input untuk memasukkan suara ke dalam handphone. Bekerja dengan cara mengubah getaran suara menjadi getaran listrik audio analog. Sinyal analog selanjutnya diubah menjadi sinyal digital audio oleh Digital Signal Processor(DSP).
  5. Kamera
  6. Sensor optik yang menangkap gambar atau objek untuk kemudian diolah oleh bagian rangkaian dan diteruskan ke handphone.
  7. VCO
  8. Merupakan IC yang berguna pada proses penerimaan sinyal dari operator. Bila IC ini rusak, penerimaan sinyal akan mengalami kegagalan.
KOMPONEN OUTPUT
  1. Ear Piece
  2. Berfungsi untuk mengubah getaran audio analog dari Digital Signal Processor(DSP) menjadi getaran udara yang akan terdengar sebagai suara.
  3. LCD
  4. Output yang mengubah sinyal SAN dan SGR menjadi gambar dan tulisan sebagai media untuk baca dan tulis. LCD juga berfungsi menampilkan tulisan, gambar, indikator baterai (penuh atau tidak), dan indikator sinyal.
  5. Buzzer
  6. Komponen penghasil ringtone atau alat speaker yang mengubah sinyal nada dering menjadi getaran udara yang terdengar sebagai suara melodi atau musik. Nada dering ini berasal dari MMA pada CPU yang diambil dari RAM.
  7. Vibrator
  8. Merupakan motor atau dinamo yang berputar dan menghasilkan getaran mekanik. Getaran mekanik ini akan terasa pada saraf kulit manusia.
KOMPONEN INPUT-OUTPUT
  1. konektor sim card
  2. merupakan tempat untuk terhubungnya sim card dengan PCB pada ponsel.
  3. Infra Red(IR)
  4. fungsinya menghubungkan hp dengan komponen lain sebagai jembatan data melalui media sinar infra merah.
  5. Bluetooth
  6. komponen yang fungsinya sama dengan infra merah, tetapi menggunakan gelombang radio yang berbentuk gigi gergaji sebagai medianya.
sumber : Daniswara Sony & Riyan, Mencari dan Memperbaiki Kerusakan pada Handphone, Kawan Pustaka
READ MORE - Komponen pada Handphone Beserta Fungsi-Fungsinya

Jumat, 31 Desember 2010

Python : Membuat GUI dengan PyGTK

    Berbagai macam toolkit GUI untuk python diantaranya tk, wxPython, PyGTK, dan lain-lain. Kali ini source code menggunakan PyGTK. Kelebihan PyGTK adalah toolkit ini melakukan manajemen memory GUI secara otomatis, sehingga memudahkan programmer tanpa perlu untuk bersusah payah dalam urusan memanajemen memori. Di bawah ini adalah source code untuk menampilkan tombol dengan text "Hello world". Jika tombol ditekan maka pada commandline akan tercetak "Hello world".

    1   #!/usr/bin/env python
    2
    3   # example helloworld.py
    4
    5   import pygtk
    6   pygtk.require('2.0')
    7   import gtk
    8
    9   class HelloWorld:
   10
   11       # This is a callback function. The data arguments are ignored
   12       # in this example. More on callbacks below.
   13       def hello(self, widget, data=None):
   14           print "Hello World"
   15
   16       def delete_event(self, widget, event, data=None):
   17           # If you return FALSE in the "delete_event" signal handler,
   18           # GTK will emit the "destroy" signal. Returning TRUE means
   19           # you don't want the window to be destroyed.
   20           # This is useful for popping up 'are you sure you want to quit?'
   21           # type dialogs.
   22           print "delete event occurred"
   23
   24           # Change FALSE to TRUE and the main window will not be destroyed
   25           # with a "delete_event".
   26           return False
   27
   28       # Another callback
   29       def destroy(self, widget, data=None):
   30           gtk.main_quit()
   31
   32       def __init__(self):
   33           # create a new window
   34           self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
   35
   36           # When the window is given the "delete_event" signal (this is given
   37           # by the window manager, usually by the "close" option, or on the
   38           # titlebar), we ask it to call the delete_event () function
   39           # as defined above. The data passed to the callback
   40           # function is NULL and is ignored in the callback function.
   41           self.window.connect("delete_event", self.delete_event)
   42
   43           # Here we connect the "destroy" event to a signal handler.
   44           # This event occurs when we call gtk_widget_destroy() on the window,
   45           # or if we return FALSE in the "delete_event" callback.
   46           self.window.connect("destroy", self.destroy)
   47
   48           # Sets the border width of the window.
   49           self.window.set_border_width(10)
   50
   51           # Creates a new button with the label "Hello World".
   52           self.button = gtk.Button("Hello World")
   53
   54           # When the button receives the "clicked" signal, it will call the
   55           # function hello() passing it None as its argument.  The hello()
   56           # function is defined above.
   57           self.button.connect("clicked", self.hello, None)
   58
   59           # This will cause the window to be destroyed by calling
   60           # gtk_widget_destroy(window) when "clicked".  Again, the destroy
   61           # signal could come from here, or the window manager.
   62           self.button.connect_object("clicked", gtk.Widget.destroy, self.window)
   63
   64           # This packs the button into the window (a GTK container).
   65           self.window.add(self.button)
   66
   67           # The final step is to display this newly created widget.
   68           self.button.show()
   69
   70           # and the window
   71           self.window.show()
   72
   73       def main(self):
   74           # All PyGTK applications must have a gtk.main(). Control ends here
   75           # and waits for an event to occur (like a key press or mouse event).
   76           gtk.main()
   77
   78   # If the program is run directly or passed as an argument to the python
   79   # interpreter then create a HelloWorld instance and show it
   80   if __name__ == "__main__":
   81       hello = HelloWorld()
   82       hello.main()

oleh : alvin
source code : Pygtk tutorial 2.0 by John Finlay
READ MORE - Python : Membuat GUI dengan PyGTK

Menampilkan bilangan fibonacci dengan python

Berikut ini adalah source code python untuk menampilkan bilangan fibonacci.

angka = input("masukkan limit deret fibonacci (angka) = ")
fibo = [0,1]
for a in range(angka):
    if a>1:
        print fibo[a-1] + fibo[a-2],
        fibo.append(fibo[a-1] + fibo[a-2])
    else:
        print fibo[a],

oleh : alvin
READ MORE - Menampilkan bilangan fibonacci dengan python
Add to Technorati Favorites Add to Technorati Favorites
OrangUNIX © 2008 Template by:
SkinCorner