有沒有辦法模糊文本(文本不是隨機文本,而是來自 db)添加showTextAligned(PdfContentByte.ALIGN_LEFT,"Random text",297,606,rotation)到PdfContentByte?或者任何其他模糊文本的方法(它可以是影像,但影像必須從輸入文本生成,而不是您添加到專案中的影像)并將其添加到 pdf 中?我正在使用itextpdf:5.5.12(在 android 上)
我想到的小例子:
PdfWriter pdfWriter=PdfWriter.getInstance(document, new FileOutputStream(file));
PdfContentByte cb = pdfWriter.getDirectContent();
cb.saveState();
cb.beginText();
cb.setColorFill(baseCol);
cb.setFontAndSize(myBaseFontArialNarrowBold,7);
//some function that blurs the text ??
//here
cb.showTextAligned(PdfContentByte.ALIGN_LEFT,"Random text that we want to blur",297,638,rotation);
cb.endText();
cb.restoreState();
//another option would be to add generated image from canvas
Bitmap btmp=bBlur.getBitmap();
ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
btmp.compress(Bitmap.CompressFormat.PNG, 100, stream2);
byte[] byteArray2 = stream2.toByteArray();
Image img2 = Image.getInstance(byteArray2);
cb.addImage(img,250,0,0,250,290,398);
在 android 中使用畫布(如果使用選項二):
//arial narrow bold
paint.setTypeface(typeface);
paint.setColor(Color.argb(190,0,0,0));
paint.setTextAlign(Paint.Align.LEFT);
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setSubpixelText(true);
paint.setLinearText(true);
//paint.setMaskFilter(new BlurMaskFilter(1, BlurMaskFilter.Blur.NORMAL));
paint.setTextSize(8);
canvas.rotate(-0.9876f);
canvas.drawText(textAr[0],6.8f,11.78f,paint);
paint.setTextSize(7);
canvas.drawText(textAr[1],6.8f,20,paint);
canvas.drawText(textAr[2],6.8f,45,paint);
canvas.setBitmap(bitmap);
第二個選項的唯一問題是,在畫布中生成的文本非常糟糕,而且在 pdf 中添加影像時看起來不太好......那么“壞字體”可能出在哪里?
非常感謝任何幫助或建議。
uj5u.com熱心網友回復:
解決方案: 使用第二個選項。增加位圖大小(設定 Bitmap.Config.ARGB_8888),將字體大小增加到大于 7 或 8 的大小,然后對其應用模糊(在我的情況下,我將字體大小增加到 24),將影像另存為位圖,然后添加影像到 PdfContentByte 或直接將影像添加到檔案(將 scaleAbsolute 應用于影像和 absolutePosition)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/365509.html
