Itextpdf模糊了pdf中的文本



有没有办法模糊添加了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格式添加时,它看起来不太好。。。那么";字体不好"?

非常感谢任何帮助或建议。

解决方案:使用第二个选项。增加位图大小(设置bitmap.Config.ARGB_8888(,将字体大小增加到大于7或8的大小,然后对其应用模糊(在我的情况下,我将字体大小提高到24(,将图像另存为位图,然后将图像添加到PdfContentByte,或将图像直接添加到文档(将scaleAbsolute应用到图像和absolutePosition(。

最新更新