function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
LogeshLogesh 

Reg: Opening a word document in Ms Word in print view/print layout by default (Visualforce)

Hi Friends,

 

Hope this scenario will be very interesting for everyone!! I have a scenario where the user needs to download the word document by clicking a link on page.

This word document is dynamically generated from visualforce by fetching values from the record.

Everything works fine. But the problem is when I try to open the downloaded document in MsWord (2007 or 2010), It opens in web layout by default. But I need to open the document in print layout / print view.

I searched and found that the below code snippet works well for all kinds of technology like php, python, etc..

// Code snippet

<!--[if gte mso 9]>
<xml>
<w:WordDocument>
  <w:view w:val="print" />
  <w:zoom w:percent="100" />
  <w:DoNotOptimizeForBrowser/>
  <w:DoNotHyphenateCaps/>
  <w:PunctuationKerning/>
</w:WordDocument>
</xml>
  <![endif]-->

 

But it didnt work with visualforce.  I placed this code snippet inside the <head> tag and right below the <title> tag as per Office XML reference. But I didnt get a positive result.

Is there anyway to achieve this in visualforce??

 

Thanks & Regards,

Logesh

SFDC_LearnerSFDC_Learner

http://boards.developerforce.com/t5/Visualforce-Development/XML-file-download-through-button-click/m-p/537573#M57654

 

Its nearer to your requirement.

 

I am not 100% sure whether it is possible or not. May be try some javascript kind of samples. 

M.sfM.sf
Open an document in print layout instead of default web layout.

By Default MS word will take the contents in Text/Html Format

Include the following code in VF Page.

<apex:page controller="TestMSWord" contentType="application/msWord#msword.doc" >
<html xmlns:w="urn:schemas-microsoft-com:office:word">
<apex:outputText value="{!PrintView}" escape="false"/>
<body>
//All your code Goes Here
</body>
</html>
</apex:page>


In class Add the following

public class TestMSWord{
    public String getPrintView()
    {
        return
        '<!--[if gte mso 9]>' +
            '<xml>' +
            '<w:WordDocument>' +
            '<w:View>Print</w:View>' +
            '<w:Zoom>100</w:Zoom>' +
            '<w:DoNotOptimizeForBrowser/>' +
            '</w:WordDocument>' +
            '</xml>' +
            '<![endif]>';
        }
    }

Explanation:

Add <html> tag with attributes since it should understand the schema is of word
Add <body> tag so that it will allow html tags like <h1>, <ul>,<li> etc
Add <Outputext> from class since directly vf page will not allow to save the html content with <w:> tag.This will enable print view by default.