Differenze tra le versioni di "Stampare un file con le funzioni del API di cups"
Da Gambas-it.org - Wikipedia.
Riga 19: | Riga 19: | ||
'''Public''' Sub Main() | '''Public''' Sub Main() | ||
− | Dim | + | Dim stamp_Def, predef As String |
Dim num_dests, err As Integer | Dim num_dests, err As Integer | ||
Dim p, pstmp As Pointer | Dim p, pstmp As Pointer | ||
Dim st As Stream | Dim st As Stream | ||
− | Dim b As Byte | + | Dim b, j As Byte |
Riga 39: | Riga 39: | ||
Seek #st, b * 32 | Seek #st, b * 32 | ||
Read #st, pstmp | Read #st, pstmp | ||
+ | Seek #st, Seek(st) + 8 | ||
+ | Read #st, j | ||
+ | If j = 1 Then | ||
+ | stamp_Def = String@(pstmp) | ||
+ | predef = " - Default\n" | ||
+ | Endif | ||
<FONT color=gray>' ''Mostriamo in console il nome delle stampanti trovate installate nel sistema:''</font> | <FONT color=gray>' ''Mostriamo in console il nome delle stampanti trovate installate nel sistema:''</font> | ||
− | Print b, String@(pstmp) | + | Print b + 1, String@(pstmp) & predef |
− | |||
− | |||
Next | Next | ||
+ | |||
+ | <FONT color=gray>' ''In questo esempio passiamo alla funzione "cupsPrintFile()" il nome della stampante 'predefinita' trovata:''</font> | ||
+ | Print "Stampa sulla stampante: "; stamp_Def | ||
st.Close() | st.Close() | ||
− | err = cupsPrintFile( | + | err = cupsPrintFile(stamp_Def, "<FONT color=gray>''/percorso/del/file/da/stampare/''</font>", "Breve titolo qualsiasi", 0, Null) |
If err = 0 then Error.Raise("Stampa del file fallita !") | If err = 0 then Error.Raise("Stampa del file fallita !") | ||
Versione delle 12:17, 11 nov 2014
Per stampare un file con le funzioni esterne del API di CUPS (Common Unix Printing System), e dunque senza l'uso della Classe Printer, bisognerà richiamare l'attuale libreria esterna: libcups.so.2 .
Mostriamo di seguito un semplice e breve codice per stampare un solo file:
Public Struct Cups_option_s ' Opzioni di stampa name As Pointer ' Nome dell'opzione value As Pointer ' Valore dell'opzione End Struct Library "libcups:2" ' int cupsGetDests(cups_dest_t **dests) Private Extern cupsGetDests(dests As Pointer) As Integer ' int cupsPrintFile(const char *printer, const char *filename, const char *title, int num_options, cups_option_t *options) Private Extern cupsPrintFile(stampante As String, nomefile As String, titolo As String, num_opzioni As Integer, opzioni As Cups_option_s) As Integer Public Sub Main() Dim stamp_Def, predef As String Dim num_dests, err As Integer Dim p, pstmp As Pointer Dim st As Stream Dim b, j As Byte num_dests = cupsGetDests(VarPtr(p)) Print "Sono state riscontrate installate nel sistema num. "; num_dests; " stampanti:\n" ' Dereferenziando la variabile di tipo "Puntatore" si ottengono i nomi delle stampanti installate. ' In particolare ciascun nome è uguale a quello del file .ppd afferente alla stampante installata, ' presente nella cartella "/etc/cups/ppd" e privo della sua estensione. ' Il nome della stampante andrà passato, come primo argomento, alla funzione "cupsPrintFile()". st = Memory p For Read For b = 0 To num_dests - 1 Seek #st, b * 32 Read #st, pstmp Seek #st, Seek(st) + 8 Read #st, j If j = 1 Then stamp_Def = String@(pstmp) predef = " - Default\n" Endif ' Mostriamo in console il nome delle stampanti trovate installate nel sistema: Print b + 1, String@(pstmp) & predef Next ' In questo esempio passiamo alla funzione "cupsPrintFile()" il nome della stampante 'predefinita' trovata: Print "Stampa sulla stampante: "; stamp_Def st.Close() err = cupsPrintFile(stamp_Def, "/percorso/del/file/da/stampare/", "Breve titolo qualsiasi", 0, Null) If err = 0 then Error.Raise("Stampa del file fallita !") End