有没有一种方法可以使模糊文本(文本不是随机文本,但它来自db),并添加showTextAligned(PdfContentByte.ALIGN_LEFT,"Random text",297,606,rotation)到PdfContentByte?或者任何其他模糊文本的方法(可以是图像,但图像必须从输入文本生成,而不是添加到项目中的图像)并将其添加到pdf中?我正在使用itextpdf:5.5.12 (在安卓上)
我想举个小例子:
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中添加图像时看起来不太好.那么“坏字体”在哪里会有问题呢?
任何帮助或建议都是非常感谢的。
发布于 2021-11-17 12:33:37
解决方案:提供第二个选项。增加位图大小(设置Bitmap.Config.ARGB_8888),将字体大小增加到比大小7或8更大的地方,然后对其应用模糊(在我的例子中,我将字体大小增加到24),将图像保存为位图,然后将图像添加到PdfContentByte或将图像直接添加到文档(将scaleAbsolute应用于图像和absolutePosition)。
https://stackoverflow.com/questions/69996055
复制相似问题