Author Topic: Sharing Tentang Setting Customer Paper Size  (Read 549 times)

0 Members and 1 Guest are viewing this topic.

Offline oongs

  • Newbie
  • *
  • Posts: 21
Sharing Tentang Setting Customer Paper Size
« on: June 05, 2017, 10:46:34 PM »
Ini cerita pengalaman. Sy memanfaatkan Printer.DLL dari mas "yw2s"

http://www.ziddu.com/download/1662572/SetPrinter20080617.zip.html
http://widiwijanarko.blogspot.com/

Berjalan dengan baik dan sudah diaplikasikan ke salah satu klien. Di tempat klien sudah sy siapkan program khusus untuk merubah ukuran kertas. Jadi ada dua program yang berbeda, Program Stok dan Program Printer. (Beda folder juga). Suatu saat komputer klien terkena virus sehingga Windows XP dan property lainnya di install ulang. Program Stok dan Program Printer tidak terkena virus. Klien telah menjalankan Program Printer dan merubah ukuran kertas (quarto dibagi 2). Berjalan normal.

Selanjutnnya test cetak nota. Hasilnya? Kertas bergerak satu halaman.  :merror:

Klien menghubungi sy dan menceritakan keluhannya.

Ok ...

Di rumah sy siapkan keperluannya

Sy pakai Windows XP
sy Install printer sesuai printer klien (Epson LQ 21xx)
sy jalankan Program Printer dan merubah ukuran kertas (quarto dibagi 2)
Sy Compile ulang program Stok (EXE) (VFP ver. 7.0)

Di tempat klien

Sy copy file EXE dan saya jalankan program Stoknya.
Sy test cetak nota. Hasilnya? Kertas bergerak satu halaman.  :merror:
sy coba ulangi jalankan Program Printer dan merubah ukuran kertas
Hasilnya? Kertas bergerak satu halaman.

Di mana salahnya ....? (dalam hati sy ...)  ???

Akhirnya Source Code sy copy ke komputer klien
sy buka Report untuk cetak nota
Sy set lagi ukuran kertas
Sy Compile ulang
Hasilnya? Kertas berheti sesuai ukuran  :icon_biggrin:

Kesimpulan dari kejadian ini, terlatak pada :
  sy buka Report untuk cetak nota
  Sy set lagi ukuran kertas

Mungkin rekan" ada pengalaman seperti topik ini? Atau saran" lainnya? Monggo ...  :icon_study:

Offline poison

  • Hero Member
  • *
  • Posts: 1.597
  • Poison 4 Women
Re: Sharing Tentang Setting Customer Paper Size
« Reply #1 on: June 06, 2017, 05:46:17 AM »
betul, itu karena masing-masing ID Paper size pada masing-masing komputer belum tentu sama (sangat jarang sama).

kalau trik  saya (dulu) :
1. create paper size (kalau mau bisa juga lewat program kita)
2. edit paper id pada report kitam bisa menggunakan tehnik :
  - manual, buka reportnya lalu arahkan paper size ke yang dimaksud,
     syaratnya : report harus exclude, tau sendiri resiko kalau report diexclude
  - automatic,
     2a. export report yang diinclude, gimana caranya?!...(tentu tau dooong sebenernya apa terbuat dari apa itu file report, form, menus. yups perlakukan mereka seperti itu)
     2b. ganti paper id report yang sudah diexclude tersebut
     2c. jalankan report yang baru

saya lebih seneng pake cara Automatic, jadi bisa lebih aman & keren....
think BIG to get BIG thing

Offline xWongso

  • Newbie
  • *
  • Posts: 8
Re: Sharing Tentang Setting Customer Paper Size
« Reply #2 on: June 06, 2017, 01:10:55 PM »
Pengalaman saya, seharusnya tidak ada masalah...
1. Buat Custom PaperSize di Komputer Kita dan Client...Beri Nama Custom PaperSize Yang Sama Pada Kedua Komputer Tersebut
2. Report saya Exclude
3. Report Properties...Uncheck Save Printer Environment
4. Report Properties...Page Setup...Size : [NamaCustomPaperSize]...Printer : [SesuaikanDenganClient/Tidak Juga Tidak Masalah]
5. Tinggal Masalah Font...Kalau Pake Epson DotMatrix...sebaiknya Pakai Font Draft??pci...biar cetaknya lebih cepat.
6. Compile dengan VFP 9 SP 2

Rgds
XWongso

Offline yosef_fl

  • Full Member
  • *
  • Posts: 71
