Base64编码图像似乎在字符串上截断

时间:2018-07-23 20:10:21

标签: java android image base64

我在使用Base64编码png图像然后与HTML字符串连接时遇到问题。

当我将编码的图像打印到AS的日志中时,我会完美地获得所有字符串,但是如果我像下面这样连接(htmlToPDF变量),则我在Log中看不到所有字符串。似乎是截断的。我不知道发生了什么。

public  void gerarPDFOnClick()
    {

        Document document = new Document(PageSize.LETTER);
        String NOME_ARQUIVO = "MeuArquivoPDF.pdf";
        String pastaArmazenamento = Environment.getExternalStorageDirectory().toString();



        File pdfDir = new File(pastaArmazenamento + File.separator + NOME_PASTA);



        if(!pdfDir.exists())
        {
            pdfDir.mkdir();
        }

        File pdfSubDir = new File(pdfDir.getPath() + File.separator + GERADOS);

        if(!pdfSubDir.exists())
        {
            pdfSubDir.mkdir();
        }

        String nomeCompleto = Environment.getExternalStorageDirectory() + File.separator + NOME_PASTA + File.separator + GERADOS
                + File.separator + NOME_ARQUIVO;

        File outputFile = new File(nomeCompleto);

        if(outputFile.exists())
        {
           outputFile.delete();
        }

        try {
            PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(nomeCompleto));
            /*Criar o ducumento para escreve-lo */
            document.open();
            document.addAuthor("Felipe Cardim");
            document.addCreator("Criador");
            document.addSubject("Obrigado por ajudar");
            document.addCreationDate();
            document.addTitle("Titulo uhuuuuu");



            XMLWorkerHelper workerHelper = XMLWorkerHelper.getInstance();

            bitmap.compress(Bitmap.CompressFormat.PNG,100,baos);
            byte[] b = baos.toByteArray();

            String encodeImage = Base64.encodeToString(b,Base64.DEFAULT);
            String htmlToPDF = "<html>" +
                    "<head></head>" +
                    "<body>" +
                    "<h1>Aeeeeee</h1>" +
                    "<a href='https://www.facebook.com/profile.php?id=736342513'>Facebook</a>" +
                    "<p>huhuhuhuhuhuh</p>" +
                    "<img src=\"data:image/png;base64," + encodeImage + "\"" +
                    " height='42' width='42'/>" +
                    "</body>" +
                    "</html>";

            Log.i("encode",encodeImage);
            Log.i("HTMLTOPDF",htmlToPDF);
            try {
                workerHelper.parseXHtml(pdfWriter,document, new StringReader(htmlToPDF));
                document.close();
                Toast.makeText(this, "PDF esta criado!!",Toast.LENGTH_LONG).show();
                mostraPDF(nomeCompleto, this);

            } catch (IOException e) {
                e.printStackTrace();
            }


        }catch (DocumentException e){
            e.printStackTrace();
        }catch (FileNotFoundException e){
            e.printStackTrace();
        }

    }

这是“编码”的日志视图:

07-23 18:07:45.196 11455-11455/exportapdf.studio.com.exportapdf I/encode: iVBORw0KGgoAAAANSUhEUgAAAHgAAAB4CAYAAAA5ZDbSAAAABHNCSVQICAgIfAhkiAAAIABJREFU
    eJzsvdmPJEly5vkztdv8do8z78qs6mvYB8nhzHAwwM4C87TAYv8l/knzuI+7WC7BIXuqSVYf1XXk
    nXF4+G1ut6nqPqi6RWR2kWySfZDAWsGQEVER7m4mKqIi3/eJmKO11vwbPbTW3ZmWGfsyIy1z0nJP
    XuXkdU7dtkglkVK+97euELiuiytcemFCEiYkQcIo7jOIevSjBFe4OI7Tnf8WD/H7/gD///HbPZx/
    rR5cNTV121C3DUVdUDYVZVOhtTYehYNwHBxHIByHqq0pm4qqqSmb0vzbViilUEoZT7/z+sJ6pRCC
    0AsI/ZDQC4iDiNAPiLwQAKUVittIoYHID4n8kDgICf2QwPMJPB/h/OvzF+/3/QH+vqNuG/Zlxr7M
    We3XrPMdm2xrDWyM6rsenuvhuS5aKaQ2xmxlS6skrZLw9yxf1X2laWVL1VR4wmMnXIQQCCGQUtKo
    llZKs1C0QmnNuDdknAyZ9EaMkgH9qIfvevCvMIr/qzVw1dbsij2LdM2b5Tsu1tdcrK+RSuEKF9cR
    REFI6AeEfkAgPDzh4glh90tzCuEiHIFwxHv7qFTSGkyB1piVoGmUpFWKVkkbEUxUaGWLtIvofHzK
    vYk5tdZ2H49/T3fqHz5+7wbelzlZlZOVObVskFIilaRsSsqmpmpMmPVcj16YkNUlVVtTNQ0q39mw
    qXEBFwfXgVtXuhPGcd7zMGVDrtKKWzfXSA0SbT3c6baD0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TLvn5uy/4
    H1/+T46HRzw5ecRHJ4/Y7Ja8un7NX/7irzidnfP0/sc8PXtCrRT7qmB

