禁用com.itextpdf.text.Paragraph的链接

问题描述 投票:0回答:1

问题如下,我有一种创建pdf的方法,但是当我添加包含链接的文本并创建pdf文件时,它允许我单击链接,出于安全考虑,它不能具有链接。

PdfReader reader = new PdfReader(new FileInputStream(new File("D:\\ruta\\\\basepdf.pdf"))); 
Document document = new Document(reader.getPageSize(1),0,0,0,0);

BaseFont base =BaseFont.createFont("D:\\ruta\\fuente.ttf", BaseFont.CP1250, BaseFont.EMBEDDED);
Font fonts = new Font(base, Float.parseFloat("40"),Font.BOLD, new BaseColor(255,0,0));

Paragraph parrafo= new Paragraph("https://www.youtube.com/", fonts);
Image imagen = Image.getInstance("D:\\ruta\\usuariosfondo.jpg");  

String base64Data = base64.substring(base64.indexOf(',') + 1);
byte[] decoded = Base64.decodeBase64(base64Data.getBytes());

Image imgQr = Image.getInstance(decoded);    

ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer=PdfWriter.getInstance(document, baos);

document.open();
document.newPage();

parrafo.setAlignment(Element.ALIGN_RIGHT);
parrafo.setFont(fonts);

ColumnText ct = new ColumnText(writer.getDirectContent());
ct.setSimpleColumn(0,0,550,780);
ct.setAlignment(Element.ALIGN_RIGHT);
ct.addElement(parrafo); 
ct.go();

Float width = document.getPageSize().getWidth();    
Float height = document.getPageSize().getHeight();
imagen.scaleToFit(width, height);
imagen.setAbsolutePosition(0f, 0f);
imgQr.setAbsolutePosition(149f, 209f);
imgQr.scaleToFit(178.2992f, 178.2992f);
document.add(imagen);
document.add(imgQr);
//document.add(parrafo);    

document.close();   
String p=java.util.Base64.getEncoder().encodeToString(baos.toByteArray());

文本应仅带有未显示为无法启动url的文本链接

java java-ee hyperlink itext wildfly
1个回答
0
投票

您的代码创建的pdf不包含链接注释。因此,您不要使其可点击。

但是它包含URL!某些pdf查看器,尤其是Adobe Reader,会自动使它们识别为可点击的任何网址。

如果使用Adobe Reader,则可以在设置中禁用此“功能”。

如果您无法控制查看器的设置,只需不要将URL放入pdf文件即可。或者阻止观看者轻松识别它们,例如通过将URL呈现为位图图像并使用这些图像代替相应的url文本。

© www.soinside.com 2019 - 2024. All rights reserved.