VB.NET – Cetak dengan custom paper size menggunakan crystal report viewer.

Tutorial Level : Intermediate -> Advanced

Berikut langkah-langkah untuk mencetak laporan dengan ukuran kertas yang kita tentukan.

Spesifikasi Computer Admin:

  • OS Windows 7
  • Visual Studio 11 / Visual Studio 2012
  • Crystal Report 13_0_5
  • Printer : EPSON L355 Series

Langkah 1 – Set terlebih dahulu ukuran kertas.

Klik Start > Devices and Printers > Print Server Properties

Create form baru dengan nama “TTH” kemudian save form.

Image

Langkah 2 – Coding pencetakan laporan

Buat sebuah public function untuk menentukan ukuran kertas

Public Function GetPapersizeID(ByVal PrinterName As String, ByVal PaperSizeName As String) As Integer
	Dim doctoprint As New System.Drawing.Printing.PrintDocument()
	Dim PaperSizeID As Integer = 0
	Dim ppname As String = ""
	Dim s As String = ""
	doctoprint.PrinterSettings.PrinterName = PrinterName '(ex."EpsonSQ-1170ESC/P2")
	For i As Integer = 0 To doctoprint.PrinterSettings.PaperSizes.Count - 1
		Dim rawKind As Integer
		ppname = PaperSizeName
		If doctoprint.PrinterSettings.PaperSizes(i).PaperName = ppname Then
			rawKind = CInt(doctoprint.PrinterSettings.PaperSizes(i).GetType().GetField("kind",
			Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic).GetValue(doctoprint.PrinterSettings.PaperSizes(i)))
			PaperSizeID = rawKind
			Exit For
		End If
	Next
	Return PaperSizeID
End Function

Sisipkan coding berikut ke dalam tombol cetak.

Dim repOptions As CrystalDecisions.CrystalReports.Engine.PrintOptions
With rptDocument
	repOptions = .PrintOptions
	With repOptions
		.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Portrait
		.PaperSize = GetPapersizeID("EPSON L355 Series", "TTH")
		.PrinterName = "EPSON L355 Series"
	End With
' Set the Report Option first before loading the report or else settings won't take effect
	.Load(path, CrystalDecisions.Shared.OpenReportMethod.OpenReportByDefault)
	.SetDataSource(_dtReport)
	.Refresh()
	.PrintToPrinter(1, True, 0, 0)
End With

Semoga Membantu. Tq

About evocruzader

I am a honest, energetic, cool, n fun... gather near me and u will live with full of joy n fun. ^^
Aside | This entry was posted in Coding, Information, IT, Pemrograman, VB.NET and tagged , , , . Bookmark the permalink.

2 Responses to VB.NET – Cetak dengan custom paper size menggunakan crystal report viewer.

  1. muhammad fiqri says:

    mas saya.SetDataSource(_ini di isi apa?) dikurung ini dataset atau database mas?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s