Cara Membuat Tombol Print Seluruh/Sebagian Halaman Web

Sering kali sebuah web terutama web aplikasi memerlukan sebuah fungsi untuk mencetak/print halaman web baik keseluruhan maupun sebagian. Fungsi ini biasanya digunakan untuk mencetak laporan, mencetak screenshot halaman web dan sebagainya. Nah, di posting kali ini saya akan berbagi bagaimana caranya membuat sebuah tombol atau link untuk print halaman website.

mencetak halaman web

Mencetak Keseluruhan Halaman Web

Secara default, setiap browser mempunyai fungsi untuk mencetak halaman web. Untuk Google Chrome misalnya dengan menekan CTRL + P atau dengan klik kanan -> ‘print’. Namun, jika anda seorang pembuat web tidak ingin menyusahkan pengguna mencetak halaman web dengan cara tersebut, ada baiknya menggunakan tombol untuk mencetak halaman tersebut. Caranya mudah, hanya memasukkan kode sebagai berikut pada halaman web :

<button onclick="window.print()">Cetak Halaman Web</button>

Demo :

Untuk Style desainnya, silahkan kustomisasi sendiri dengan menggunakan kode CSS.

Mencetak Sebagian Halaman Web

Cara 1

Pada browser manapun, setahu saya tidak ada fitur khusus untuk mencetak sebagian halaman web. Tapi, ada website yang menyediakan layanan untuk mencetak/print sebagian halaman web yang diinginkan, yaitu Www.printwhatyoulike.com.

print yang kamu suka

Kunjungi websitenya, lalu masukkan url web yang ingin di print dan anda akan dialihkan ke halaman di mana anda dapat memilih bagian mana yang ingin dicetak.

pilih bagian yang akan di print

Lalu klik tombol print yang ada di pojok kiri atas halaman, anda akan dialihkan ke panel pengaturan pencetakan default browser.

Untuk Membuat link tombolnya agar memudahkan pengunjung, cukup buat dengan kode dibawah ini :

<a href="http://www.printwhatyoulike.com/print?url=url_halaman_yang_akan_diprint">Cetak Halaman</a>

Cara 2

Jika anda tidak ingin menggunakan web printwhatyoulike.com, anda bisa mencetak sebagian halaman web dengan menggunakan javascript. Namun, dengan cara ini pengguna tidak bisa memilih halaman yang akan dicetak karena sudah ditentukan oleh anda. Cara ini berguna untuk halaman web berisi bagian tertentu yang harus di print, dan bagian lainnya tidak.

Caranya adalah dengan menambahkan kode javascript berikut ini sebelum tag html </body> :

<textarea id="printing-css" style="display:none;">.no-print{display:none}</textarea>
<iframe id="printing-frame" name="print_frame" src="about:blank" style="display:none;"></iframe>
<script type="text/javascript">
function printDiv(elementId) {
 var a = document.getElementById('printing-css').value;
 var b = document.getElementById(elementId).innerHTML;
 window.frames["print_frame"].document.title = document.title;
 window.frames["print_frame"].document.body.innerHTML = '<style>' + a + '</style>' + b;
 window.frames["print_frame"].window.focus();
 window.frames["print_frame"].window.print();
}
</script>

Lalu, buat tombol/link printnya dengan kode di bawah ini :

<a href="javascript:printDiv('id-elemen-yang-ingin-di-print');">Print</a>

Dan, elemen web yang akan di printnya mempunyai atribut id=”id-elemen-yang-ingin-di-print” . misalnya :

<div id="id-elemen-yang-ingin-di-print"> ..... </div>

Demo Link : http://jsfiddle.net/tovic/cSN9G/embedded/result,html,js,css/

Bagaimana ?  work? Jika ada pertanyaan, jangan sungkan tanyakan di komentar. Jangan lupa share ke fb atau twitter apabila merasa posting ini bermanfaat. Sekian, semoga bermanfaat 🙂

~Muhammad Syakirurohman~

