2017-02-10 52 views
10

Android.graphics.pdf kullanarak PDF oluşturmaya çalışıyorum. Sorunum, birden çok sayfa ile. Daha sonra bir PDF'ye basılabilen android.graphics.pdf html verebiliyorum. Artık metin, ayarlanan sayfa boyutunu aşarsa bu işe yaramaz. Tüm html vermek mümkün mü ve sayfa büyüklüğüne göre içeriğe göre birden çok sayfa oluşturur? TCPDF gibiandroid.graphics.pdf kullanarak PDF'in birden çok sayfasını oluşturma

Not. İçeriğin yüksekliğini hesaplayarak ayrı birden çok sayfa oluşturmamaya çalışıyorum. Bunun için

+0

hey sen cevap http://stackoverflow.com/a/36349822 alacak olabilir bu bağlantıyı deneyin/2888952 – Arpan24x7

+0

İçerik taşdığında bir hata oluştu mu? – Michael

cevap

0

projenize arasında iTextG kavanoz eklemeniz gerekir:

public void createandDisplayPdf(String text) { 

    Document doc = new Document(); 

    try { 
     String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Dir"; 

     File dir = new File(path); 
     if(!dir.exists()) 
      dir.mkdirs(); 

     File file = new File(dir, "newFile.pdf"); 
     FileOutputStream fOut = new FileOutputStream(file); 

     PdfWriter.getInstance(doc, fOut); 

     //open the document 
     doc.open(); 

     Paragraph p1 = new Paragraph(text); 
     Font paraFont= new Font(Font.COURIER); 
     p1.setAlignment(Paragraph.ALIGN_CENTER); 
     p1.setFont(paraFont); 

     //add paragraph to document 
     doc.add(p1);  

    } catch (DocumentException de) { 
     Log.e("PDFCreator", "DocumentException:" + de); 
    } catch (IOException e) { 
     Log.e("PDFCreator", "ioException:" + e); 
    } 
    finally { 
     doc.close(); 
    } 

    viewPdf("newFile.pdf", "Dir"); 
} 

// Method for opening a pdf file 
private void viewPdf(String file, String directory) { 

    File pdfFile = new File(Environment.getExternalStorageDirectory() + "/" + directory + "/" + file); 
    Uri path = Uri.fromFile(pdfFile); 

    // Setting the intent for pdf reader 
    Intent pdfIntent = new Intent(Intent.ACTION_VIEW); 
    pdfIntent.setDataAndType(path, "application/pdf"); 
    pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

    try { 
     startActivity(pdfIntent); 
    } catch (ActivityNotFoundException e) { 
     Toast.makeText(TableActivity.this, "Can't read pdf file", Toast.LENGTH_SHORT).show(); 
    } 
}