Hello,
Thanks for your feedback!
As one method, please refer to the following code to draw the PdfTextWebLink to each page first, and then add the FooterTemplate to the PDF file. In this way, you can download the file through the link of the PdfTextWebLink, and then open it.
- Code: Select all
Dim pdf As PdfDocument = New PdfDocument()
pdf.Pages.Add()
pdf.Pages.Add()
pdf.Pages.Add()
pdf.Pages.Add()
Dim margins As New PdfMargins(60, 60, 60, 60)
For Each page As PdfPageBase In pdf.Pages
Dim ponit As PointF = New PointF(80, page.Size.Height - 100)
CreateLink(page, ponit)
Next
pdf.Template.Bottom = CreateFooterTemplate(pdf, margins)
pdf.SaveToStream(ms, FileFormat.PDF)
Private Function CreateFooterTemplate(doc As PdfDocument, margins As PdfMargins) As PdfPageTemplateElement
'get page size
Dim pageSize As SizeF = doc.PageSettings.Size
'create a PdfPageTemplateElement object which works as footer space
Dim footerSpace As New PdfPageTemplateElement(pageSize.Width, margins.Bottom)
footerSpace.Foreground = False
'declare two float variables
Dim x As Single = margins.Left
Dim y As Single = 0
'draw line in footer space
Dim pen As New PdfPen(PdfBrushes.Gray, 1)
footerSpace.Graphics.DrawLine(pen, x, y, pageSize.Width - x, y)
'draw text in footer space
y = y + 5
Dim font As New PdfTrueTypeFont(New Font("Impact", 10.0F), True)
Dim format As New PdfStringFormat(PdfTextAlignment.Left)
'draw dynamic field in footer space
Dim number As New PdfPageNumberField()
Dim count As New PdfPageCountField()
Dim compositeField As New PdfCompositeField(font, PdfBrushes.Gray, "Page {0} of {1}", number, count)
compositeField.StringFormat = New PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Top)
Dim size As SizeF = font.MeasureString(compositeField.Text)
compositeField.Bounds = New RectangleF(pageSize.Width - x, y, size.Width, size.Height)
compositeField.Draw(footerSpace.Graphics)
'return footerSpace
Return footerSpace
End Function
Private Sub CreateLink(page As PdfPageBase, point As PointF)
Dim font2 As New PdfTrueTypeFont(New Font("Verdana", 10, System.Drawing.FontStyle.Bold))
Dim text As String = "Download the Carbon Footprint Calculator"
Dim link2 As New PdfTextWebLink()
link2.Text = text
link2.Url = "https://www.ail.ca/wp-content/uploads/2021/04/CSP-vs-RCP-Carbon-Footprint-Calculator-2.xlsx"
link2.Font = font2
link2.Brush = PdfBrushes.DarkSeaGreen
link2.DrawTextWebLink(page.Canvas, point)
End Sub
Else, you can consider referring to the following code to add the file which from your URL as an attachment to the PDF file, and then open this file.
- Code: Select all
Dim url As String = "https://www.ail.ca/wp-content/uploads/2021/04/CSP-vs-RCP-Carbon-Footprint-Calculator-2.xlsx"
Dim myWebClient As New WebClient()
Dim fileBytes As Byte() = myWebClient.DownloadData(url)
Dim pdf As PdfDocument = New PdfDocument()
Dim attachment As New PdfAttachment("customName.xlsx", fileBytes)
attachment.Description = "the downloadfile"
pdf.Attachments.Add(attachment)
pdf.SaveToFile("attach.pdf", FileFormat.PDF)
Anyway, if there is any progress with SPIREPDF-4176, we will keep you informed.
Sincerely,
Marcia
E-iceblue support team