Re: Sharing Tentang Setting Customer Paper Size
« Reply #3 on: June 10, 2017, 01:29:27 PM »
pengalaman saya agak beda dengan yang diatas,report udah saya set custom paper size,tapi komputer pertama kali nyala,setting custom paper size pada printer tidak ada,mesti setting ulang lagi,hal ini terus terjadi .... apa ada solusi rekan2x ?

thank's
Yosef

Offline xWongso

  • Newbie
  • *
  • Posts: 8
Re: Sharing Tentang Setting Customer Paper Size
« Reply #4 on: June 11, 2017, 07:50:54 AM »
Pak Yosef_fl,

Kalau cara saya di atas tidak jalan, maka coba hack frx dengan fungsi yang saya buat dari Blog Pak Herman Tan di bawah ini...

*-----------------------
Function CustomPaper
*-----------------------
Parameters lc_PaperName,lc_PaperWidth,lc_PaperHeight
  * Fungsi Untuk Membuat Custom Paper
  * Usage : CustomPaper('TEST',21,7)
  * lc_PaperWidth,lc_PaperHeight use CentiMeter
  * Setelah create Custom Paper...Nama Custom Papernya di simpan di IniFile...ini berguna pada fungsi FILLPAPERIDTOFRX

Local hPrinter
Local cPrinterName, cPaperName
Local pPaperName, sPaperSize
Local nResult, nBufLen, nPaperWidth, nPaperHeight

Declare Long GetLastError in Kernel32
Declare Long ClosePrinter in WinSpool.Drv Long hPrinter
Declare Long OpenPrinter in WinSpool.Drv ;
String cPrinterName, Long @O_hPrinter, Long pDefault

Declare Long GetForm in WinSpool.drv as GetPrinterForm ;
Long hPrinter, String pFormName, ;
Long nLevelInfo, String @O_pFormInfo, ;
Long nBufSize, Long @O_nBufNeeded

Declare Long AddForm in WinSpool.drv as AddPrinterForm ;
Long hPrinter, Long nLevelInfo, String @pFormInfo

Declare Long LocalAlloc in Kernel32 Long uFlags, Long dwBytes
Declare Long LocalFree in Kernel32 Long hMem

cPrinterName = set( 'Printer', 2 ) && Get default Windows printer
hPrinter = 0

If (OpenPrinter( cPrinterName, @hPrinter, 0 ) != 0)
   cPaperName = lc_PaperName  &&&'Half A4 [PRODXW]'
   nBufLen = 32 && FORM_INFO_1_Size
   cInfo = Replicate( Chr(0), 32 )
   nResult = GetPrinterForm( hPrinter, cPaperName, 1, ;
      @cInfo, nBufLen, @nBufLen )

   If (nResult == 0) && Get printer form failed
      nResult = GetLastError()
      If (nResult == 1902) && ERROR_INVALID_FORM_NAME
         ** Custom Printer Form not exist, add the new one
         nPaperWidth = lc_PaperWidth*10*1000  &&210000  && Paper size is in 1/1000 millimeters
         nPaperHeight = lc_PaperHeight*10*1000 &&297000 / 2
         sPaperSize = BinToC( nPaperWidth, '4rs' ) + BinToC( nPaperHeight, '4rs' )
         pPaperName = LocalAlloc( 64, 32 )

         If (pPaperName != 0)
            Sys( 2600, pPaperName, Len( cPaperName ), cPaperName )
            cInfo = BinToC( 0, '4rs' ) + BinToC( pPaperName, '4rs' ) + ;
               sPaperSize + BinToC( 0, '4rs' ) + BinToC( 0, '4rs' ) + sPaperSize

            If (AddPrinterForm( hPrinter, 1, cInfo ) != 0)
               Messagebox('Custom Paper Form (' + cPaperName + ') Has Been Added! ',0+64,'Info')
            *?'Custom paper form (' + cPaperName + ') has been added! '
            Else
               Messagebox(GetLastError(),0+16,'Error')
            *? 'Error:', GetLastError()
            Endif

            LocalFree( pPaperName )
         Endif

      Else
         If (nResult == 122) && Insufficient buffer
            Messagebox('Custom Paper Form (' + cPaperName + ') Already Exist!',0+16,'Error')
            *? 'Error: Custom Paper Form already exist!'
         Else
            Messagebox(nResult,0+16,'Error')
            *? 'Error: ', nResult
         Endif
      Endif
   Else
      Messagebox(nResult,0+16,'Error')
      *? 'Error: ', nResult
   Endif
   ClosePrinter( hPrinter )
Endif
EndFunc

