Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Tuesday, February 20, 2007 6:16:13 AM(UTC)

blitzy  
blitzy

Groups: Registered
Posts: 16


I followed the sample code provided in the documentation for Print a Real Image Size in Inches and also tried the code in the VB Main Demo but still cannot get any of my documents to print correctly. The documents are printed much smaller than the original size. I am using LEADTOOLS v14.5 build 37 for NET. Also, is it possible to set the paper size to legal for each print job? How?

Here's the first code that I used:
    Private Sub mnu_ScanPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnu_ScanPrint.Click
        ' Check for printer on this machine
        If (Not IsNothing(PrinterSettings.InstalledPrinters)) And (PrinterSettings.InstalledPrinters.Count > 0) Then
            If Not prt_ScanDoc Is Nothing Then
                prt_ScanDoc.Print()
            End If
        End If
    End Sub

    Private Sub prt_ScanDoc_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles prt_ScanDoc.PrintPage
        Dim Image As IRasterImage
        Dim Printer As New RasterImagePrinter

        Image = RasterImageViewer1.Image
        Printer.Print(Image, Image.Page, e)
    End Sub


This is the second set of code that I tried after the first didn't work:
    Private Sub mnu_ScanPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnu_ScanPrint.Click
        ' Check for printer on this machine
        If (Not IsNothing(PrinterSettings.InstalledPrinters)) And (PrinterSettings.InstalledPrinters.Count > 0) Then
            If Not prt_ScanDoc Is Nothing Then
                prt_ScanDoc.Print()
            End If
        End If
    End Sub

Private Sub prt_ScanDoc_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles prt_ScanDoc.PrintPage
        Dim TotalWidth As Single
        Dim TotalHeight As Single
        Dim ImageWidth As Single
        Dim ImageHeight As Single
        Dim ScanGraphics As Graphics
        Dim Ratio As Single
        Dim RasterRectangle As RectangleF
        Dim RasterProp As RasterPaintProperties

        ' Print current document displayed in RasterImageViewer1
        ImageWidth = RasterImageViewer1.Image.ImageWidth * (RasterImageViewer1.Image.XResolution / e.Graphics.DpiX)
        ImageHeight = RasterImageViewer1.Image.ImageHeight * (RasterImageViewer1.Image.YResolution / e.Graphics.DpiY)

        ScanGraphics = RasterImageViewer1.CreateGraphics

        Try
            TotalWidth = e.MarginBounds.Width * (e.Graphics.DpiX / ScanGraphics.DpiX)
            TotalHeight = e.MarginBounds.Height * (e.Graphics.DpiY / ScanGraphics.DpiY)
        Catch ex As System.Exception
            My.Application.Log.WriteException(ex)
        Finally
            ScanGraphics.Dispose()
        End Try

        Ratio = TotalWidth / ImageWidth
        If ((Ratio * ImageHeight) > TotalHeight) Then
            Ratio = TotalHeight / ImageHeight
        End If

        RasterRectangle = New RectangleF(e.MarginBounds.Left, e.MarginBounds.Top, 3.8 * ImageWidth, 3.8 * ImageHeight)
        RasterProp = RasterPaintProperties.Default
        RasterProp.PaintDisplayMode = RasterPaintDisplayModeFlags.ScaleToGray
        RasterImageViewer1.Image.Paint(e.Graphics, Rectangle.Round(RasterRectangle), RasterProp)
    End Sub
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Wednesday, February 21, 2007 11:15:43 AM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 764


Your second code example looks like it is close to the "Print a Real Image Size in Inches" but with a couple minor modifications.  Where does 3.8 come from?  In our sample you would be using the Ratio calculated from TotalHeight / ImageHeight.  Was this just trial and error to get the desired result?

Are you sure that your image is printing incorrectly?  The point of this topic is to have the image print exactly the size it should be on paper.  This will take into consideration your image's DPI.  If your image is something like 300x600 pixels and it's DPI is 300, then your image on paper will only be 1x2 inches. 

As for changing the paper size, you should be able to do this by using the System.Drawing.Printing.PrintDocument class' DefaultPageSettings.PaperSize property.  Something like this would do the trick:


Dim pd As New Printing.PrintDocument
pd.DefaultPageSettings.PaperSize = New PaperSize("Letter", 850, 1400)


If you are still having problems, please send us the file you are trying to print as well and a scan of the page you printed with your code.

NOTE: If you are attaching a project or file to the forums...
1.) Zip the file(s) up.
2.) Make sure it is less than 5 MB.  If it is larger, please send an email to support@leadtools.com or  give us your email address and we'll send you FTP instructions.
3.) Remove ANY AND ALL unlock codes and LEADTOOLS DLLs.
4.) Do not click the preview button, the attachment will not show up when you post it.
 
If you do not wish to post your file(s) on the forum since they are publically viewable, please send an email to support@leadtools.com and make sure that you include a link to this forum post.

 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.086 seconds.