2017-03-24 4 views
1

이 라이브러리에 몇 가지 문제가 있습니다. roboto 및 arial ttf로 시도했지만 작동하지 않습니다. Sigma를 작성하려고합니다. Σ 기호 PDF와 그것이 exeption로 끝나는, 글꼴 등 내가 테스트 한PDFbox이 글꼴 유형은 8 비트 코드 포인트 만 지원합니다

public void drawTable(PDPage page, PDPageContentStream contentStream, 
         float y, float margin, 
         String[][] content) throws IOException { 
    final int rows = content.length; 
    final int cols = content[0].length; 
    final float rowHeight = 20f; 
    final float tableWidth = page.getBBox().getWidth()-(2*margin); 
    final float tableHeight = rowHeight * rows; 
    final float colWidth = tableWidth/(float)cols; 
    final float cellMargin=5f; 

    //draw the rows 
    float nexty = y ; 
    for (int i = 0; i <= rows; i++) { 
     contentStream.drawLine(margin,nexty,margin+tableWidth,nexty); 
     nexty-= rowHeight; 
    } 

    //draw the columns 
    float nextx = margin; 
    for (int i = 0; i <= cols; i++) { 
     contentStream.drawLine(nextx,y,nextx,y-tableHeight); 
     nextx += colWidth; 
    } 


    //now add the text 
    contentStream.setFont(PDType1Font.COURIER,12); 
    PDTrueTypeFont robotoRegular = PDTrueTypeFont.loadTTF(document, getActivity().getAssets().open("arial.ttf")); 
    robotoRegular.encode("WinAnsiEncoding"); 
    PDTrueTypeFont robotBold = PDTrueTypeFont.loadTTF(document, getActivity().getAssets().open("ariblk.ttf")); 
    robotBold.encode("WinAnsiEncoding"); 
    float textx = margin+cellMargin; 
    float texty = y-15; 
    for(int i = 0; i < content.length; i++){ 
     for(int j = 0 ; j < content[i].length; j++){ 
      String text = content[i][j]; 
      contentStream.beginText(); 
      if (j==0){ 
       contentStream.setFont(robotBold,12); 
      }else { 
       contentStream.setFont(robotoRegular,12); 
      } 
//    byte[] commands = "Σ".getBytes(); 
//    commands[1] = (byte) 128; 
//    contentStream.appendRawCommands(commands); 
      contentStream.moveTextPositionByAmount(textx,texty); 
      contentStream.drawString(text); 
      contentStream.endText(); 
      textx += colWidth; 
     } 
     texty-=rowHeight; 
     textx = margin+cellMargin; 
    } 
} 
+1

PDFBox 1.8을 기반으로 한 android 용 PDFBox와 함께 사용할 수 있을지 의심 스럽습니다. PDType1Font.SYMBOL을 사용해 보시고 자신을 인코딩 할 수 있습니다. 시그마에 대한 8 진수 코드는 16 진수 53입니다 (PDF 사양 부록 A 참조). 나는. Tj와 \ n을 원시 명령으로 사용하십시오. 'robotoRegular.encode ("WinAnsiEncoding");'행은 무의미하며, 필요하지 않습니다. 또는 서버에서 PDF를 작성하고 2. * 버전을 사용하십시오. –

+0

안드로이드 용 PDFBox가 2.0 개념을 사용하고있는 것으로 보입니다. 하단의 https://github.com/TomRoush/PdfBox-Android/issues/100을 참조하십시오. 작동하는 경우 질문에 직접 답변하십시오. –

답변

1

사전에 감사하고, 사용 LiberationSans을 나는이를 인코딩해야하는 경우 알아야 할, 그리고 어떻게 그것을 할 수있는 것 시그마 기호를 인코딩 할 수 있습니다.

PDFont liberationSans = PDType0Font.load(document, getActivity().getAssets().open("com/tom_roush/pdfbox/resources/ttf/LiberationSans-Regular.ttf"));은 글꼴을로드 한 다음 평소대로 drawString을 사용할 수 있습니다.

+0

저에게 잘 부탁드립니다. –