0

我需要的是在我的应用程序中拍照并移动到PDF文档,到目前为止我可以做的是:拍照,将其保存在我的特定目录中但我无法将这些照片转换为PDF,但其他参数与你,如 textView、EditText ...我的问题是,如何将这些图像传输到 PDF?

这是我的 PDF 代码:

public void  gerarPDF(View view) {

    //Cria um documento para gerar o PDF
    PdfDocument documentoPDF = new PdfDocument();

    //Especifica detalhes da página
    PdfDocument.PageInfo detalhesDaPagina = new PdfDocument.PageInfo.Builder(500, 600, 1).create();

    //Cria primeira Pagina
    PdfDocument.Page novaPagina = documentoPDF.startPage(detalhesDaPagina);
    Canvas canvas = novaPagina.getCanvas();

    Paint corDoTexto = new Paint();
    corDoTexto.setColor(Color.BLACK);
    Paint foto = new Paint();

    canvas.drawText(textView6.getText().toString(), 50, 100, corDoTexto);

    canvas.drawText(textView.getText().toString(), 50, 130, corDoTexto);
    canvas.drawText(etCliente.getText().toString(), 105, 130, corDoTexto);

    canvas.drawText(textView2.getText().toString(), 50, 150, corDoTexto);
    canvas.drawText(etPostes.getText().toString(), 105, 150, corDoTexto);

    canvas.drawText(textView3.getText().toString(), 50, 170, corDoTexto);
    canvas.drawText(etObservacao.getText().toString(), 145, 170, corDoTexto);

    canvas.drawBitmap( bitmap, 0, 0, null );

    documentoPDF.finishPage(novaPagina);

    //SALVA RELATORIO EM PDF NO SDCARD
    SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyyhhmmss");
    String pdfName = "pdf"
            + sdf.format(Calendar.getInstance().getTime()) + ".pdf";
    String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/VIEW REPORT/Pdf";

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

    if( documentoPDF != null ){

        // write the document content
        try {
            OutputStream out = new FileOutputStream(pdffile);

            if( out != null ){
                documentoPDF.writeTo(out);

                // close the document
                documentoPDF.close();
                out.close();

                Toast.makeText(this, "PDF GERADO COM SUCESSO", Toast.LENGTH_LONG).show();
            }
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(this, "FALHA AO GERAR PDF: ", Toast.LENGTH_LONG).show();
        }
    }
}

如果有人在 iText 中有解决方案,那也会有很大帮助。

4

0 回答 0