Beranda > Pemrograman > Pemrograman GUI Menggunakan Gambas + wkhtmltopdf + Ubuntu (Convert HTML ke PDF)

Pemrograman GUI Menggunakan Gambas + wkhtmltopdf + Ubuntu (Convert HTML ke PDF)

Tutorial ini akan membarikan gambaran bagaimana membuat tampilan GUI dari sebuah program berbasis console.

wkhtmltopdf merupakan aplikasi konsole perubah HTML ke format PDF.

Sebelumnya install terlebih dahulu  wkhtmltopdf dengan menggunakan Ubuntu Software Center.

Contoh syntax penggunaan  wkhtmltopdf :

root@ubuntu:~# wkhtmltopdf http://code.google.com/p/wkhtmltopdf/ aaa.pdf

Berikut tutorial membuat GUI dari sebuah aplikasi berbasis Konsole:

Berikut Source code lengkap tutorial ini:

‘ Gambas class file

PUBLIC SUB _new()

END
‘==============================================================
PUBLIC SUB Form_Open()
FileView1.Dir = DirView1.Current
FMain.Top = (Desktop.height / 2) – (FMain.height / 2)
FMain.Left = (Desktop.Width / 2) – (FMain.Width / 2)
END
‘==============================================================
PUBLIC SUB Form_Close()
login.Close
END
‘==============================================================
PUBLIC SUB ToggleButton1_Click()
DIM namaasal AS String
DIM namasimpan AS String
DIM j AS String
DIM xxx AS Boolean
DIM status AS String

Timer1.Enabled = TRUE
Timer2.Enabled = TRUE
Label5.Caption = “Converting…”
‘EXEC [“wkhtmltopdf”, ” http://ilmuphotoshop.com/2010/07/09/membuat-efek-foto-kanvas/”, “/home/yopi/Desktop/test2.pdf”]
IF TextBox1.Text = “” OR TextBox2.Text = “” OR TextBox3.Text = “” OR TextBox4.Text = “” THEN
ELSE
IF Right$(TextBox1.text, 4) = “html” OR Right$(TextBox1.text, 4) = “HTML” THEN
namaasal = TextBox1.Text
namasimpan = TextBox2.Text & TextBox3.Text & TextBox4.Text
ToggleButton1.Enabled = FALSE
xxx = Exist(namasimpan)
IF xxx = TRUE THEN
status = “TRUE”
ELSE
status = “FALSE”
END IF

TextBox5.text = status
ProgressBar1.value = 0

EXEC [“wkhtmltopdf”, namaasal, namasimpan]
ELSE
Timer1.Enabled = FALSE
status = “TRUE”
ToggleButton1.Enabled = TRUE
Label5.ForeColor = &H00C000&
Label5.Caption = “Done…”
END IF
END IF

Timer2.Enabled = FALSE
END
‘==============================================================
PUBLIC SUB ToggleButton2_Click()

DIM imageFile AS String
Dialog.Filter = [“*.html”, “Web Page”]
IF Dialog.OpenFile(TRUE) THEN RETURN
FOR EACH imageFile IN Dialog.Paths
TextBox1.Text = imageFile
NEXT
CATCH
Message.Info(Error.Text)

END
‘==============================================================
PUBLIC SUB DirView1_Click()

FileView1.Dir = DirView1.Current

END
‘==============================================================
PUBLIC SUB FileView1_Click()
Timer1.Enabled = FALSE
TextBox1.text = DirView1.Current & “/” & FileView1.Current
TextBox3.text = FileView1.Current
END
‘==============================================================
PUBLIC SUB Timer1_Timer()
DIM namaasal AS String
DIM namasimpan AS String
DIM xxx AS Boolean
DIM status AS String

namaasal = TextBox1.Text
namasimpan = TextBox2.Text & TextBox3.Text & TextBox4.Text

xxx = Exist(namasimpan)
IF xxx = TRUE THEN
status = “TRUE”
ToggleButton1.Enabled = TRUE
Label5.ForeColor = &H00C000&
Label5.Caption = “Done…”

ELSE
status = “FALSE”
ToggleButton1.Enabled = FALSE
Label5.ForeColor = &HC00000&
Label5.Caption = “Converting…”

END IF

TextBox5.text = status

END
‘==============================================================
PUBLIC SUB ToggleButton4_Click()

DIM xxx AS Boolean
DIM status AS String
status = “TRUE”
ToggleButton1.Enabled = TRUE
Label5.ForeColor = &H00C000&
Label5.Caption = “Done…”

END

Kategori:Pemrograman
  1. Belum ada komentar.
  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: