2012-09-04 68 views
-2

android中的iTextPDF在我不想要的PDF圖像中設置邊框。如何解決這個問題。 注: - 我搜索了很多的解決方案,我找不到任何。Android ItextPDF ...圖像不需要的邊框

com.itextpdf.text.Document pdfDocument = new com.itextpdf.text.Document(); 
    pdfDocument.setPageSize(PageSize.A4); 
    pdfDocument.setMargins(72f,72f,72f,72f);                   

    File extStore   = Environment.getExternalStorageDirectory(); 

    try { 
     PdfWriter.getInstance(pdfDocument,new FileOutputStream(extStore.getAbsolutePath()+"/MyNewPDF.pdf")); 
    } catch (FileNotFoundException e1) { 
     e1.printStackTrace(); 
    } catch (DocumentException e1) { 
     e1.printStackTrace(); 
    } 

    pdfDocument.open(); 

    BaseColor colorBlack = new BaseColor(0, 0, 0);                

    /*Setting the Image Header*/ 
    Drawable myImage    =  getResources().getDrawable(R.drawable.pdf_logo); 
    Bitmap bitmap     =  ((BitmapDrawable)myImage).getBitmap(); 
    ByteArrayOutputStream stream =  new ByteArrayOutputStream(); 
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); 
    byte[] bitmapdata = stream.toByteArray(); 

    Image imageHeader = null; 

    try { 
     imageHeader = Image.getInstance(bitmapdata); 
    } catch (BadElementException e1) { 
     e1.printStackTrace(); 
    } catch (MalformedURLException e1) { 
     e1.printStackTrace(); 
    } catch (IOException e1) { 
     e1.printStackTrace(); 
    } 

    imageHeader.setAlignment(Element.ALIGN_RIGHT);                 
    Font font = new Font(Font.FontFamily.UNDEFINED,15,Font.ITALIC); 
    try { 
     pdfDocument.add(imageHeader); 
     pdfDocument.add(Chunk.NEWLINE); 
     /*Setting the heading line*/ 
     pdfDocument.add(new Paragraph("Document Name: Qwert Document ID: Dgj",font)); 
    } catch (DocumentException e1) { 
     e1.printStackTrace(); 
    } 


    /*Black Line*/ 
    Chunk linebreak   = new Chunk(new LineSeparator(1f, 100f, colorBlack, Element.ALIGN_CENTER, -1)); 
    try { 
     pdfDocument.add(linebreak); 
     pdfDocument.add(Chunk.NEWLINE); 
     pdfDocument.add(Chunk.NEWLINE); 
     pdfDocument.add(Chunk.NEWLINE); 
     pdfDocument.add(Chunk.NEWLINE); 
    } catch (DocumentException e) { 
     e.printStackTrace(); 
    } 

    /*Main Image*/ 
    Bitmap bitMap     = mBitmapArray.get(mPager.getCurrentItem()).mBitmap; 
    ByteArrayOutputStream streamNew = new ByteArrayOutputStream(); 
    bitMap.compress(Bitmap.CompressFormat.PNG, 100, streamNew); 
    byte[] byteArray = streamNew.toByteArray(); 

    Image imageMain = null; 
    try { 
     imageMain = Image.getInstance(byteArray); 
    } catch (BadElementException e) { 
     e.printStackTrace(); 
    } catch (MalformedURLException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    imageMain.setAlignment(Element.ALIGN_CENTER); 
    try { 
     pdfDocument.add(imageMain); 
     pdfDocument.add(Chunk.NEWLINE); 
     pdfDocument.add(Chunk.NEWLINE); 
     pdfDocument.add(Chunk.NEWLINE); 
    } catch (DocumentException e) { 
    } 


    Chunk linebreak2  = new Chunk(new LineSeparator(2f, 100f, colorBlack, Element.ALIGN_CENTER, -1)); 
    try { 
     /*Black Line*/ 
     pdfDocument.add(linebreak2); 
     /*Last Line*/ 
     pdfDocument.add(new Paragraph("Sent by Traveler ID")); 
    } catch (DocumentException e) { 
     e.printStackTrace(); 
    } 
    pdfDocument.close(); 

請多關照

+0

粘貼一些代碼 – Aamirkhan

回答

0

我用另一個庫解決了這個問題。