Return to Snippet

Revision: 30690
at August 19, 2010 13:31 by Xhitman


Initial Code
private String getXmlString(Contact c)
        {
            String s = '<?xml version="1.0" encoding="UTF-8"?>' +
	            '<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">' +
	            '<f href="http://mysites-developer-edition.na1.force.com/resource/0/myform.pdf"/>' +
	            '<fields>' +
	            '<field name="DOB"><value>' + c.birthdate + '</value></field>' +
	            '<field name="Name"><value>' + c.firstname + ' ' + c.lastname + '</value></field>' +
	            '<field name="SS"><value>' + c.SS_Number__c + '</value></field>' +
	            '<field name="Phone"><value>' + c.phone + '</value></field>' +
	            '<field name="Citizenship"><value>' + c.Citizenship__c + '</value></field>' +
	            '<field name="CountryOfBirth"><value>' + c.Country_of_Birth__c + '</value></field>' +
	            '<field name="Tax"><value>' + c.Country_of_Tax_Residence__c + '</value></field>' +
	            '<field name="GovId"><value>' + c.Government_Identification__c + '</value></field>' +
	            '<field name="IdNumber"><value>' + c.ID_Number__c + '</value></field>' +
	            '</fields><ids original="FEBDB19E0CD32274C16CE13DCF244AD2" modified="5BE74DD4F607B7409DC03D600E466E12"/>' +
	            '</xfdf>';
                        
            return s;
        }       
        


        public PageReference XFDFInit() {
            Contact c = [SELECT Id, firstname, lastname, SS_Number__c, birthdate, 
                     phone, Citizenship__c,
                     Country_of_Birth__c, Country_of_Tax_Residence__c, 
                     Government_Identification__c, ID_Number__c,
                     Account.Name, Account.BillingStreet, Account.BillingCity, 
                     Account.BillingState, Account.BillingPostalCode
                     FROM Contact
                     WHERE id = :ApexPages.currentPage().getParameters().get('id')];
	        
	    String xmlContent = getXmlString(c);
	        
	    Attachment attachment = new Attachment();
            attachment.Body = Blob.valueOf(xmlContent);
            attachment.Name = c.lastname + c.firstname + '.XFDF';
            attachment.ParentId = c.Id;
            
            insert attachment;
	                         
	    PageReference contactPage = new PageReference('/' + c.id);
	    contactPage.setRedirect(true);
	    return contactPage;
        }



<apex:page showHeader="true"
	controller="myXFDFController" 
	action="{!XFDFInit}"
	showHeader="false">
</apex:page>

Initial URL
http://blog.sforce.com/sforce/2008/12/use-visualforce-and-apex-to-populate-pdf-forms.html

Initial Description
Credits to Jesse Lorenz
http://wiki.developerforce.com/index.php/Adobe_XFDF

Initial Title
Visualforce and Apex to Populate PDF Forms

Initial Tags

                                

Initial Language
Other