I have a WPF Window that I want to save to an XPS file (or really, any type of file that would store the window image). This window contains a lengthy DataGrid. So far I am able to write to an XPS file, but the resulting document contains only one page, so most of the DataGrid rows are missing. How can I get the XPSDocumentWriter to use as many pages as necessary?
Here is what I've got so far (I've turned off the grid scroll bar and autosized the window to make sure it is full-sized before writing to XPS file):
Dim visual = CType(Me.Content, Media.Visual)
Me.LogGrid.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden
Me.SizeToContent = Windows.SizeToContent.WidthAndHeight
Dim xd As New System.Windows.Xps.Packaging.XpsDocument(file, IO.FileAccess.ReadWrite)
Dim xw = System.Windows.Xps.Packaging.XpsDocument.CreateXpsDocumentWriter(xd)
xw.Write(visual)
xd.Close()
I think Will's comment is probably the right answer.
Related
I have a WPF (vb.net) application with a RichTextBox and load a rtf file into it. This works basically as expected except with the line spacing tag \sl
For me it looks like the RichTextBox does not handle this tag correctly - am I right with this assumption? The same file shows the correct line spacing in MS Wordpad.
Has anyone of you had the same problem - and found a solution?
Thanks for each hint?
This is the code I use to load the rtf into the box
Dim tr As TextRange = New TextRange(TextBoxMain.Document.ContentStart, TextBoxMain.Document.ContentEnd)
tr.Load(myFileStream, System.Windows.DataFormats.Rtf)
Alois
In my WPF application I want to print a custom generated FlowDocument but I have big problems getting the pages on the center of the paper. Every page is aligned to the upper left corner. Even so close the printer can not reach it. Small parts of the document are missing. On the lower and right side there is plenty of empty space so the document can easiely fit on the paper. If it would be centered!
Is the any way to set borders/margin/or offset for the PrintTicket or the Paginator?
I did not find anything that would work.
This is what I do:
// selectedDocument is a FlowDocument
private const double PAGE_HEIGHT = 728;
private const double PAGE_WIDTH = 1024;
var paginator
= ((IDocumentPaginatorSource)this .selectedDocument).DocumentPaginator;
paginator.PageSize = new Size(PAGE_WIDTH, PAGE_HEIGHT);
printDialog.PrintTicket.PageOrientation
= System.Printing.PageOrientation.Landscape;
printDialog.PrintDocument(paginator, "Report");
I also tried different page sizes but it makes no difference.
If I save my FlowDocument as XpsDocument via XpsSerializationManager the created file looks perfect. Borders and margins are all as they should be. In a later step I use this file to create a pdf file. If I then print the pdf-File it looks fine on paper too.
I want to implement previews/thumbnails in my project, therefor i need the graphical output of a control as bitmap. I have a third party control which loads documents and displays them. Is it possible to fetch the output of an control and store it in a bitmap object without adding it to the UI? And If how?
Edit: I probably should said that before, but i don't know if that's important. The ThirdParty Control is an OCX(ActiveX control).
in a Form do:
Bitmap myBitmap = new Bitmap(button1.Width, button1.Height);
// button1.Draw..., not 'this.Draw...'!
button1.DrawToBitmap(myBitmap, button1.DisplayRectangle);
myBitmap.Save(#"C:\test.bmp");
Is there a method within the RichTextBox control in WPF to allow for the user to resize inserted images, or do you have to devise your own method for this.
What I'm trying to achieve is shown below, a screenshot of a WordPad doing what I want:
Notes:
Reading the RTF file as plain text I find that the control tags related to image size is \picscalex100 and \picscaley100 (where 100 denotes scaled to 100%).
So yeah, is there a proper way or trick to this? Any advice on how to go about programming it? Or am I looking at the wrong control altogether?
Turns out you need to wrap your image in a ResizingAdorner.
A beautiful and simple implementation of this code can be found at http://msdn.microsoft.com/en-us/library/ms771714%28loband%29.aspx by Marco Zhou (second post).
The code for this ResizingAdorner is available as an MSDN sample at http://msdn.microsoft.com/en-us/library/ms771714%28loband%29.aspx
Here's a VB.net equivalent of the code I am now using
Dim img As Image
Sub AddImg() Handles btnAddImage.Click
Dim dlg As New Microsoft.Win32.OpenFileDialog
dlg.Filter = "Image Files(*.*) | *.*"
If dlg.ShowDialog Then
img = New Image
AddHandler img.Loaded, AddressOf imgloaded
img.Source = New BitmapImage(New Uri(dlg.FileName, UriKind.Absolute)) With {.CacheOption = BitmapCacheOption.OnLoad}
Dim container As New BlockUIContainer(img)
rtb.Document.Blocks.Add(container)
End If
End Sub
Private Sub imgloaded(ByVal sender As Object, ByVal e As Windows.RoutedEventArgs)
Dim al As AdornerLayer = AdornerLayer.GetAdornerLayer(img)
If Not (al Is Nothing) Then
al.Add(New SDKSample.ResizingAdorner(img))
End If
End Sub
The ResizingAdorner sample will require some great hacking to meet my needs, but what a great start.
Hope someone else finds this useful!
Maybe copy image to Paint and resize accordingly and then post to the RichTextBox in VB6. Images posted directly to VB6 tend to get distorted. Any image copied from Paint to VB6 is pasted as it was in Paint. I found this out when copying from a PDF image to a RichTextBox.
We have 2 flowdocuments that we'd like to compare similar to when using a diff viewer (winmerge, beyond compare, etc). Has anybody done this or know how to get the text out of a flowdocument to do a compare?
Here's a way to save it as raw xaml (text file) from the code-behind file, assuming that the flowdocument (not viewer) itself is named "myFlowDoc", if only the viewer is named, use the property .Document of the viewer to get it. And a stream to a stream myStream (FileStream, MemoryStream, etc doesn't matter).
// Create a TextRange around the entire document.
TextRange documentTextRange = new TextRange(myFlowDoc.ContentStart, myFlowDoc.ContentEnd);
// Save it. Note that it will not respect current stream position;
// it'll assume that it gets the entire stream.
documentTextRange.Save(myStream, DataFormats.Xaml);
I just forged together a basic WPF diff viewer. Shouldn't be too hard to adapt it to write a side by side Flowdocument diff view.
Find more information here: http://www.eqqon.com/index.php/GitSharp#GitSharp.Demo
-- henon