2

I an trying to make a flow document and print with, I was able to adjust the data to required size, and I am getting the required output.

Below is the code for my Flow Document:

<Window x:Class="test"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="test" Height="600" Width="500">
    <Grid>
        <FlowDocumentReader Width="330" Height="110" Name="DocumentRdr">
            <FlowDocument FontSize="8" Name="Document" >
                <Paragraph Margin="0">
                    <TextBlock Text="Brand:"/>
                    <Run Text="{Binding Brand}" />
                </Paragraph>
                <Paragraph Margin="0">
                    <TextBlock Text="Item:"/>
                    <Run Text="{Binding Cat1}" />
                    <TextBlock Text="Size:"/>
                    <Run Text="{Binding Size}" />
                </Paragraph>
                <Paragraph Margin="0">
                    Welcome
                    <Run Text="{Binding Brand}" />
                </Paragraph>
                <BlockUIContainer Margin="0">
                    <Image Source="{Binding BarCode}" Width="Auto" Height="Auto" Stretch="None" HorizontalAlignment="Left" />
                </BlockUIContainer>
            </FlowDocument>
        </FlowDocumentReader>
    </Grid>
</Window>

and the code I use for printing is as follows:

Dim data As New SampleData With {.Brand = "Some Brand", .Cat1 = "A Cat 1", .Size = "100-120"}
Dim k As Zen.Barcode.BarcodeDraw = Zen.Barcode.BarcodeDrawFactory.Code25InterleavedWithoutChecksum
Dim ms As New MemoryStream
k.Draw("1234", 25).Save(ms, System.Drawing.Imaging.ImageFormat.Png)
ms.Position = 0
Dim bi As New BitmapImage
bi.BeginInit()
bi.StreamSource = ms
bi.EndInit()

data.BarCode = bi

Dim temp As New test
temp.DataContext = data

Dim doc = temp.Document
doc.PageHeight = 110

Dim pd = New PrintDialog()

Dim dps As IDocumentPaginatorSource = doc
dps.DocumentPaginator.PageSize = New Windows.Size(100, 100)
If pd.ShowDialog() = True Then
    dps.DocumentPaginator.PageSize = New Windows.Size(330, 110)
    pd.PrintDocument(dps.DocumentPaginator, "Document")
End If

The Problem is, the text and image every thing comes in the size I want, but I am not able to change the size of the paper. I am trying to print labels, due to long page I am getting a print for every 10-12 labels, I want to change the paper size. This print dialog is part of system.windows.control and not system.drawings.printing. I tied to change the code by keeping required size in every place in code where there is size, but not able to do. Could you please correct me, where I went wrong.
Tried the below code too:

pd.PrintQueue.DefaultPrintTicket.PageMediaSize = New System.Printing.PageMediaSize(10, 10)
surpavan
  • 1,372
  • 7
  • 34
  • 66
  • Maybe this question could help: http://stackoverflow.com/questions/345009/printing-a-wpf-flowdocument – Leandro Carracedo Dec 05 '14 at 20:11
  • @PatrickLC, thank you for the comment, I was able to achieve the column width etc, the only option I am searching if for paper size and not page size. – surpavan Dec 05 '14 at 22:25
  • 1
    I added the same question at MSDN Forums, and seems no correct solution there, still waiting for a answer : https://social.msdn.microsoft.com/Forums/en-US/1e91ca9c-45e3-473b-bf87-62f770d826f2/flow-document-paper-size-not-page-size?forum=wpf – surpavan Dec 11 '14 at 01:05
  • Still waiting for answer at MSDN and stackoverflow too. – surpavan Mar 19 '15 at 21:22

0 Answers0