referensi : http://www.dte.web.id/2013/03/printmencetak-sebagian-halaman-saja.html

cialis samples overnight ciprofloxacin 500 azithromycin pediatric dosing what does ciprofloxacin 500mg treat acyclovir dosage for cold sores zovirax cream viagra wikipedia viagra coupons cialis vs viagra levitra coupon free cialis finasteride cialis alternative post finasteride syndrome acyclovir 400mg azithromycin class levitra erfahrungen azithromycin eye drops generic for lexapro how does lexapro work cipro drug class tamoxifen interaction viagra without a doctor prescription usa zovirax pills stopping lexapro female viagra finasteride for women what is finasteride used for cheap cialis lexapro para que sirve acyclovir dose finasteride 5mg tab cialis price how to wean off lexapro cialis vs viagra tamoxifen cost levitra 10 mg prezzo natural viagra cialis coupon print cialis sample cialis coupons from manufacturer is lexapro a controlled substance viagra price acyclovir medication free viagra cialis coupons thuoc azithromycin tamoxifen citrate what is cipro used for levitra online cialis patent expiration 2017 azithromycin 500 mg viagra coupon azithromycin for uti buy cialis escitalopram effets secondaires cialas viagra tablets escitalopram 10 mg lexapro medication viagra 100 buy cialis online azithromycin drug class how does cialis work ciprofloxacin drops what does viagra do ciprofloxacin hcl effects of stopping finasteride acyclovir ointment 5 cialis for sale viagra vs cialis vs levitra what is ciprofloxacin tamoxifen cialis for bph viagra pillen kruidvat finasteride long term effects azithromycin for pneumonia lexapro dosing viagra pill ciprofloxacin 500 mg lexapro reviews lexapro 10mg is azithromycin cialis savings card cialis from canada tamoxifen and weight gain how long for azithromycin to take effect viagra for sale cipro side effects in elderly ciprofloxacin 500mg antibiotics cialis voucher cipro cialis online cheap viagra cialis 30 day sample azithromycin tablet cialis coupon zovirax how does viagra work finasteride for hair loss acyclovir for shingles what is ciprofloxacin prescribed for viagra without a doctor prescription finasteride side effects in men viagra canada azithromycin liquid lexapro viagra prices how much does cialis cost over the counter viagra side effects of viagra cost of cialis azithromycin three times a week side effects of cialis levitra 20mg cost per pill buy levitra online sophia viagra cialis tadalafil tamoxifen nebenwirkungen azithromycin z pak pfizer viagra coupons from pfizer azithromycin without a doctor’s prescription viagra samples viagra vs cialis vs levitra acyclovir what is azithromycin used for viagra from canada does lexapro cause weight gain viagra ohne rezept auf rechnung azithromycin 250 mg treatment azithromycin coverage side effects of azithromycin how does acyclovir work viagra on line no prec tamoxifen and foods to avoid order viagra how to get off lexapro what is tamoxifen azithromycin 500 erfahrungen liquid cialis cialis pills acyclovir side effects lexapro side effects men is tamoxifen chemotherapy escitalopram side effects lexapro generic name azithromycin dosage cialis patent expiration tamoxifen bijwerkingen viagra for women viagra side effects viagra effects revatio vs viagra cipro and tendonitis ciprofloxacin 500mg antibiotics side effects what is cipro ciprofloxacin drug class viagra activate levitra bayer 20mg meilleur prix azithromycin pregnancy category lexapro generic ciprofloxacin 500mg tablets levitra prezzo in farmacia azithromycine eg 500 mg bijsluiter lexapro 20mg finasteride results viagra on line cialis pharmacy prices levitra vs viagra side effects of finasteride 5mg viagra vs cialis cialis professional lexapro benefits for women cipro dosage viagra for sale uk levitra generic finasteride side effects when will cialis go generic lexapro manufacturer website lexapro and weight loss discount cialis wholesale cialis finasteride 5mg side effects viagra lexapro vs celexa common side effects of ciprofloxacin 500 mg cialis coupons printable levitra 20 mg von bayer ciprofloxacin side effects lexapro ciprofloxacin 250mg levitra coupons cialis generic cialis 5mg daily cialis canada levitra 20 mg azithromycin 250 azithromycin uses lexapro dosage lexapro vs wellbutrin utilisation viagra cialis testimonials lexapro side effects in women acyclovir 200mg finasteride medication buy generic levitra viagra dosage discount viagra lowest cialis prices viagra alternatives cipro antibiotic what is azithromycin for generic lexapro cilias acyclovir for cold sores cyalis generic cialis finasteride 1mg is azithromycin penicillin zithromax 500 mg cialis for men antibiotic ciprofloxacin cialis cheap ciprofloxacin for dogs viagra alternative levitra prices ciprofloxacin 500 mg tabletten cialis reviews viagra cost cialis 20 mg sex viagra for women how to take cialis cialis 20mg directions wellbutrin and lexapro finasteride dosage viagra cialis zithromax z-pak women viagra acyclovir 800mg weaning off lexapro tamoxifen side effects in women 200 cialis coupon escitalopram 20 mg finasteride reviews levitra 20mg what is cialis lexapro withdrawal symptoms azithromycin viagra generico price cialis erectile dysfunction cialis azithromycin cost cialis discount buy viagra online cialis 5mg azithromycin 5 day dose pack side effects of azithromycin 250 mg cialis daily what is tamoxifen used for side effects of tamoxifen cialis for women how to wean off lexapro without withdrawals cialis canadian pharmacy levitra 20 mg precio farmacia what is acyclovir cialis 10 mg ciprofloxacin dose cialis without a doctor’s prescription viagra 50mg lexapro vs zoloft finasteride effets secondaires viagra soft ciprofloxacin hydrochloride ophthalmic levitra dosage cialis for daily use ciprofloxacin uses viagra natural viagra pills side effects of ciprofloxacin 500 mg cialis dosage recommendations azithromycin side effects cialis pills for sale escitalopram 10mg cialis side effects tamoxifen therapy side effects of lexapro in women what bacteria does ciprofloxacin kill tamoxifen side effects cialis copay card finasteride and enlarged prostate cialis 5 mg ciprofloxacin eye drops is ciprofloxacin a penicillin ciprofloxacin hcl 500 mg side effects of lexapro 10 mg canadian cialis cipro antibiotics azithromycine lexapro dosages zithromax lexapro and weight gain in women cialis on line acyclovir ointment escitalopram nebenwirkungen ciprofloxacin hydrochloride ciprofloxacin spc azithromycin 250mg tablets 6 pack levitra rezeptfrei deutschland viagra 100 mg finasteride vs dutasteride finasteride 5mg side effects mayo clinic cialis prices cialis 20mg propecia levitra vs viagra for hardness viagra generic what is lexapro used for online viagra generic viagra 100mg cialis 30 day trial coupon generic levitra how long for lexapro to work how long does viagra last ciprofloxacin class acyclovir dosage viagra receptfritt side effects of acyclovir cheap levitra best price viagra escitalopram 10 mg para que sirve viagra 100mg canada cialis ciprofloxacin nebenwirkungen celexa vs lexapro viagra vs cialis zovirax dosage viagra sex viagra for men what infections does ciprofloxacin treat nolvadex cipro side effects finasteride efectos secundarios vardenafil 20mg lexapro side effects in men zithromax dosage what is escitalopram cialis generic tadalafil canadian viagra ciprofloxacin dosierung what is ciprofloxacin used for side effects of finasteride lexapro overdose azithromycin 500 what is acyclovir used for cialis coupons 2017 cialis samples cialis trial viagra costs what does finasteride do viagra uk escitalopram cipro for uti ciprofloxacin ophthalmic solution viagra sans ordonnance cialis dosage strengths viamedic cialis levitra without a doctor prescription pfizer viagra vardenafil vs viagra ciprofloxacin 500mg ciprofloxacin side effects what does azithromycin treat what is lexapro for online cialis ciprofloxacin used for viagra ohne rezept aus deutschland cialis otc generic for cialis cialis generic availability finasteride 5mg generic levitra vardenafil 20mg ciprofloxacin 500 mg for urinary tract infection escitalopram oxalate cialis medication viagra online generic viagra ciprofloxacin bnf ciprofloxacin side effects after age 60 azithromycin vs erythromycin withdrawal from lexapro cialis pricing ciprofloxacin hcl 500 mg tab viagra 100mg tablets retail price levitra 20 mg cost walmart zovirax for cold sores tamoxifen lawsuits viagra tablet what works better than viagra buying viagra finasteride tablets lexapro withdrawal cipro 500 cialis cialis website acyclovir dosing acyclovir vs valacyclovir how to use viagra tamoxifen side effects in women over 55 viagra kaufen azithromycin for strep throat generic cialis tadalafil herbal viagra zoloft vs lexapro buy viagra azithromycine 250 mg azithromycin and alcohol finasteride permanent side effects viagra en ligne livraison 24h cialis free trial equipe argentine viagra lexapro bula azithromycin 250 mg lexapro for anxiety side effects of ciprofloxacin acyclovir 800 mg for shingles viagra bestellen lexapro and wellbutrin combination therapy lexapro side effects zovirax ointment what is cipro usually prescribed for viagra wiki viagra medicine zithromax antibiotic propecia side effects azithromycin tablets azithromycin 250mg azithromycin 500mg acyclovir 800 mg viagra nebenwirkungen canada viagra cipro dangers acyclovir cream cialis dosage what is viagra azithromycin medscape finasteride 5 mg what is lexapro first few days on lexapro where to buy viagra what does ciprofloxacin treat finasteride hair loss viagra substitute daily cialis what is acyclovir for ciprofloxacin 250 mg cost of viagra cialis coupon 20 mg azithromycin pregnancy buy generic viagra levitra vs viagra what is azithromycin lexapro 5mg buy levitra cipro uses cealis levitra lexapro and weight gain viagra single packs cialis effects cialis patent expiration date extended effects of stopping lexapro suddenly lexapro weight gain generic cialis at walmart finasteride 5 mg tab tamoxifen langzeitfolgen tamoxifen and bone pain ciprofloxacin side effects in women lexapro coupons what is finasteride 9 levitra at walmart side effects of lexapro cialis or viagra ciprofloxacin dosage acyclovir 400 mg viagra tesco lexapro 10 mg cialis cost ciprofloxacin coverage acyclovir 800 mg 5 times a day ciprofloxacin hcl 500 mg side effects

