This question is locked. New answers and comments are not allowed.
Hi.
I am having a hard time on how to make PDF viewer print.
I am using telerik toolbar from demo with options defined their an all is working ok except to print.
Can someone give me hint on what can be the issue?
My code is something like:
XAML:
and on code-behind:
As you can see I use byte[] for source and then a converter for stream. It displays ok. Should I store it as stream instead?
Any help appretiated.
Thanks
I am having a hard time on how to make PDF viewer print.
I am using telerik toolbar from demo with options defined their an all is working ok except to print.
Can someone give me hint on what can be the issue?
My code is something like:
XAML:
<
telerik:RadWindow
x:Class
=
"DoisSoft.TTrack.ReportWindow"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
xmlns:local
=
"clr-namespace:DoisSoft.TTrack"
xmlns:converters
=
"clr-namespace:Telerik.Windows.Documents.Converters;assembly=Telerik.Windows.Controls.FixedDocumentViewers"
xmlns:fixed
=
"clr-namespace:Telerik.Windows.Documents.Fixed;assembly=Telerik.Windows.Controls.FixedDocumentViewers"
CanMove
=
"False"
>
<
telerik:RadWindow.ModalBackground
>
<
SolidColorBrush
Color
=
"White"
Opacity
=
"0.5"
/>
</
telerik:RadWindow.ModalBackground
>
<
telerik:RadWindow.Resources
>
<
local:ByteArrayToMemoryStreamConverter
x:Key
=
"ByteArrayToMemoryStreamConverter"
></
local:ByteArrayToMemoryStreamConverter
>
<
fixed:PdfDocumentSourceValueConverter
x:Key
=
"PdfDocumentSourceValueConverter"
/>
</
telerik:RadWindow.Resources
>
<
telerik:RadWindow.Header
>
<
TextBlock
>Relatório</
TextBlock
>
</
telerik:RadWindow.Header
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"25"
/>
<
RowDefinition
Height
=
"*"
/>
</
Grid.RowDefinitions
>
<
telerik:RadToolBar
DataContext
=
"{Binding ElementName=pdfViewer, Path=Commands}"
>
<
telerik:RadToolBar.Resources
>
<
converters:DoubleToStringPercentConverter
x:Key
=
"doubleToStringPercentConverter"
/>
</
telerik:RadToolBar.Resources
>
<!--<
telerik:RadButton
Padding
=
"4"
Command
=
"{Binding OpenPdfDocumentCommand}"
>
<
ToolTipService.ToolTip
>
<
TextBlock
Text
=
"Open"
/>
</
ToolTipService.ToolTip
>
<
Image
Source
=
"/Telerik.Windows.Controls.FixedDocumentViewers;component/Images/open.png"
Stretch
=
"None"
/>
</
telerik:RadButton
>-->
<
telerik:RadButton
Command
=
"{Binding PrintPdfDocumentCommand}"
Click
=
"RadButton_Click"
>
<
ToolTipService.ToolTip
>
<
TextBlock
Text
=
"Print"
/>
</
ToolTipService.ToolTip
>
<
Image
Source
=
"/Telerik.Windows.Controls.FixedDocumentViewers;component/Images/printer.png"
Stretch
=
"None"
/>
</
telerik:RadButton
>
<
telerik:RadToolBarSeparator
/>
<
telerik:RadButton
Command
=
"{Binding PageUpCommand}"
>
<
ToolTipService.ToolTip
>
<
TextBlock
Text
=
"«"
></
TextBlock
>
</
ToolTipService.ToolTip
>
<
Image
Source
=
"/Telerik.Windows.Controls.FixedDocumentViewers;component/Images/previous.png"
Stretch
=
"None"
/>
</
telerik:RadButton
>
<
telerik:RadButton
Command
=
"{Binding PageDownCommand}"
>
<
ToolTipService.ToolTip
>
<
TextBlock
Text
=
"»"
/>
</
ToolTipService.ToolTip
>
<
Image
Source
=
"/Telerik.Windows.Controls.FixedDocumentViewers;component/Images/next.png"
Stretch
=
"None"
/>
</
telerik:RadButton
>
<
TextBox
Width
=
"30"
Margin
=
"2"
Text
=
"{Binding FixedDocumentViewer.CurrentPageNumber, Mode=TwoWay}"
HorizontalContentAlignment
=
"Center"
x:Name
=
"tbCurrentPage"
KeyDown
=
"tbCurrentPage_KeyDown"
/>
<
TextBlock
VerticalAlignment
=
"Center"
Margin
=
"2"
Text
=
"/"
/>
<
TextBlock
VerticalAlignment
=
"Center"
Margin
=
"2"
Text
=
"{Binding ElementName=pdfViewer, Path=Document.Pages.Count}"
/>
<
telerik:RadToolBarSeparator
/>
<
telerik:RadButton
Command
=
"{Binding ZoomInCommand}"
>
<
ToolTipService.ToolTip
>
<
TextBlock
Text
=
"Zoom in"
/>
</
ToolTipService.ToolTip
>
<
Image
Source
=
"/Telerik.Windows.Controls.FixedDocumentViewers;component/Images/zoom-in.png"
Stretch
=
"None"
/>
</
telerik:RadButton
>
<
telerik:RadButton
x:Name
=
"PART_btnZoomOut"
Command
=
"{Binding ZoomOutCommand}"
>
<
ToolTipService.ToolTip
>
<
TextBlock
Text
=
"Zoom out"
/>
</
ToolTipService.ToolTip
>
<
Image
Source
=
"/Telerik.Windows.Controls.FixedDocumentViewers;component/Images/zoom-out.png"
Stretch
=
"None"
/>
</
telerik:RadButton
>
<
telerik:RadComboBox
IsEditable
=
"True"
Margin
=
"2"
Width
=
"70"
SelectedIndex
=
"4"
Text
=
"{Binding FixedDocumentViewer.ScaleFactor, Converter={StaticResource doubleToStringPercentConverter}, Mode=TwoWay}"
>
<
telerik:RadComboBoxItem
Content
=
"10%"
/>
<
telerik:RadComboBoxItem
Content
=
"25%"
/>
<
telerik:RadComboBoxItem
Content
=
"50%"
/>
<
telerik:RadComboBoxItem
Content
=
"75%"
/>
<
telerik:RadComboBoxItem
Content
=
"100%"
/>
<
telerik:RadComboBoxItem
Content
=
"150%"
/>
<
telerik:RadComboBoxItem
Content
=
"200%"
/>
<
telerik:RadComboBoxItem
Content
=
"500%"
/>
<
telerik:RadComboBoxItem
Content
=
"1000%"
/>
<
telerik:RadComboBoxItem
Content
=
"2000%"
/>
</
telerik:RadComboBox
>
<
telerik:RadToolBarSeparator
/>
<
telerik:RadToggleButton
IsChecked
=
"{Binding FixedDocumentViewer.IsInPanMode, Mode=TwoWay}"
>
<
ToolTipService.ToolTip
>
<
TextBlock
Text
=
"Pan"
/>
</
ToolTipService.ToolTip
>
<
Image
Source
=
"/Telerik.Windows.Controls.FixedDocumentViewers;component/Images/hand-free.png"
Stretch
=
"None"
/>
</
telerik:RadToggleButton
>
</
telerik:RadToolBar
>
<
telerik:RadPdfViewer
Grid.Row
=
"1"
x:Name
=
"pdfViewer"
DocumentSource
=
"{Binding Path=Document, Mode=TwoWay, Converter={StaticResource ByteArrayToMemoryStreamConverter}}"
Loaded
=
"pdfViewer_Loaded"
/>
</
Grid
>
</
telerik:RadWindow
>
and on code-behind:
public
partial
class
ReportWindow : RadWindow, INotifyPropertyChanged
{
private
byte
[] _document;
private
IEventAggregator _eventAgrregator;
public
byte
[] Document
{
get
{
return
_document; }
set
{
if
(_document != value)
{
_document = value;
OnPropertyChanged(
"Document"
);
}
}
}
public
ReportWindow(IEventAggregator eventAggregator)
{
InitializeComponent();
_eventAgrregator = eventAggregator;
this
.DataContext =
this
;
}
private
void
pdfViewer_Loaded(
object
sender, System.Windows.RoutedEventArgs e)
{
_eventAgrregator.GetEvent<BusyLoadingEvent>().Publish(
false
);
}
private
void
tbCurrentPage_KeyDown(
object
sender, System.Windows.Input.KeyEventArgs e)
{
TextBox textBox = sender
as
TextBox;
if
(textBox !=
null
)
{
if
(e.Key == System.Windows.Input.Key.Enter)
{
textBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
}
}
}
#region INotifyPropertyChanged Members
public
event
PropertyChangedEventHandler PropertyChanged;
protected
void
OnPropertyChanged(
string
propertyName)
{
if
(
this
.PropertyChanged !=
null
)
{
this
.PropertyChanged(
this
,
new
PropertyChangedEventArgs(propertyName));
}
}
#endregion
private
void
RadButton_Click(
object
sender, System.Windows.RoutedEventArgs e)
{
try
{
pdfViewer.Print();
}
catch
(Exception ex)
{
var aux = ex;
}
}
}
As you can see I use byte[] for source and then a converter for stream. It displays ok. Should I store it as stream instead?
Any help appretiated.
Thanks