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.
Hyperlink Syntax
Insert clickable hyperlinks into your documents using the following template syntax:
<<link[linkUrl][linkDisplay]>>
Components:
linkUrl- The target URL or web addresslinkDisplay- The text displayed for the clickable link
Basic Hyperlink Example
Simple Link Insertion
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/)
Multiple Hyperlinks
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"
}
Hyperlinks in Tables
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.
Example: Product Links
Template:
<<foreach [product in products]>>
Product: <<[product.name]>>
View Details: <<link["https://example.com/product/" + product.id][product.name]>>
<</foreach>>
Example: Email Links
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.)
Conditional Hyperlinks
Display hyperlinks only when certain conditions are met.
Example: Optional Website Link
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.
Example: Capitalized 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
Invoice Footer with Links
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>>
Hyperlink Best Practices
URL Management
- Validate URLs - Ensure URLs are properly formatted before passing to templates
- Use HTTPS - Prefer secure HTTPS URLs where possible
- Short display text - Keep link text concise and descriptive
- Test links - Verify all generated links work correctly
Link Styling
- Consistent formatting - Use similar link text patterns throughout documents
- Clear context - Make link purpose clear from display text
- Visual distinction - Ensure links are visually distinguishable (usually automatic)
Data Preparation
- Encode special characters - Handle special characters in URLs properly
- Provide defaults - Have fallback values for missing URL data
- Validation - Validate URL formats in your application before template processing
Hyperlink Types Supported
Web Links
<<link["https://example.com"]["Visit Website"]>>
Email Links
<<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.
Document Links
<<link["file:///path/to/document.pdf"]["View PDF"]>>
Phone Links (for compatible viewers)
<<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"
}
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.