首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Itextpdf模糊pdf文本

Itextpdf模糊pdf文本
EN

Stack Overflow用户
提问于 2021-11-16 21:09:10
回答 1查看 177关注 0票数 0

有没有一种方法可以使模糊文本(文本不是随机文本,但它来自db),并添加showTextAligned(PdfContentByte.ALIGN_LEFT,"Random text",297,606,rotation)PdfContentByte?或者任何其他模糊文本的方法(可以是图像,但图像必须从输入文本生成,而不是添加到项目中的图像)并将其添加到pdf中?我正在使用itextpdf:5.5.12 (在安卓上)

我想举个小例子:

代码语言:javascript
复制
    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中使用画布(如果使用选项二):

代码语言:javascript
复制
//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中添加图像时看起来不太好.那么“坏字体”在哪里会有问题呢?

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-17 12:33:37

解决方案:提供第二个选项。增加位图大小(设置Bitmap.Config.ARGB_8888),将字体大小增加到比大小7或8更大的地方,然后对其应用模糊(在我的例子中,我将字体大小增加到24),将图像保存为位图,然后将图像添加到PdfContentByte或将图像直接添加到文档(将scaleAbsolute应用于图像和absolutePosition)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69996055

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档