+ Start a Discussion
mat_tone_84mat_tone_84 

xfdf testing problem - first code

I try to do this http://wiki.developerforce.com/index.php/Adobe_XFDF in my sandbox but i have 2 question that stop me for continue the develop:

1- where Do I put the code which start with : "private String getXmlString(Contact c)........." ? i try to a class but doesn't work

2- where Do I put the code which start with : "public PageReference XFDFInit() {.........." I try to a class but doesn't work

The only code which work is the apex page; I have created a link which open Visual force page

Thanks for help me
mat_tone_84mat_tone_84
I suppose that I'm the only one who want use xfdf..........
mat_tone_84mat_tone_84

After some days of study, I create a class with this code:

 

 

public with sharing class myXFDFController {
    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://www.xxxxx.com/xxxx/test.pdf"/>' +
                '<fields>' +
                '<field name="lastname"><value>' + c.lastname + '</value></field>' +
                '<field name="firstname "><value>' + c.firstname + '</value></field>' +
                '<field name="phone"><value>' + c.phone + '</value></field>' +
                '<field name="mobilephone"><value>' + c.mobilephone + '</value></field>' +
                '</fields><ids original="B74972B97D3A3843ACA884D1A1DCA1DC" modified="5D533F9265CF4A419CEE9DFE05BAF689"/>' +
                '</xfdf>';
                        
            return s;
        }  
    public PageReference XFDFInit() {
            Contact c = [SELECT firstname, lastname, mobilephone, phone
                     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;
    }

}

 

 

after I create a visual force page with this code:

 

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

 

now I have to create a link on contact page or add VF page into my layout of contact.

The problem is that I don't have the VF page into layout and I haven't the VF page into the section for create a link.....

 

How Can I do this ?

thanks

 

rforce2rforce2

Checkout the PerFom app, it can generate XFDF files from salesforce object to populate PDF forms, it should help you:

http://sites.force.com/appexchange/listingDetail?listingId=a0N30000003GLHrEAO

mat_tone_84mat_tone_84

thanks, perfect solution!

 

Now I have to choose to buy or to study and develop the software by myself :smileyhappy:

mat_tone_84mat_tone_84

for some days it is free and after I have to buy it.

Instead can you help me for the code above ?

mat_tone_84mat_tone_84

maybe I'm near the solution.

after the creation of apeg page, called testpdf with this line:

 

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

 

 

I create a button link into the contact with this:

 

https://cs2.salesforce.com/apex/testpdf?id={!Contact.Id}

 

I have a file called myname.xfdf attached into contact, but it hasn't the form filled....

 

If I click on myname.xfdf which is attached on contact, adobe open the file and ask me to gain access to web for open this link: http://www.xxxxx.com/xxxx/test.pdf.

If i go forward, adobe doesn't open my pdf with field filled.

I read on guide this:

Therefore, you can use your Force.com platform as a reliable method of storing the required PDF forms in known locations. Otherwise, it will not always be possible for PDF-viewing/editing applications to retrieve and open the PDF Forms when they are needed. We will use a Sites enabled developer edition in this example.

I try to upload on SF test.pdf but I have this link without pdf extension https://cs2.salesforce.com/resource/1274917042000/test instead of this link wich is on guide . How can I put a pdf file with extension on force.com ? 

http://mysites-developer-edition.na1.force.com/resource/0/myform.pdf
rforce2rforce2

Sorry for the delay, for some reason I didn't get the email notification for your reply.

 

Instead of using this link:

https://cs2.salesforce.com/resource/1274917042000/test 

 

You should use the servlet.FileDownload:

https://cs2.salesforce.com/servlet/servlet.FileDownload?file=00PA0000000XXXX

mat_tone_84mat_tone_84

I take the id of my document and write the link in the same way of your, but doesn't work.

If I click my link, SF doesn't find id.

 

For take id I do this:

setup - develope - Static Resources

click on my file

read the url on the browser wich is https://cs2.salesforce.com/081R00000008U6y, instead if I click on link "Click here to view this file" I have https://cs2.salesforce.com/resource/1274918509000/test

create the link https://cs2.salesforce.com/servlet/servlet.FileDownload?file=081R00000008U6y

 

 

rforce2rforce2

You are working with static resources, and the solution I suggested is for Attachments.

 

To work with static resources - you should take a look at this url, if you haven't check it out yet:

http://wiki.developerforce.com/index.php/Delivering_Static_Resources_with_Visualforce

mat_tone_84mat_tone_84

I use this:

 

'<f href="https://cs2.salesforce.com/resource/1274918509000/test"  type="application/pdf"/>' +

 

and doesn't work xfdf.

 

According me, the problem is that xfdf file doesn't find pdf file for fill the field,

 

