| from spire.pdf.common import * from spire.pdf import *   # 创建PDF文档 pdf = PdfDocument()   # 添加页面 page = pdf.Pages.Add()   # 设置初始X和Y坐标 y = 30.0 x = 10.0   # 创建PDF字体 font = PdfTrueTypeFont("宋体", 14.0, PdfFontStyle.Regular, True) font1 = PdfTrueTypeFont("宋体", 14.0, PdfFontStyle.Underline, True)   # 添加简单文本链接 label = "简单链接: " format = PdfStringFormat() format.MeasureTrailingSpaces = True page.Canvas.DrawString(label, font, PdfBrushes.get_Black(), 0.0, y, format) x = font.MeasureString(label, format).Width url = "https://www.e-iceblue.cn" page.Canvas.DrawString(url, font1, PdfBrushes.get_Blue(), x, y) y = y + 28   # 添加超文本链接 label = "超文本链接:" page.Canvas.DrawString(label, font, PdfBrushes.get_Black(), 0.0, y, format) x = font.MeasureString(label, format).Width webLink = PdfTextWebLink() webLink.Text = "主页" webLink.Url = url webLink.Font = font1 webLink.Brush = PdfBrushes.get_Blue() webLink.DrawTextWebLink(page.Canvas, PointF(x, y)) y = y + 28   # 添加邮件链接 label = "邮件链接: " page.Canvas.DrawString(label, font, PdfBrushes.get_Black(), 0.0, y, format) x = font.MeasureString(label, format).Width link = PdfTextWebLink() link.Text = "联系我们" link.Url = "mailto:support @e-iceblue.com" link.Font = font1 link.Brush = PdfBrushes.get_Blue() link.DrawTextWebLink(page.Canvas, PointF(x, y)) y = y + 28   # 添加文档链接 label = "文档链接: " page.Canvas.DrawString(label, font, PdfBrushes.get_Black(), 0.0, y, format) x = font.MeasureString(label, format).Width text = "点击打开文件" location = PointF(x, y) size = font1.MeasureString(text) linkBounds = RectangleF(location, size) fileLink = PdfFileLinkAnnotation(linkBounds, "C:\\Users\\Administrator\\Desktop\\排名.xlsx") fileLink.Border = PdfAnnotationBorder(0.0) page.AnnotationsWidget.Add(fileLink) page.Canvas.DrawString(text, font1, PdfBrushes.get_Blue(), x, y)   # 保存PDF文档 pdf.SaveToFile("PDF超链接.pdf") pdf.Close() |