22 Comments

  1. kalo nge print image + text gimana gan ? saya nge print image yang ada text nya, yang ke print hanya text nya aja, background yang di belakangnya gak ikutan ke print

  2. Sip mas , sngat mmbantu

  3. .no-print{display:none}

    itu untuk apa ya maksudnya?

  4. gan kalo misalkan di web localhost saya cmn ada gambar ama tombol, trus kalau print gambarnya aja gmna gan?

    gambarnya ini terhubung ke database gan,
    terima kasih gan

  5. mas, kalau merubah tampilannya bisa, soalnya punya saya tampilan saat di print dengan halaman yang ingin di print berbeda

  6. saya nyoba sintaknya kok tidak bisa??

  7. Mas , saya sudah coba mengguankan window.print . nah ternyata di setiap halaman berbeda ukuran nya .
    misal di halaman 1 saya menggunakan margin top : 5 px . tetapi di halaman kedua , margin top tersebut tidak berfungsi . kenapa ya ?
    padahal saya ingin di setiap halaman , sama hal nya dengan halaman pertama

  8. Gan, saya ingin mencetak halaman web dengan tabel berwarna, saya menggunakan css, tetapi pada saat di print preview kenapa ya warna nya hilang?

  9. sya mencoba kok ngelink.nya di situs PrintWhatYoyLike mas??tolong kasih pencerahan

  10. Makasih gan infonya bermanfaat sekali

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *