<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ricky Feli</title>
    <description>The latest articles on DEV Community by Ricky Feli (@ricky_feli_2a72a68448cc08).</description>
    <link>https://dev.to/ricky_feli_2a72a68448cc08</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2530765%2F05ebfca5-7977-4468-91a0-5780d3a82cea.jpg</url>
      <title>DEV Community: Ricky Feli</title>
      <link>https://dev.to/ricky_feli_2a72a68448cc08</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ricky_feli_2a72a68448cc08"/>
    <language>en</language>
    <item>
      <title>I need help on Epson Scanner Control uing Python twain.</title>
      <dc:creator>Ricky Feli</dc:creator>
      <pubDate>Sun, 30 Mar 2025 06:32:21 +0000</pubDate>
      <link>https://dev.to/ricky_feli_2a72a68448cc08/i-need-help-on-epson-scanner-control-uing-python-twain-1mnc</link>
      <guid>https://dev.to/ricky_feli_2a72a68448cc08/i-need-help-on-epson-scanner-control-uing-python-twain-1mnc</guid>
      <description>&lt;p&gt;Dear Dev.to!&lt;/p&gt;

&lt;p&gt;Recently I am working on a project that need to control scanner using script.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The purpose&lt;/strong&gt; of the script is to run the scanner with ADF(Auto Document Feed) mode and return the result(Destination Folder, Count of Scanned Images)&lt;/p&gt;

&lt;p&gt;I am using &lt;strong&gt;pytwain&lt;/strong&gt; library for this and current my python version is &lt;strong&gt;3.13.2&lt;/strong&gt;&lt;br&gt;
And the scanner is &lt;strong&gt;Epson 580W&lt;/strong&gt; scanner.&lt;/p&gt;

&lt;p&gt;I want to control the scanning parameters using script. &lt;/p&gt;

&lt;p&gt;Currently I have script that works in flat mode. &lt;/p&gt;

&lt;p&gt;This is current python code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from io import BytesIO
import twain
import tkinter
from tkinter import ttk
import logging
import PIL.ImageTk
import PIL.Image

scanned_image = None


def scan():
    global scanned_image
    with twain.SourceManager(root) as sm:
        # this will show UI to allow user to select source
        src = sm.open_source()
        if src:
            src.request_acquire(show_ui=False, modal_ui=False)
            (handle, remaining_count) = src.xfer_image_natively()
            bmp_bytes = twain.dib_to_bm_file(handle)
            img = PIL.Image.open(BytesIO(bmp_bytes), formats=["bmp"])
            width, height = img.size
            factor = 600.0 / width
            # Storing PhotoImage in global variable to prevent it from being deleted once this function exits
            # since PhotoImage has a __del__ destructor
            scanned_image = PIL.ImageTk.PhotoImage(img.resize(size=(int(width * factor), int(height * factor))))
            frm.destroy()
            ttk.Label(root, image=scanned_image).pack(side="left", fill="both", expand=1)
        else:
            print("User clicked cancel")


logging.basicConfig(level=logging.DEBUG)
root = tkinter.Tk()
frm = ttk.Frame(root, padding=10)
frm.grid()
ttk.Button(frm, text="Scan", command=scan).grid(column=0, row=0)
root.mainloop()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Is there anybody who have experienced with pytwain especially Epson scanner or other scanners in ADF mode?&lt;/p&gt;

&lt;p&gt;I appreciate your help.&lt;/p&gt;

&lt;p&gt;Thanks. &lt;/p&gt;

&lt;h2&gt;
  
  
  PS: I found an github repo that can be useful, but I am not sure about the version. It uses Python 2.7 and 3.9.
&lt;/h2&gt;

&lt;p&gt;This is github repo url: &lt;a href="https://github.com/wlsc10th-info/auto-scan" rel="noopener noreferrer"&gt;https://github.com/wlsc10th-info/auto-scan&lt;/a&gt;&lt;br&gt;
But Currently I already built my codebase with python 3.13.2. &lt;br&gt;
So now I am worring about the version conflict. &lt;/p&gt;

&lt;p&gt;Do you have any experience or solution for this?&lt;/p&gt;

</description>
      <category>help</category>
      <category>epson</category>
      <category>python</category>
      <category>scanner</category>
    </item>
  </channel>
</rss>
