Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Flow Document Paper Size (Not Page Size)

$
0
0

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)


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>