2010-03-22 12 views
12

Bir WPF Denetimi'nden bir XPS Belgesi oluşturmaya çalışıyorum. Yazdırma şu ana kadar çalışıyor, ancak manzara modunda XPS'yi oluşturmanın bir yolunu bulamıyorum.Yatay yönde XPS'de WPF

Kodum çoğunlukla Herhangi bir yardım takdir başka SO sayfa

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(); 
     } 
    } 

alınan, XPS dosyası oluşturmak için. ReturnFixedDoc içinde FixedPage boyutunun ayarlanması

cevap

12

Dene:

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

numaralar şeklinde (inç) x (inç başına nokta) vardır. 96, WPF'nin DPI'sidir. Bir A4 sayfasının boyutlarını kullandım.

+0

Teşekkür ederim, bu hile yapmak gibi görünüyor. Kontrolü döndürmek için "yeni RotateTransform (90)" kullanıyordum ama sayfayı uygun boyutlara yeniden boyutlandırmak daha iyi :-) – Felix

İlgili konular