流动文件纸张尺寸

时间:2014-11-26 18:51:54

标签: printing flowdocument page-size

我试图制作流文档并打印,我能够将数据调整到所需的大小,并且我得到了所需的输出。

以下是我的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>

我用于打印的代码如下:

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

问题是,文字和图像的每个东西都有我想要的尺寸,但我无法改变纸张的大小。我正在尝试打印标签,由于长页面我得到每10-12个标签的打印件,我想更改纸张尺寸。 此打印对话框是system.windows.control的一部分,而不是system.drawings.printing。我通过在代码中的每个位置保持所需大小来改变代码,但是没有能力。你能纠正我,我错了。
尝试了下面的代码:

pd.PrintQueue.DefaultPrintTicket.PageMediaSize = New System.Printing.PageMediaSize(10, 10)

0 个答案:

没有答案