If I work on local with xfdf , the file works properly

SSRS2SSRS2

>>I use this:

 

>>'<f href="https://cs2.salesforce.com/resource/1274918509000/test"  type="application/pdf"/>' +

 

>>and doesn't work xfdf.

 

Its work for me

upload your XFDF support pdf  to Document and get URL .

 

<f href="https://ap1.salesforce.com/servlet/servlet.FileDownload?file=015900000001Uav"/>


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="https://ap1.salesforce.com/servlet/servlet.FileDownload?file=015900000001Uav"/>' +
                '<fields>' +
                '<field name="lastName"><value>' + c.lastname + '</value></field>' +

etc..

 

did you select  ' XFDF include'  for your form text fields(lastName...) ?

 

-Suresh

 


mat_tone_84mat_tone_84

doesn't work.

this is the code of apex class

 

 

public with sharing class myXFDFController {
    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="https://cs2.salesforce.com/servlet/servlet.FileDownload?file=015R00000009hXX"/>' +
                '<fields>' +
                '<field name="lastname"><value>' + c.lastname + '</value></field>' +
                '<field name="firstname"><value>' + c.firstname + '</value></field>' +
                '<field name="phone"><value>' + c.phone + '</value></field>' +
                '<field name="mobile"><value>' + c.mobilephone + '</value></field>' +
                '</fields><ids original="B74972B97D3A3843ACA884D1A1DCA1DC" modified="5D533F9265CF4A419CEE9DFE05BAF689"/>' +
                '</xfdf>';
                        
            return s;
        }  
    public PageReference XFDFInit() {
            Contact c = [SELECT firstname, lastname, mobilephone, phone
                     FROM Contact
                     WHERE id = :ApexPages.currentPage().getParameters().get('id')];
            //'003R000000PJdLR'];
        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;
    }

https://cs2.salesforce.com/servlet/servlet.FileDownload?file=015R00000009hXX  <--- this is the link of my test.pdf .

test.pdf is saved into documents of SF

test.pdf have 4 field called lastname,firstname,phone,mobile.

 

I try to overwrite the link of test.pdf with the link of test.pdf located into static resources https://cs2.salesforce.com/resource/1280351829000/test, but doesn't work too

 

 

 

SSRS2SSRS2

I think no problem with your Apex code its works fine for me. I think problem with your PDF file in my case created PDF using ADOBE ACROBAT 8 PRIFESIONAL

Version 8.0.0

 

-Suresh

 

 

 

mat_tone_84mat_tone_84

If i use xfdf  and pdf test in local , it work properly.

I will create a pdf with other version of acrobat and after I will update you,thanks

 

ederu21ederu21

In the example code to put the link: <f href="http://mysites-developer-edition.na1.force.com/resource/0/myform.pdf"/>
when you try to find the template file attempts to download the file but I changed the class the value of the url just for:'<f href=" Demo PDF Form"/> which must be in the path where you download the form XFDF with this by opening the XFDF file and displays the data retrieved in thequery.

 

 

public with sharing class myXFDFController {

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="Demo PDF Form.pdf"/>' +
'<fields>' +
'<field name="Date of Birth"><value>' + c.birthdate + '</value></field>' +
'<field name="Your Name"><value>' + c.firstname + ' ' + c.lastname + '</value></field>' +
'<field name="Prueba1"><value>' + c.lastname + '</value></field>' +
'</fields><ids original="FEBDB19E0CD32274C16CE13DCF244AD2" modified="4144AA6BFA956D43B9A9D20B9DC8A914"/>' +
'</xfdf>';

return s;
}
public PageReference XFDFInit() {
Contact c = [SELECT Id, firstname, lastname, birthdate,
phone,(Select Id From Attachments)
FROM Contact
WHERE id = :ApexPages.currentPage().getParameters().get('id')];

String xmlContent = getXmlString(c);
system.debug(':: '+ xmlContent );

Attachment attachment = new Attachment();
attachment.Body = Blob.valueOf(xmlContent);
attachment.Name = c.lastname + c.firstname + '.XFDF';
system.debug(':: '+ c.id);
attachment.ParentId = c.Id;

insert attachment;

PageReference attachmentPage = new PageReference('/' + attachment.id);
//attachmentPage.setRedirect(true);
return attachmentPage;
}

}

 

 


Santi DiezSanti Diez
Hi all, this might be obvious for most people... but it took me a while.. xD

The code above works prefectly (even without the sites, using just public static resources for the pdf form). In order to see the results, the .xfdf file has to be open with the microsoft explorer browser, not the adobe or chrome.. hope it helps!! 
Cameron CohranCameron Cohran
Is there a way to download the file/view it if you are not using Explorer? We use chrome.