*-----------------------
Function FindPaperID
*-----------------------
Parameters lc_FindPaperName
*Fungsi untuk mencari PaperID
**SAME AS FUNCTION PRTINFO(2)

*Sample
*CustomPaper('1/2 PRODXW',21,29.7)
*MESSAGEBOX(FindPaperID('1/2 PRODXW')


#Define DC_PAPERS 2
#Define DC_PAPERS_Size 2
#Define DC_PAPERNAMES 16
#Define DC_PAPERNAMES_Size 64
Declare Long DeviceCapabilities In WinSpool.drv ;
   String cPrinterName, String cPort, Short nCapFlags, ;
   String @O_cBuffer, Long pDevMode

Local Array la_Printer[1]
Local ln_Row, ln_Result, ln_I, ln_Index
Local lc_PrinterName, lc_Buffer
Local lc_PaperSizeID, lc_PaperName,nPaperID
nPaperID=0

lc_PrinterName = Set( 'Printer', 2 ) && Get default windows printer
= Aprinters( la_Printer )
ln_Row = Ascan( la_Printer, lc_PrinterName, 1, 0, 0, 9 )
ln_Result = DeviceCapabilities( la_Printer[ ln_Row, 1 ], ;
   la_Printer[ ln_Row, 2 ], DC_PAPERNAMES, 0, 0 )
If (ln_Result > 0)
   ln_Index = -1
   * lc_FindPaperName = Upper( 'MyCustom - Half A4' )
   lc_Buffer = Replicate( Chr(0), ln_Result * DC_PAPERNAMES_Size )
   ln_Result = DeviceCapabilities( la_Printer[ ln_Row, 1 ], ;
      la_Printer[ ln_Row, 2 ], DC_PAPERNAMES, @lc_Buffer, 0 )
   For ln_I = 0 To ln_Result-1
      lc_PaperName = Upper( Substr( lc_Buffer, (ln_I * DC_PAPERNAMES_Size )+1, ;
         DC_PAPERNAMES_Size ))
      lc_PaperName = Substr(lc_PaperName,1,Len(lc_FindPaperName))

      If (Upper(lc_FindPaperName) $ Upper(lc_PaperName))
         ln_Index = ln_I
         Exit
      Endif
   Next
   * ? "Ok"
   If (ln_Index != -1)
   ** Paper Name found
   ** Get PaperSize ID
      ln_Result = DeviceCapabilities( la_Printer[ ln_Row, 1 ], ;
         la_Printer[ ln_Row, 2 ], DC_PAPERS, 0, 0 )

      If (ln_Result > 0)
         lc_Buffer = Replicate( Chr(0), ln_Result * DC_PAPERS_Size )
         ln_Result = DeviceCapabilities( la_Printer[ ln_Row, 1 ], ;
            la_Printer[ ln_Row, 2 ], DC_PAPERS, @lc_Buffer, 0 )
         lc_PaperSizeID = Substr( lc_Buffer, (ln_Index * DC_PAPERS_Size )+1, DC_PAPERS_Size )
         * ? 'PaperSize ID for "' + lc_FindPaperName + '" is', CToBin( lc_PaperSizeID, '2rs' )
         nPaperID = CToBin( lc_PaperSizeID, '2rs')
      Endif
   Endif
Endif
Return nPaperID
Endfunc

*-------------------------
Function FillPaperIDToFRX
*-------------------------
Parameters NameOfFrx
*Fungsi Untuk Insert Paper ID ke FRX secara otomatis
*Letakkan fungsi  FillPaperIDToFRX('namareport') sebelum Report Form...
Local OldArea,IdPaper,lnSettings,lnPapersizeLIne,lcExpr

OldArea = Select()
Select 88
Use "&NameOfFrx"
Locate For Objtype = 1 And Objcode = 53
Replace Tag With "",Tag2 With ""
IdPaper = FindPaperID(READINI("Custom Paper","Name","","INIFILE.INI"))
lnSettings = Alines( laSettings, Expr )
lnPapersizeLine = Ascan( laSettings, "PAPERSIZE",1,0,0,4)
laSettings( lnPapersizeLine ) = "PAPERSIZE = " + Transform( IdPaper )
lcExpr = ""
For lnSetting = 1 To lnSettings
   lcExpr = lcExpr + laSettings( lnSetting ) + Chr(13)
Endfor
Replace Expr With lcExpr
If Used("&NameOfFrx")
   Use In &NameOfFrx
Endif
Select(OldArea)
Return
Endfunc

Semoga bisa membantu.

Rgds
xWongso
« Last Edit: June 11, 2017, 07:55:10 AM by xWongso »

Offline agooze

  • Junior Member
  • *
  • Posts: 134
Re: Sharing Tentang Setting Customer Paper Size
« Reply #5 on: June 11, 2017, 09:52:07 AM »

*-------------------------
Function FillPaperIDToFRX
*-------------------------
Parameters NameOfFrx
*Fungsi Untuk Insert Paper ID ke FRX secara otomatis
*Letakkan fungsi  FillPaperIDToFRX('namareport') sebelum Report Form...
Local OldArea,IdPaper,lnSettings,lnPapersizeLIne,lcExpr

OldArea = Select()
Select 88
Use "&NameOfFrx"
Locate For Objtype = 1 And Objcode = 53
Replace Tag With "",Tag2 With ""
IdPaper = FindPaperID(READINI("Custom Paper","Name","","INIFILE.INI"))
lnSettings = Alines( laSettings, Expr )
lnPapersizeLine = Ascan( laSettings, "PAPERSIZE",1,0,0,4)
laSettings( lnPapersizeLine ) = "PAPERSIZE = " + Transform( IdPaper )
lcExpr = ""
For lnSetting = 1 To lnSettings
   lcExpr = lcExpr + laSettings( lnSetting ) + Chr(13)
Endfor
Replace Expr With lcExpr
If Used("&NameOfFrx")
   Use In &NameOfFrx
Endif
Select(OldArea)
Return
Endfunc

function READINI() belum disertakan ya?

Offline xWongso

  • Newbie
  • *
  • Posts: 8
Re: Sharing Tentang Setting Customer Paper Size
« Reply #6 on: June 11, 2017, 12:04:21 PM »
Pak Agooze...
Terlampir Fungsi Read And Write Ini File, semoga bermanfaat...

*----------------
Function ReadIni
*----------------
*READINI("Custom Paper","Name","","INIFILE.INI")
Parameters xsection,xentry,xdefault,xinifile
Local ret_value,filehandler
Declare Integer GetPrivateProfileString In Win32API  As GetPrivStr String, String, String, String @, Integer, String
If File(xinifile)
   filehandler = Fopen(xinifile,0)
Else
   xinifile = "C:\WINDOWS\"+xinifile
   If File(xinifile)
      filehandler = Fopen(xinifile,0)
   Else
      Return xdefault
   Endif
Endif
If filehandler < 0
   Messagebox("Failed To Access INI File....",0+16)
   = Fclose(filehandler)
   Return xdefault
Else
   = Fclose(filehandler)
Endif
ret_value = Space(1024)
=GetPrivStr(xsection,xentry,xdefault,@ret_value,Len(ret_value),xinifile)
Return Alltrim(Strtran(ret_value,Chr(0),""))
Endfunc

*-----------------
Function WriteIni
*------------------
*WRITEINI("Custom Paper","Name","CusPprName","INIFILE.INI")

Parameters xsection,xentry,xstring,xinifile
Local filehandler
Declare Integer WritePrivateProfileString In Win32API  As WritePrivStr String, String, String, String
If File(xinifile)
   filehandler = Fopen(xinifile,0)
Else
   xinifile = "C:\WINDOWS\"+xinifile
   If File(xinifile)
      filehandler = Fopen(xinifile,0)
   Else
      Return .F.
   Endif
Endif
If filehandler < 0
   Messagebox("Failed To Access INI File....",0+16)
   = Fclose(filehandler)
   Return .F.
Else
   = Fclose(filehandler)
Endif
=WritePrivStr(xsection,xentry,xstring,xinifile)
Return .T.
Endfunc

Rgds
XWongso

Offline agooze

  • Junior Member
  • *
  • Posts: 134
Re: Sharing Tentang Setting Customer Paper Size
« Reply #7 on: June 12, 2017, 03:50:48 PM »

 :thumbsup: :thumbsup: :thumbsup:

Offline yosef_fl

  • Full Member
  • *
  • Posts: 71
Re: Sharing Tentang Setting Customer Paper Size
« Reply #8 on: June 12, 2017, 08:12:07 PM »
wuihhh,ini bahasa tingkat tinggi....,mesti banyak belajar saya...

Thank's

Offline yosef_fl

  • Full Member
  • *
  • Posts: 71
Re: Sharing Tentang Setting Customer Paper Size
« Reply #9 on: June 14, 2017, 09:17:20 AM »
akhirnya sebagian  sudah terpecahkan rekan2x... terima kasih atas pencerahannya,tapi saya belum pakai report yang include,tapi  sudah otomatis setting kertas walaupun setting kertas di printer hilang...

Thank's
Yosef