android - pdf android中图像上的多个超链接

标签 android pdf itext pdf-generation

我创建了一个使用(电话电子邮件链接)生成名片的应用

以两种格式保存它PDF(使用 LIB itextpdf)和图像

我在 PDF 中插入了相同的 Image

图像看起来像这样

enter image description here

现在的问题是

Numberemailwebsite 应该是可点击的

到目前为止我尝试了什么

我尝试使用 Hyperlink Rectangle 破解此功能

但是当我使用下面的代码添加 Rectangle 时

PdfContentByte canvas = writer.getDirectContent();
                Rectangle rect = new Rectangle(36, 636, 559, 10);
                rect.setBorder(Rectangle.BOX);
                rect.setBorderWidth(2);
                canvas.rectangle(rect);

但我无法将矩形放在正确的位置

X, Y, width AND height 没问题,但给出了这个输出

PDF 输出

enter image description here

我的问题是

  1. 是否可以破解此功能?
  2. 如何制作位置正确的可点击矩形?
  3. 您还有其他建议吗?

最佳答案

我解决了我的问题并回答了我自己的问题

解决了我的矩形位置

Rectangle phone = new Rectangle(36, 640,540,676);
Rectangle email = new Rectangle(36,604,540, 640);
Rectangle website = new Rectangle(36,568,540, 604);

使用以下代码链接矩形

                PdfReader reader = new PdfReader(file.getAbsolutePath() + File.separator + "card1_" + name.getText().toString() + ".pdf");
                PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(file.getAbsolutePath() + File.separator + "card1_Clickable_" + name.getText().toString() + ".pdf"));
                Rectangle phone = new Rectangle(36, 640,540,676);
                Rectangle email = new Rectangle(36,604,540, 640);
                Rectangle website = new Rectangle(36,568,540, 604);
                phone.setBorder(0);
                email.setBorder(0);
                website.setBorder(0);

                PdfAnnotation link = PdfAnnotation.createLink(stamper.getWriter(),
                        phone, PdfAnnotation.HIGHLIGHT_INVERT,new PdfAction("tel://"+phone_edit.getText().toString()));
                link.setBorder(new PdfBorderArray(0, 0, 0));

                PdfAnnotation link1 = PdfAnnotation.createLink(stamper.getWriter(),
                        email, PdfAnnotation.HIGHLIGHT_INVERT,new PdfAction("mailto:"+email_edit.getText().toString()));
                link1.setBorder(new PdfBorderArray(0, 0, 0));

                PdfAnnotation link2 = PdfAnnotation.createLink(stamper.getWriter(),
                        website, PdfAnnotation.HIGHLIGHT_INVERT,new PdfAction(website_edit.getText().toString()));
                link2.setBorder(new PdfBorderArray(0, 0, 0));

                stamper.addAnnotation(link,1);
                stamper.addAnnotation(link1,1);
                stamper.addAnnotation(link2,1);
                stamper.close();

现在我可以点击图片上的每个链接

关于android - pdf android中图像上的多个超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44394986/

相关文章:

Android 在 Java 中设置(获取)环境变量

android - 为什么我的 Android 应用程序因某个特定库的 NoClassDefFoundError 而崩溃?

android - Android(在 ARM 上)是否有硬件性能计数器?

java - PDF 页面大小与提供的页面大小不准确

c# - ItextSharp Font.BaseFont 为某些字体返回 Null

java - iText 设置加密错误

android - 如何上传 mapping.txt 到 PlayStore

c# - C#.NET 中 iTextSharp 中的自定义页面大小

windows - 使用命令行打印特定的 PDF 页面

php - Tcpdf 自动设置每张