Skip to main content

Hyperlinks in Templates - Dynamic Links Guide

Hyperlinks have become essential components of modern documents, appearing in invoices, contracts, quotes, legal documents, reports, and various business communications. PDF4me enables dynamic hyperlink insertion within generated documents, allowing you to create interactive, web-connected documentation.


Insert clickable hyperlinks into your documents using the following template syntax:

<<link[linkUrl][linkDisplay]>>

Components:

  • linkUrl - The target URL or web address
  • linkDisplay - The text displayed for the clickable link

Template Syntax:

Visit our website: <<link[websiteUrl][companyName]>>

Data Source (JSON):

{
"websiteUrl": "https://dev.pdf4me.com/",
"companyName": "PDF4me API Website"
}

Generated Output:

Visit our website: PDF4me API Website

(Where "PDF4me API Website" is a clickable link to https://dev.pdf4me.com/)


Generate multiple hyperlinks within a document using different data fields.

Example: Contact Information

Template:

Website: <<link[website][websiteName]>>
Support Portal: <<link[supportUrl][supportText]>>
Documentation: <<link[docsUrl][docsText]>>

Data:

{
"website": "https://pdf4me.com/",
"websiteName": "PDF4me Homepage",
"supportUrl": "https://dev.pdf4me.com/support/",
"supportText": "Contact Support",
"docsUrl": "https://dev.pdf4me.com/documentation/",
"docsText": "View Documentation"
}

Combine hyperlinks with table structures for organized link presentations.

Resource Table Example

Template:

Resource | Link
<<foreach [resource in resources]>>
<<[resource.name]>> | <<link[resource.url][resource.linkText]>>
<</foreach>>

Data:

{
"resources": [
{
"name": "API Documentation",
"url": "https://dev.pdf4me.com/documentation/",
"linkText": "View Docs"
},
{
"name": "Support Center",
"url": "https://dev.pdf4me.com/support/",
"linkText": "Get Help"
},
{
"name": "Code Samples",
"url": "https://github.com/pdf4me/samples",
"linkText": "Browse Code"
}
]
}

Dynamic URL Construction

Build URLs dynamically using expressions and concatenation.

Template:

<<foreach [product in products]>>
Product: <<[product.name]>>
View Details: <<link["https://example.com/product/" + product.id][product.name]>>
<</foreach>>

Template:

Contact: <<link["mailto:" + employee.email][employee.name]>>

Data:

{
"employee": {
"name": "John Smith",
"email": "[email protected]"
}
}

Output:

Contact: John Smith

(Clicking opens email client with the address from the template.)


Display hyperlinks only when certain conditions are met.

Template:

<<if [websiteUrl != null]>>
Visit us: <<link[websiteUrl][websiteName]>>
<</if>>

Template with Foreach:

<<foreach [contact in contacts]>>
<<[contact.name]>>
<<if [contact.website != null]>> - <<link[contact.website]["Visit Website"]>><</if>>
<</foreach>>

Formatted Display Text

Apply text formatting to hyperlink display text for styled links.

Template:

Visit: <<link[url][companyName:caps]>>

Data:

{
"url": "https://pdf4me.com",
"companyName": "pdf4me solutions"
}

Output:

Visit: Pdf4me Solutions

(With proper capitalization and clickable link)


Common Use Cases

Template:

Questions? Visit our FAQ: <<link[faqUrl]["FAQ Page"]>>
Payment Portal: <<link[paymentUrl]["Pay Invoice"]>>
Contact Support: <<link["mailto:" + supportEmail]["Email Support"]>>

Report References

Template:

Data Sources:
<<foreach [source in dataSources]>>
- <<[source.name]>>: <<link[source.url][source.description]>>
<</foreach>>

Product Catalog

Template:

<<foreach [product in products]>>
Product Name: <<[product.name]>>
Price: $<<[product.price]>>
More Info: <<link[product.detailsUrl]["View Details"]>>

<</foreach>>

URL Management

  1. Validate URLs - Ensure URLs are properly formatted before passing to templates
  2. Use HTTPS - Prefer secure HTTPS URLs where possible
  3. Short display text - Keep link text concise and descriptive
  4. Test links - Verify all generated links work correctly
  1. Consistent formatting - Use similar link text patterns throughout documents
  2. Clear context - Make link purpose clear from display text
  3. Visual distinction - Ensure links are visually distinguishable (usually automatic)

Data Preparation

  1. Encode special characters - Handle special characters in URLs properly
  2. Provide defaults - Have fallback values for missing URL data
  3. Validation - Validate URL formats in your application before template processing

<<link["https://example.com"]["Visit Website"]>>
<<link["mailto:[email protected]"]["Email Us"]>>

Use your own email or a placeholder; avoid raw support/contact emails in templates to prevent broken links on some hosts.

<<link["file:///path/to/document.pdf"]["View PDF"]>>
<<link["tel:+1234567890"]["Call Us"]>>

Troubleshooting

Common Issues

Issue: Links not clickable in generated document
Solution: Verify syntax matches exactly: <<link[url][text]>>

Issue: Broken URLs in output
Solution: Check for special characters; encode URLs properly

Issue: Display text shows merge field syntax
Solution: Ensure closing >> brackets are present

Issue: Links display as plain text
Solution: Verify document viewer supports hyperlinks


Complete Example: Customer Communication

Template:

Dear <<[customerName]>>,

Thank you for your recent purchase. Your order details are available at:
<<link[orderTrackingUrl]["Track Your Order"]>>

For assistance, please visit:
- Help Center: <<link[helpUrl]["Get Help"]>>
- Email Support: <<link["mailto:" + supportEmail]["Contact Support"]>>
- Live Chat: <<link[chatUrl]["Start Chat"]>>

Best regards,
<<[companyName]>>

Data:

{
"customerName": "John Smith",
"orderTrackingUrl": "https://example.com/track/12345",
"helpUrl": "https://example.com/help",
"supportEmail": "[email protected]",
"chatUrl": "https://example.com/chat",
"companyName": "Acme Corporation"
}

Link Testing

Always test generated documents with actual hyperlinks to ensure they function correctly across different PDF viewers and platforms. Some viewers may handle certain link types differently.