2017-04-11 1 views
-4

테이블에 텍스트가있는 바코드 이미지가 포함 된 pdf 파일을 만들고 싶습니다. 이 형식으로 만들 수 없습니다.안드로이드에서 iText를 사용하여 여러 비트 맵 이미지를 텍스트와 함께 테이블에 추가하는 방법은 무엇입니까?

Required output should be like this

PdfPTable table = new PdfPTable(qrCodeModelArrayList.size()); 

    for (int i = 0; i < qrCodeModelArrayList.size(); i++) { 

     Bitmap bitmap = qrCodeModelArrayList.get(i).getQrBitMap(); 
     ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
     bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); //use the compression format of your need 
     InputStream is = new ByteArrayInputStream(stream.toByteArray()); 

     Bitmap bmp = BitmapFactory.decodeStream(is); 
     ByteArrayOutputStream stream1 = new ByteArrayOutputStream(); 
     bmp.compress(Bitmap.CompressFormat.PNG, 100, stream1); 
     Image bitmapImage = null; 
     try { 
      bitmapImage = Image.getInstance(stream1.toByteArray()); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

     PdfPCell cell = new PdfPCell(); 
     cell.addElement(bitmapImage); 
     Paragraph p = new Paragraph(qrCodeModelArrayList.get(i).getQrCodeName()); 
     p.setAlignment(Element.ALIGN_CENTER); 
     cell.addElement(p); 
     table.addCell(cell); 
    } 
아래 이 코드를 사용하는 경우

, 내가 가진 않았다 출력 :

enter image description here

내 바코드 이미지를 볼 수 없습니다이고 모든 열이 같은 행에 추가 . 5 열에 넣고 싶었어.

+0

코드를 알려주십시오. –

+0

이 질문은 [공식 FAQ] (http://developers.itextpdf.com/frequently-asked-developer-questions-7)에서 이미 답변되었습니다 : [동일한 셀에 이미지와 텍스트를 추가하는 방법] http://developers.itextpdf.com/content/best-itext-questions-stackoverview/tables/itext-how-add-image-and-text-same-cell) iText 5 답변이 필요한 경우 [이전 버전] (http://developers.itextpdf.com/question/how-add-image-and-text-same-cell). –

+0

@AmedeeVanGasse 내 코드를 확인하십시오. –

답변

1

BarcodeQRCode 클래스를 사용하여 수행해야하는 QRCode를 만들려고 실제 질문을 표시하도록 질문을 업데이트했습니다. 그런 다음 placeBarcode() 메소드를 사용하여 코드를 PDF에 추가해야합니다. Android에 AWT가 없으므로 createAwtImage() 메소드를 사용할 수 없습니다. 현재 사용중인 코드에는 이미지와 관련된 일부 문제가 있다고 생각합니다. QR 코드는 벡터 데이터로 구성되며 손실 JPEG 형식으로 변환합니다 (바코드 스캐너는 JPG를 읽는 데 문제가 있으므로 PNG를 사용해야합니다). 또한 바코드를 압축합니다. 벡터 형식이 될 수있는 이미지에는 의미가 없습니다.

placeBarcode() 메서드를 사용하면 QRCode가 벡터 이미지로 추가됩니다 (PDF 구문 사용). 래스터 이미지로 바코드를 추가하는 것보다 훨씬 낫습니다.