2017-11-22 8 views
0

iTextG 라이브러리를 사용하여 pdf를 만들었습니다. 이제 이더넷을 통해 인쇄하고 싶습니다. 어떻게해야합니까? 다음 줄을 사용하면 기본 인쇄 서비스를 호출 할 수 있지만 프린터가 이더넷에 연결되어 있지는 않습니다. 내 PC에 드라이버를 설치 한 후 Google 클라우드 프린트 서비스를 사용하여 pdf를 인쇄 할 수 있습니다. 아무도 이것에 나를 도울 수 있습니까?인쇄는 PDF를 통해 iTextG를 사용하여 생성되었습니다. 프린터가 이더넷에 연결되어 있습니까?

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

을 나는 다음과 같은 프린터 사용하고 있습니다 :

https://www.amazon.in/Heyday-Thermal-Receipt-Printer-GP-U80300I/dp/B011BWM95E 다음과 같이 내가 전화

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); 
     } 

    } 
} 

그리고 위의 헬퍼 클래스를 사용 : 현재

나는 다음과 같은 코드를 사용하고

+1

iText에 관한 질문이 아닙니다. 태그가 삭제되었습니다. –

답변

0

기기가 p와 동일한 네트워크에 있어야합니다. 린터. 또한 사용하는 프린터가 Mopria-certified인지 확인해야합니다. "통합 인쇄 지원 전 세계에서 판매되는 프린터의 97 %를 차지하는 모든 Mopria 인증 프린터와 호환 가능합니다."