header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Print a .bmp file?
Last Post 20 Sep 2010 01:07 PM by George Howarth. 7 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
BustedFlushUser is Offline
New Member
New Member
Posts:97
Avatar

--
16 Sep 2010 05:46 PM
    Is there a way to script printing a .bmp file?

    I saw a post on another forum where someone had suggested using
    [void][reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
    to convert a file from .bmp to .jpg, so I used that to try some things.

    I tried this, but it doesn't work:

    [void][reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
    $img = new-object system.drawing.bitmap "Z:\inkjet_test.bmp"
    $img | out-printer "\\phoenix\882c"

    That prints out a list of stuff that describes the file, but not the image itself.
    Marco ShawUser is Offline
    Veteran Member
    Veteran Member
    Posts:1684
    Avatar

    --
    16 Sep 2010 05:56 PM
    Yeah, I'm going to say you're limited to text using out-printer... You just want to print an image? I might suggest opening it in IE or Word, then printing it. There are some .NET libraries to convert images from one format to another. Take a peak here:
    http://blogs.msdn.com/b/powershell/...83227.aspx
    BustedFlushUser is Offline
    New Member
    New Member
    Posts:97
    Avatar

    --
    16 Sep 2010 07:01 PM
    Yep, I can open it with IE just fine, but I can't seem to print it from there.

    $ie = new-object -comobject internetexplorer.application
    $ie.navigate2("Z:\inkjet_test.bmp")
    $ie.visible = $true

    $ie.print doesn't work.
    $ie | get-member throws an "rpc server unavailable" error

    The statement that out-printer is limited to text gave me an idea. I just want to automate a small print job to keep my inkjet heads fresh. I made a little bmp with basic colors. Could I do it manually? Oh yeah. But that's no fun.

    But I don't absolutely have to print that file, anything that uses a little color would work just as well - even text, but if I remember correctly, only write-host supports -foreground and -background, so that doesn't help.
    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    17 Sep 2010 05:14 AM
    There is no Print() method on the InternetExplorer object, it seems that you have to use the ExecWB() method and provide enumeration values to specify the operation you want IE to carry out. Try this:

    $ie = New-Object -ComObject InternetExplorer.Application
    $ie.Navigate2("Z:\inkjet_test.bmp")
    while ($ie.Busy) { } # Wait for the page to load
    $ie.ExecWB(6, 2) # 6 = print; 2 = don't prompt
    BustedFlushUser is Offline
    New Member
    New Member
    Posts:97
    Avatar

    --
    17 Sep 2010 01:59 PM
    Thanks. So I would use $ie.ExecWB(6)?

    Cannot find an overload for "ExecWB" and the argument count: "1".
    At line:4 char:11
    + $ie.ExecWB <<<< (6)
    + CategoryInfo : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest
    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    17 Sep 2010 02:13 PM
    The second paramter is not optional. You have the following options:

    0 = Carry out the default operation
    1 = Prompt the user
    2 = Don't prompt the user
    3 = Show help
    BustedFlushUser is Offline
    New Member
    New Member
    Posts:97
    Avatar

    --
    17 Sep 2010 03:16 PM
    D'OH! Score one of reading comprehension - I read your comment as 6, print, 2 don't print. I wondered why you'd include a don't print option. :)

    Still didn't work though.

    Exception calling "ExecWB" with "2" argument(s): "Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100 (DR
    AGDROP_E_NOTREGISTERED))"
    At line:4 char:11
    + $ie.ExecWB <<<< (6, 2)
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    20 Sep 2010 01:07 PM

    Try this instead. I think this works (this stupid XPS software keeps giving me a dialog...):

    function Print-Bitmap
    {
        param (
            [System.Drawing.Bitmap]$Bitmap
        )
       
        $printDocument = New-Object System.Drawing.Printing.PrintDocument
       
        Register-ObjectEvent -InputObject $printDocument -EventName PrintPage -SourceIdentifier PrintDocument.PrintPage -Action {
            param (
                [System.Object]$sender,
                [System.Drawing.Printing.PrintPageEventArgs]$e
            )
           
            $e.Graphics.DrawImage($Bitmap, 0, 0)
        }
       
        $printDocument.Print()
    }

    function Download-Image
    {
        param (
            [String]$Url
        )
       
        $webRequest = [System.Net.WebRequest]::Create($Url)
        $webResponse = $webRequest.GetResponse()
        $stream = $webResponse.GetResponseStream()
       
        return New-Object System.Drawing.Bitmap -ArgumentList $stream
    }

    $bitmap = Download-Image -Url "your_url_goes_here"
    Print-Bitmap -Bitmap $bitmap

    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer