Data & Services - PDF Service
Configure PDF generation and document processing services
Overview
The PDF Service section configures ColdFusion's PDF generation capabilities, including PDFg (PDF Generator) service integration. PDF operations include creating PDFs from HTML, merging documents, adding watermarks, form manipulation, and digital signatures.
Service Configuration
Configure how ColdFusion generates PDF documents and manages PDFg services.
PDF Service Mode
Remote PDFg: Connect to external PDFg server
Production: Remote PDFg for better performance and scalability
Remote PDFg Server Configuration
Port: PDFg service port (default 8989)
Weight: Load balancing weight when multiple servers configured
- Configure at least 2 PDFg servers for redundancy
- Use weight settings to distribute load evenly
- Monitor PDFg server health and availability
- Set up automatic failover between servers
PDF Service Memory Allocation
Moderate use: 1 GB - 2 GB
Heavy use: 2 GB - 4 GB
PDF Operation Timeout
Complex reports: 120-300 seconds
Large documents: 300+ seconds
PDF Generation Examples
Common PDF operations using ColdFusion's PDF functionality.
Generate PDF from HTML
Convert HTML content to PDF document:
// Generate PDF from HTML content
cfdocument(format="pdf", filename="output.pdf") {
writeOutput("
<html>
<head>
<style>
body { font-family: Arial, sans-serif; }
h1 { color: #d63200; }
.content { margin: 20px; }
</style>
</head>
<body>
<h1>Sample Report</h1>
<div class='content'>
<p>This is a PDF generated from HTML.</p>
</div>
</body>
</html>
");
}<!--- Generate PDF from HTML content --->
<cfdocument format="pdf" filename="output.pdf">
<html>
<head>
<style>
body { font-family: Arial, sans-serif; }
h1 { color: #d63200; }
.content { margin: 20px; }
</style>
</head>
<body>
<h1>Sample Report</h1>
<div class="content">
<p>This is a PDF generated from HTML.</p>
</div>
</body>
</html>
</cfdocument>Merge Multiple PDFs
Combine multiple PDF files into a single document:
// Merge multiple PDF files
cfpdf(action="merge", destination="merged.pdf") {
cfpdfparam(source="document1.pdf");
cfpdfparam(source="document2.pdf");
cfpdfparam(source="document3.pdf");
}
// Alternative: Merge using array
pdfFiles = ["document1.pdf", "document2.pdf", "document3.pdf"];
cfpdf(action="merge", source=pdfFiles, destination="merged.pdf");<!--- Merge multiple PDF files --->
<cfpdf action="merge" destination="merged.pdf">
<cfpdfparam source="document1.pdf">
<cfpdfparam source="document2.pdf">
<cfpdfparam source="document3.pdf">
</cfpdf>
<!--- Alternative: Merge using array --->
<cfset pdfFiles = ["document1.pdf", "document2.pdf", "document3.pdf"]>
<cfpdf action="merge" source="#pdfFiles#" destination="merged.pdf">Add Watermark
Apply watermark to PDF documents:
// Add text watermark to PDF
cfpdf(
action="addWatermark",
source="original.pdf",
destination="watermarked.pdf",
text="CONFIDENTIAL",
rotation=45,
opacity=0.3,
foreground=true
);
// Add image watermark
cfpdf(
action="addWatermark",
source="original.pdf",
destination="watermarked.pdf",
image="logo.png",
position="0,0",
opacity=0.5
);<!--- Add text watermark to PDF --->
<cfpdf
action="addWatermark"
source="original.pdf"
destination="watermarked.pdf"
text="CONFIDENTIAL"
rotation="45"
opacity="0.3"
foreground="true">
<!--- Add image watermark --->
<cfpdf
action="addWatermark"
source="original.pdf"
destination="watermarked.pdf"
image="logo.png"
position="0,0"
opacity="0.5">Protect PDF with Password
Encrypt and password-protect PDF documents:
// Protect PDF with password
cfpdf(
action="protect",
source="document.pdf",
destination="protected.pdf",
newUserPassword="userPass123",
newOwnerPassword="ownerPass123",
permissions="AllowPrinting,AllowCopy",
encrypt="AES_128"
);
// Remove password protection
cfpdf(
action="protect",
source="protected.pdf",
destination="unprotected.pdf",
password="ownerPass123",
newUserPassword="",
newOwnerPassword=""
);<!--- Protect PDF with password --->
<cfpdf
action="protect"
source="document.pdf"
destination="protected.pdf"
newUserPassword="userPass123"
newOwnerPassword="ownerPass123"
permissions="AllowPrinting,AllowCopy"
encrypt="AES_128">
<!--- Remove password protection --->
<cfpdf
action="protect"
source="protected.pdf"
destination="unprotected.pdf"
password="ownerPass123"
newUserPassword=""
newOwnerPassword="">Best Practices
Server Separation
Run PDFg on separate servers for production environments to isolate resource-intensive PDF operations from web traffic.
Load Balancing
Use multiple PDFg instances for high-volume PDF generation with proper load distribution and failover.
Memory Allocation
Allocate sufficient memory for PDF operations based on document complexity and generation volume.
Security
Always encrypt PDFs containing sensitive information using strong passwords and AES encryption.
Asynchronous Processing
Generate large PDFs asynchronously to avoid blocking user requests and improve application responsiveness.
Monitoring
Monitor PDFg server health, memory usage, and generation times to identify performance issues early.
Common Issues & Solutions
OutOfMemoryError During PDF Generation
- Increase PDF service memory allocation in administrator
- Increase JVM heap size for dedicated PDFg servers
- Optimize PDF content (reduce image sizes, use efficient fonts)
- Split large documents into smaller chunks
- Process PDFs in batches rather than simultaneously
PDF Generation Timeout
- Increase PDF operation timeout setting
- Use asynchronous generation for long-running operations
- Optimize HTML/CSS for faster rendering
- Reduce document complexity (images, tables, fonts)
- Consider using dedicated PDFg servers with more resources
Connection Refused to PDFg Server
- Verify PDFg server is running and accessible
- Check firewall rules allow connections on PDFg port (8989)
- Verify hostname/IP and port configured correctly
- Test connection from ColdFusion server to PDFg server
- Check PDFg server logs for startup errors