Tuesday, January 29, 2013

How to printing a document in silverlight

How to printing a document in silverlight

I've written an application web in silverlight for view Tiff files. I send an absolut uri of Tiff files to silverlight app and it view /zooming or download a file.

I print the tiff with PrintDocument library, but the file sent to printer is very large (500Mb for 100kb of tiff file).

Now this is my code for printing:

 Protected Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)     Try         If (PrintPageCount = 0) Then             PrintPageCount = ImageTiff.NumberOfDirectories             PrintCurrPage = 0         End If         If (PrintCurrPage < PrintPageCount) Then             ImageTiff.SetDirectory(PrintCurrPage)             Dim cnv As New Canvas With                 {                     .Width = 840,                     .Height = 1180,                     .Background = New ImageBrush With {                              .ImageSource = GetWritableBmp(ImageTiff, larghezza, altezza),                              .Stretch = Stretch.Fill                      }                 }             ev.PageVisual = cnv             PrintCurrPage += 1             ev.HasMorePages = True         Else             ev.HasMorePages = False         End If     Catch ex As Exception         MessageBox.Show("Errore handler:" & ex.Message & vbCrLf & ex.StackTrace)     End Try End Sub 

And my event handler for print button

 Private Sub ButtonPrint_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles ButtonPrint.Click     Try         Dim pdoc As New PrintDocument()         AddHandler pdoc.PrintPage, AddressOf Me.pd_PrintPage         pdoc.Print(Uri.AbsoluteUri)     Catch ex As Exception         MessageBox.Show("Errore:" & ex.Message)     End Try End Sub 

I want to send print of "http://www.mysite.it/tifffiles/mytif.tif" directly to printer, this is possible?

Answers & Comments...




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog