2017-11-22 10 views
0

iTextGライブラリを使ってpdfを作成しました。今はイーサネットで印刷したいと思います。私はこれをどのように達成すべきですか?次の行を使って、私はデフォルトのプリントサービスを呼び出すことができますが、イーサネットに接続されたプリンタは表示されません。私はPCにドライバをインストールした後、Googleクラウドプリントサービスを使ってpdfを印刷することができます。誰かが私にこれを助けることができますか?via iTextG経由でPDFを印刷します。プリンタはイーサネットに接続されていますか?

現在、私は次のコードを使用しています:

public class MyPrintHelper { 

    private Context context; 

    public MyPrintHelper(Context context) { 
     this.context = context; 
    } 

    public void print() { 
     PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE); 
     // Set job name, which will be displayed in the print queue 
     String jobName = context.getString(R.string.app_name) + " Document"; 
     // Start a print job, passing in a PrintDocumentAdapter implementation 
     // to handle the generation of a print document 
     printManager.print(jobName, new MyPrintDocumentAdapter(), null); 
    } 

    private class MyPrintDocumentAdapter extends PrintDocumentAdapter { 

     @Override 
     public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, WriteResultCallback callback) { 
      InputStream input = null; 
      OutputStream output = null; 

      try { 

       input = new FileInputStream(new File(context.getExternalCacheDir(), PDF_FILE_NAME)); 
       output = new FileOutputStream(destination.getFileDescriptor()); 

       byte[] buf = new byte[1024]; 
       int bytesRead; 

       while ((bytesRead = input.read(buf)) > 0) { 
        output.write(buf, 0, bytesRead); 
       } 

       callback.onWriteFinished(new PageRange[]{PageRange.ALL_PAGES}); 

      } catch (IOException e) { 
       e.printStackTrace(); 
      } finally { 
       try { 
        input.close(); 
        output.close(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
      } 
     } 

     @Override 
     public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras) { 

      if (cancellationSignal.isCanceled()) { 
       callback.onLayoutCancelled(); 
       return; 
      } 


      PrintDocumentInfo pdi = new PrintDocumentInfo.Builder("Name of file").setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT).build(); 

      callback.onLayoutFinished(pdi, true); 
     } 

    } 
} 

を上記のヘルパークラスを使用するために、次のように、私はそれを呼び出す:

MyPrintHelper helper = new MyPrintHelper(getActivity()); 
helper.print(); 

私は、次のプリンタを使用しています:

https://www.amazon.in/Heyday-Thermal-Receipt-Printer-GP-U80300I/dp/B011BWM95E

+1

あなたの質問はiTextに関するものではありません。タグが削除されました。 –

答えて

0

お使いのデバイスはpと同じネットワーク上にある必要がありますリンター。また、使用しているプリンタがMopria-certifiedであることを確認する必要があります。「統合印刷のサポート 世界中で販売されているプリンタの97%を構成するすべてのMopria認定プリンタと互換性があります。

関連する問題