2010-03-22 18 views
12

मैं एक डब्ल्यूपीएफ नियंत्रण से एक्सपीएस दस्तावेज़ उत्पन्न करने की कोशिश कर रहा हूं। प्रिंटिंग अब तक काम करता है, लेकिन मुझे लैंडस्केप मोड में एक्सपीएस बनाने का कोई तरीका नहीं मिल रहा है।लैंडस्केप ओरिएंटेशन में डब्ल्यूपीएफ से एक्सपीएस

मेरे कोड एक्सपीएस फ़ाइल बनाने के लिए, ज्यादातर एक और एसओ पेज

public FixedDocument ReturnFixedDoc() 
    { 
     FixedDocument fixedDoc = new FixedDocument(); 
     PageContent pageContent = new PageContent(); 
     FixedPage fixedPage = new FixedPage(); 

     var ctrl = new controlToPrint(); 

     //Create first page of document 
     fixedPage.Children.Add(ctrl); 
     ((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage); 
     fixedDoc.Pages.Add(pageContent); 
     //Create any other required pages here 

     return fixedDoc; 
    } 


    public void SaveCurrentDocument() 
    { 
     // Configure save file dialog box 
     Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); 
     dlg.FileName = "MyReport"; // Default file name 
     dlg.DefaultExt = ".xps"; // Default file extension 
     dlg.Filter = "XPS Documents (.xps)|*.xps"; // Filter files by extension 

     // Show save file dialog box 
     Nullable<bool> result = dlg.ShowDialog(); 

     // Process save file dialog box results 
     if (result == true) 
     { 
      // Save document 
      string filename = dlg.FileName; 

      FixedDocument doc = ReturnFixedDoc(); 
      XpsDocument xpsd = new XpsDocument(filename, FileAccess.Write); 
      System.Windows.Xps.XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter(xpsd); 
      xw.Write(doc); 
      xpsd.Close(); 
     } 
    } 

किसी भी मदद की सराहना की है से लिया।

उत्तर

12

ReturnFixedDoc में अपने FixedPage के आकार सेट करके देखें:

// hard coded for A4 
fixedPage.Width = 11.69 * 96; 
fixedPage.Height = 8.27 * 96; 

संख्या के रूप में (इंच) एक्स (बिंदु प्रति इंच) कर रहे हैं। 96 डब्ल्यूपीएफ का डीपीआई है। मैंने ए 4 पेज के आयामों का उपयोग किया है।

+0

धन्यवाद, ऐसा लगता है कि यह चाल है। मैं नियंत्रण को घुमाने के लिए "नया घुमावदार ट्रांसफॉर्म (9 0)" का उपयोग कर रहा था लेकिन पृष्ठ को उचित आयामों में आकार बदलना बेहतर है :-) – Felix

संबंधित मुद्दे