您好我已经使用silverlight创建了Id卡。
<UserControl x:Class="ICartPrinting.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="409" d:DesignWidth="360" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" Loaded="UserControl_Loaded">
<Grid x:Name="LayoutRoot" Background="White" Height="410" Width="360" >
<Border x:Name="AreaToPrint" BorderThickness="1" BorderBrush="Black" Margin="0,30,0,0" >
<Grid x:Name="GridAreaToPrint">
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="95,15,0,0" Name="lbl1" VerticalAlignment="Top" Width="89" FontWeight="Bold" Content="CSC" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="170,15,0,0" Name="lblCSC" VerticalAlignment="Top" Width="180" Content="CSC" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="160,15,0,0" Name="lbl2" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="95,40,0,0" Name="lbl3" VerticalAlignment="Top" Width="89" FontWeight="Bold" Content="Name" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="170,40,0,0" Name="lblName" VerticalAlignment="Top" Width="212" Content="Name" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="160,40,0,0" Name="lbl4" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="95,65,0,0" Name="lbl5" VerticalAlignment="Top" Width="89" FontWeight="Bold" Content="Address" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="160,65,0,0" Name="lbl6" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="170,65,0,0" Name="lblAddress" VerticalAlignment="Top" Width="212" Content="Adderss" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="95,90,0,0" Name="lbl7" VerticalAlignment="Top" Width="89" FontWeight="Bold" Content="Code No." />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="160,90,0,0" Name="lbl8" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="170,90,0,0" Name="lblCode" VerticalAlignment="Top" Width="72" Content="Code" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="250,90,0,0" Name="lbl11" VerticalAlignment="Top" Width="40" FontWeight="Bold" Content="Rank" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="290,90,0,0" Name="lbl12" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="300,90,0,0" Name="lblRank" VerticalAlignment="Top" Width="70" Content="Rank" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="95,115,0,0" Name="lbl9" VerticalAlignment="Top" Width="89" FontWeight="Bold" Content="Join Date" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="160,115,0,0" Name="lbl10" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="170,115,0,0" Name="lblDOF" VerticalAlignment="Top" Width="89" Content="Join Date" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="250,115,0,0" Name="lbl47" VerticalAlignment="Top" Width="89" FontWeight="Bold" Content="Valid" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="290,115,0,0" Name="lbl48" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="300,115,0,0" Name="lblValid" VerticalAlignment="Top" Width="78" Content="Valid" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="10,140,0,0" Name="lbl13" VerticalAlignment="Top" Width="50" FontWeight="Bold" Content="S.R." />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="80,140,0,0" Name="lblSR" VerticalAlignment="Top" Width="90" Content="sr" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="65,140,0,0" Name="lbl23" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="10,160,0,0" Name="lbl14" VerticalAlignment="Top" Width="50" FontWeight="Bold" Content="S.D." />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="65,160,0,0" Name="lbl24" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="80,160,0,0" Name="lblSD" VerticalAlignment="Top" Width="90" Content="sd" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="10,180,0,0" Name="lbl15" VerticalAlignment="Top" Width="50" FontWeight="Bold" Content="D.O." />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="65,180,0,0" Name="lbl25" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="80,180,0,0" Name="lblDO" VerticalAlignment="Top" Width="90" Content="do" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="10,200,0,0" Name="lbl16" VerticalAlignment="Top" Width="50" FontWeight="Bold" Content="Z.O." />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="65,200,0,0" Name="lbl26" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="80,200,0,0" Name="lblZO" VerticalAlignment="Top" Width="90" Content="zo" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="10,220,0,0" Name="lbl17" VerticalAlignment="Top" Width="50" FontWeight="Bold" Content="E.M.(I)" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="65,220,0,0" Name="lbl27" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="80,220,0,0" Name="lblEM1" VerticalAlignment="Top" Width="90" Content="EM(I)" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="10,240,0,0" Name="lbl18" VerticalAlignment="Top" Width="50" FontWeight="Bold" Content="E.M.(R)" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="65,240,0,0" Name="lbl28" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="80,240,0,0" Name="lblEMR" VerticalAlignment="Top" Width="90" Content="EM(R)" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="10,260,0,0" Name="lbl19" VerticalAlignment="Top" Width="50" FontWeight="Bold" Content="EMH" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="65,260,0,0" Name="lbl29" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="80,260,0,0" Name="lblEMH" VerticalAlignment="Top" Width="90" Content="EMH" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="10,280,0,0" Name="lbl20" VerticalAlignment="Top" Width="50" FontWeight="Bold" Content="EMH(2)" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="65,280,0,0" Name="lbl30" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="80,280,0,0" Name="lblEMH2" VerticalAlignment="Top" Width="90" Content="EMH(2)" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="10,300,0,0" Name="lbl21" VerticalAlignment="Top" Width="50" FontWeight="Bold" Content="EMH(4)" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="65,300,0,0" Name="lbl22" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="80,300,0,0" Name="lblEMH4" VerticalAlignment="Top" Width="90" Content="EMH(4)" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="200,140,0,0" Name="lbl31" VerticalAlignment="Top" Width="50" FontWeight="Bold" Content="S.O." />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="260,140,0,0" Name="lbl32" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="280,140,0,0" Name="lblSO" VerticalAlignment="Top" Width="90" Content="so" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="200,160,0,0" Name="lbl33" VerticalAlignment="Top" Width="50" FontWeight="Bold" Content="S.I." />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="260,160,0,0" Name="lbl34" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="280,160,0,0" Name="lblSI" VerticalAlignment="Top" Width="90" Content="si" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="200,180,0,0" Name="lbl35" VerticalAlignment="Top" Width="50" FontWeight="Bold" Content="R.O." />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="260,180,0,0" Name="lbl36" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="280,180,0,0" Name="lblRO" VerticalAlignment="Top" Width="90" Content="ro" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="200,200,0,0" Name="lbl37" VerticalAlignment="Top" Width="50" FontWeight="Bold" Content="E.M." />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="260,200,0,0" Name="lbl38" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="280,200,0,0" Name="lblEM" VerticalAlignment="Top" Width="90" Content="EM" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="200,220,0,0" Name="lbl39" VerticalAlignment="Top" Width="50" FontWeight="Bold" Content="E.M.(II)" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="260,220,0,0" Name="lbl40" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="280,220,0,0" Name="lblEM2" VerticalAlignment="Top" Width="90" Content="em(2)" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="200,240,0,0" Name="lbl41" VerticalAlignment="Top" Width="50" FontWeight="Bold" Content="E.M.(C)" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="260,240,0,0" Name="lbl42" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="280,240,0,0" Name="lblEMC" VerticalAlignment="Top" Width="90" Content="EM(C)" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="200,260,0,0" Name="lbl43" VerticalAlignment="Top" Width="50" FontWeight="Bold" Content="EMH(1)" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="260,260,0,0" Name="lbl44" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="280,260,0,0" Name="lblEMH1" VerticalAlignment="Top" Width="90" Content="EMH(1)" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="200,280,0,0" Name="lbl45" VerticalAlignment="Top" Width="50" FontWeight="Bold" Content="EMH(3)" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="260,280,0,0" Name="lbl46" VerticalAlignment="Top" Width="9" FontWeight="Bold" Content=":" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="280,280,0,0" Name="lblEMH3" VerticalAlignment="Top" Width="90" Content="EMH(3)" />
<TextBox Height="31" Background="Black" HorizontalAlignment="Center" Margin="0,330,0,0" Name="textBox1" VerticalAlignment="Top" Text=" 107,MONALISA COMPLEX,,NR.KALYAN" Foreground="White" Width="410" />
<TextBox Height="28" Background="Black" HorizontalAlignment="Center" Margin="0,350,0,0" BorderBrush="Black" Name="textBox2" VerticalAlignment="Top" Text=" HOTEL,SAYAJIGUNJ,VADODARA,Vadodara,Gujarat" Foreground="White" Width="410" />
</Grid>
</Border>
<Button Content="Print" Height="23" HorizontalAlignment="Left" Margin="3,3,0,0" Name="PrintButton" VerticalAlignment="Top" Width="75" Click="PrintButton_Click" />
</Grid>
</UserControl>
这是身份证。当我在A4尺寸的纸张上打印时,内容在左上方的纸张上打印,但是当我在小尺寸的纸张上打印时,只打印了右侧的一半,左侧的一半被切掉。我可以在Page的中心打印吗?任何帮助,将不胜感激。感谢
答案 0 :(得分:0)
您是否通过循环浏览所有标签进行打印,然后只打印文本?或者将“GridAreaToPrint”转换为UI元素,然后打印出来?
如果你要转换为UI元素,那么你已经在那里了一半。您必须指定要打印A4,A5或其他任何天气的天气,然后根据用户的选择,您可以根据用户的选择来适当调整网格。 (有踪迹和错误)
如果你不想适合页面,你可以调整X&amp; Y值(scaleTransform.ScaleX
&amp; caleTransform.ScaleX
),直到您的身份证到达您想要的位置。
请参阅此参考:Silverlight printing: Fit to page
它应该包含你需要的一切