这是“ HTMLTOPDF”的日志视图:

07-23 18:07:45.196 11455-11455/exportapdf.studio.com.exportapdf I/HTMLTOPDF: <html><head></head><body><h1>Test</h1><a href='https://www.facebook.com/profile.php?id=736342513'>Facebook</a><p>huhuhuhuhuhuh</p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAB4CAYAAAA5ZDbSAAAABHNCSVQICAgIfAhkiAAAIABJREFU
    eJzsvdmPJEly5vkztdv8do8z78qs6mvYB8nhzHAwwM4C87TAYv8l/knzuI+7WC7BIXuqSVYf1XXk
    nXF4+G1ut6nqPqi6RWR2kWySfZDAWsGQEVER7m4mKqIi3/eJmKO11vwbPbTW3ZmWGfsyIy1z0nJP
    XuXkdU7dtkglkVK+97euELiuiytcemFCEiYkQcIo7jOIevSjBFe4OI7Tnf8WD/H7/gD///HbPZx/
    rR5cNTV121C3DUVdUDYVZVOhtTYehYNwHBxHIByHqq0pm4qqqSmb0vzbViilUEoZT7/z+sJ6pRCC
    0AsI/ZDQC4iDiNAPiLwQAKUVittIoYHID4n8kDgICf2QwPMJPB/h/OvzF+/3/QH+vqNuG/Zlxr7M
    We3XrPMdm2xrDWyM6rsenuvhuS5aKaQ2xmxlS6skrZLw9yxf1X2laWVL1VR4wmMnXIQQCCGQUtKo
    llZKs1C0QmnNuDdknAyZ9EaMkgH9qIfvevCvMIr/qzVw1dbsij2LdM2b5Tsu1tdcrK+RSuEKF9cR
    REFI6AeEfkAgPDzh4glh90tzCuEiHIFwxHv7qFTSGkyB1piVoGmUpFWKVkkbEUxUaGWLtIvofHzK
    vYk5tdZ2H49/T3fqHz5+7wbelzlZlZOVObVskFIilaRsSsqmpmpMmPVcj16YkNUlVVtTNQ0q39mw
    qXEBFwfXgVtXuhPGcd7zMGVDrtKKWzfXSA0SbT3c6baD0PcJvIDEiwg8H9BUTcUiXZGWey43c3zX
    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+NjzuyNmPRNnTxJhox7QxxAWmJhX+U0siKrCuq2MUiU
    Z2pXpyMZXKTWlHWNiFwC1xANrhC3RITn47oeriNQSjIMEx6Mjnm5uuLt9oa3mzmbbEeuNW1bo3HA
    dQGPQrassi1VU7Per4n9kDiIeHJ0j4ezM+5PTwGHq+0Nr5eXPDt9xMenTxgm/X/dBp7vlvzs7Rf8
    xRef8nB6ynfOP+KjowfMdysu1nP+4otP2Zf57R9YUAEvACUNWKFaAtdlECWM+2M+Pn3E98+f8f3z
    Z/TC2ODLQpgkpT9i3B8hlTQoWFNTNBW1bNgVe5SSCBxiP7rldR1whYtUirwuCYPQQKGRqVd918P3
    fMIgIvADAtdnmgxQxw9QSvLZxdd8dvmcBoVSEikbitJGH9cD1yNrW7JqDe38/Rv0nX/Po9k5Hx0/
    4O3qmq/nb/j88jlpmZGEMU+O74P/mwvYvxEDr/Yb1vsNq2zD29UFoHkwPcN1HN4tL1nvlrxeXaOU
    5MHsnLwuaaVheyrZUklJpVp84RnazvU4Hx9zNj7ibHzMJycPeTA942g0JfRDuz0bqq+sK1bpxoAV
    TUPd1mRVjlQK3/Nw8PGE2Y/RoDDUYWvDeKskrk1wtFa3mbnrd5BpP+qhdAQWv74/3ZO3NVprBl7I
    VZAQuj77uqS21+O7rr0W10CuQpjcQLhcLC/5y89/bOp7KXkwPSP0PObbBZ+++IzT0THT/phJ718e
    rn8jBl7vN3x9/ZKvr19SNjUAD2fn3GxuuFhestjcUCuFcl0ezM4p25qyaaiamm2Rsisy6qIi9EIG
    UcIw7vNwesbj2TmPZ+c8O35kDDycddi01ppGtpRNxb7MLHdcU8uG1hIWvkWzfGswpRRSSbO46pJa
    1pRNAY5GaYlULZEf4ruG3/VcFyFc+nHPJ

0 个答案:

没有答案