Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement --page-height and --page-width #401

Closed
kenodressel opened this issue Feb 20, 2022 · 28 comments
Closed

Implement --page-height and --page-width #401

kenodressel opened this issue Feb 20, 2022 · 28 comments
Assignees
Milestone

Comments

@kenodressel
Copy link

Describe the bug

I have a FUJITSU fi-6130dj scanner. It is well supported with sane but I can not scan a full A4 page (297mm). At the moment the max setting on the scanservjs frontend is 279.364mm in height. I searched the internet a bit and found this thread from 2011: https://alioth-lists.debian.net/pipermail/sane-devel/2015-January/032999.html which seems to tackle a similar problem.

Expected behavior

I would like to use the full scan range of y = 0..879.489mm and x = 0..224.846mm

Client:

  • Browser: Firefox
  • Version: 96.0.3

Server:

  • OS: Debian 10
  • Runs in Docker and scanner is passed through via USB mapping

Logs

Device Info
[2022-02-20T19:57:53.962Z] DEBUG (Devices): Device list:  device `fujitsu:fi-6130dj:105436' is a FUJITSU fi-6130dj scanner
[2022-02-20T19:57:54.071Z] DEBUG (Devices): Device features:  
All options specific to device `fujitsu:fi-6130dj:105436':
  Standard:
    --source ADF Front|ADF Back|ADF Duplex [ADF Front]
        Selects the scan source (such as a document-feeder).
    --mode Lineart|Halftone|Gray|Color [Lineart]
        Selects the scan mode (e.g., lineart, monochrome, or color).
    --resolution 50..600dpi (in steps of 1) [600]
        Sets the resolution of the scanned image.
  Geometry:
    --page-width 0..224.846mm (in steps of 0.0211639) [215.872]
        Specifies the width of the media.  Required for automatic centering of
        sheet-fed scans.
    --page-height 0..879.489mm (in steps of 0.0211639) [279.364]
        Specifies the height of the media.
    -l 0..215.872mm (in steps of 0.0211639) [0]
        Top-left x position of scan area.
    -t 0..279.364mm (in steps of 0.0211639) [0]
        Top-left y position of scan area.
    -x 0..215.872mm (in steps of 0.0211639) [215.872]
        Width of scan-area.
    -y 0..279.364mm (in steps of 0.0211639) [279.364]
        Height of scan-area.
  Enhancement:
    --brightness -127..127 (in steps of 1) [0]
        Controls the brightness of the acquired image.
    --contrast -127..127 (in steps of 1) [0]
        Controls the contrast of the acquired image.
    --threshold 0..255 (in steps of 1) [0]
        Select minimum-brightness to get a white point
    --rif[=(yes|no)] [no]
        Reverse image format
    --ht-type Default|Dither|Diffusion [inactive]
        Control type of halftone filter
    --ht-pattern 0..3 (in steps of 1) [inactive]
        Control pattern of halftone filter
    --emphasis -128..127 (in steps of 1) [0]
        Negative to smooth or positive to sharpen image
    --variance 0..255 (in steps of 1) [0]
        Set SDTC variance rate (sensitivity), 0 equals 127
  Advanced:
    --ald[=(yes|no)] [no]
        Scanner detects paper lower edge. May confuse some frontends.
    --df-action Default|Continue|Stop [Default]
        Action following double feed error
    --df-skew[=(yes|no)] [inactive]
        Enable double feed error due to skew
    --df-thickness[=(yes|no)] [inactive]
        Enable double feed error due to paper thickness
    --df-length[=(yes|no)] [inactive]
        Enable double feed error due to paper length
    --df-diff Default|10mm|15mm|20mm [inactive]
        Difference in page length to trigger double feed error
    --bgcolor Default|White|Black [Default]
        Set color of background for scans. May conflict with overscan option
    --dropoutcolor Default|Red|Green|Blue [Default]
        One-pass scanners use only one color during gray or binary scanning,
        useful for colored paper or ink
    --buffermode Default|Off|On [Off]
        Request scanner to read pages quickly from ADF into internal memory
    --prepick Default|Off|On [Default]
        Request scanner to grab next page from ADF
    --overscan Default|Off|On [Default]
        Collect a few mm of background on top side of scan, before paper
        enters ADF, and increase maximum scan area beyond paper size, to allow
        collection on remaining sides. May conflict with bgcolor option
    --sleeptimer 0..60 (in steps of 1) [0]
        Time in minutes until the internal power supply switches to sleep mode
    --lowmemory[=(yes|no)] [no]
        Limit driver memory usage for use in embedded systems. Causes some
        duplex transfers to alternate sides on each call to sane_read. Value of
        option 'side' can be used to determine correct image. This option
        should only be used with custom front-end software.
    --side[=(yes|no)] [no] [read-only]
        Tells which side (0=front, 1=back) of a duplex scan the next call to
        sane_read will return.
    --hwdeskewcrop[=(yes|no)] [no]
        Request scanner to rotate and crop pages digitally.
    --swdeskew[=(yes|no)] [no]
        Request driver to rotate skewed pages digitally.
    --swdespeck 0..9 (in steps of 1) [0]
        Maximum diameter of lone dots to remove from scan.
    --swcrop[=(yes|no)] [no]
        Request driver to remove border from pages digitally.
    --swskip 0..100% (in steps of 0.100006) [0]
        Request driver to discard pages with low percentage of dark pixels
  Sensors:
    --top-edge[=(yes|no)] [no] [hardware]
        Paper is pulled partly into ADF
    --a3-paper[=(yes|no)] [no] [hardware]
        A3 paper detected
    --b4-paper[=(yes|no)] [no] [hardware]
        B4 paper detected
    --a4-paper[=(yes|no)] [no] [hardware]
        A4 paper detected
    --b5-paper[=(yes|no)] [no] [hardware]
        B5 paper detected
    --page-loaded[=(yes|no)] [no] [hardware]
        Page loaded
    --omr-df[=(yes|no)] [no] [hardware]
        OMR or double feed detected
    --cover-open[=(yes|no)] [no] [hardware]
        Cover open
    --power-save[=(yes|no)] [no] [hardware]
        Scanner in power saving mode
    --email[=(yes|no)] [no] [hardware]
        Email button
    --manual-feed[=(yes|no)] [no] [hardware]
        Manual feed selected
    --scan[=(yes|no)] [no] [hardware]
        Scan button
    --function <int> [1] [hardware]
        Function character on screen
    --double-feed[=(yes|no)] [no] [hardware]
        Double feed detected
    --error-code <int> [32] [hardware]
        Hardware error code
    --skew-angle <int> [0] [hardware]
        Requires black background for scanning
@kenodressel kenodressel changed the title Unable to use the full page height Unable to use the full page height and width in FUJITSU fi-6130dj Feb 20, 2022
@sbs20
Copy link
Owner

sbs20 commented Feb 20, 2022

@kenodressel
Copy link
Author

Thats amazing! I will try it today :)

@kenodressel
Copy link
Author

So i created a config:

module.exports = {
  afterDevices(devices) {
    devices
      .filter(d => d.id.includes('fujitsu'))
      .forEach(device => {
        device.features['--page-height'].default = 297;
        device.features['-l'].limits = [0, 210];
        device.features['-t'].limits = [0, 297];
        device.features['-x'].default = 210;
        device.features['-x'].limits = [0, 210];
        device.features['-y'].default = 297;
        device.features['-y'].limits = [0, 297];
      });
  }
}

which gets picked up correctly but the problem is that the cli argument --page-height is not set in the scan call:

[2022-02-21T10:18:34.924Z] DEBUG (Process): /usr/bin/scanimage -d 'fujitsu:fi-6130dj:105436' --mode 'Gray' --source 'ADF Duplex' --resolution 100 -l 0 -t 0 -x 210 -y 297 --format 'tiff' --brightness 10 --contrast 0 > data/temp/~tmp-scan-0-0001.tif > data/preview/preview.tif,  undefined , {"encoding":"binary","shell":true,"maxBuffer":16384,"ignoreErrors":false}

therefore we run into the issue described here: https://alioth-lists.debian.net/pipermail/sane-devel/2015-January/032999.html

I checked and ran the following command manually:

/usr/bin/scanimage -d 'fujitsu:fi-6130dj:105436' --mode 'Gray' --source 'ADF Duplex' --page-height 297 --resolution 100 -l 0 -t 0 -x 210 -y 297 --format 'tiff' --brightness 10 --contrast 0 > data/temp/~tmp-scan-0-0001.tif > data/preview/preview.tif

and this works like a charm. Can I force the param to be set?

@sbs20
Copy link
Owner

sbs20 commented Feb 21, 2022

Hmm. It's not configurable. I'd be up for making it configurable but probably won't get to it all that quickly.

You could manually add a line somewhere round here though:

cmdBuilder.arg('--resolution', params.resolution);

If it works then we can figure something out.

@kenodressel
Copy link
Author

kenodressel commented Feb 21, 2022

I guess something like

    if ('page-height' in params) {
      cmdBuilder.arg('--page-height', params.pageHeight);
    }

should cover this case right? By default it would not be set but if i overwrite the device configuration it should be appended. As far as I understood the mailing list the --page-height and --page-width only acts as the upper bound of possible scans while the -x and -y. I tested it with --page-height 500 and it made no difference to the scan vs --page-height 297. Official Doc indicates that this might be a fujitsu specific settings for scanners with ADFs, a bit niche. If you feel like this should not be part of the main repo I would be fine with forking.

@sbs20
Copy link
Owner

sbs20 commented Feb 21, 2022

Should --page-height be a constant for any given scanner? If so, then I'd likely make it a config variable rather than a scanrequest attribute. If that's the case, then I'll put it in the mainline code and let people override it.

@kenodressel
Copy link
Author

kenodressel commented Feb 21, 2022

As far as I understood the documentation it seems that this is an attribute that is supported by some scanners. Mostly the ones with ADF but eg. some brother scanners do seem to have some troubles with it. Gut feeling from my side is I would not set it by default but rather as an opt-in.

@sbs20
Copy link
Owner

sbs20 commented Feb 23, 2022

Agreed. But would anyone ever need to change --page-height for a specific scanner? i.e. you need yours to be 297 - would you ever change that? If not, then it can go in config.local.js, but if you do need to change it, then it needs to go in the UI / ScanRequest

@kenodressel
Copy link
Author

No i think can be set once and forget about it afterwards. In my case I would probably set it to 800 or similar but the x and y limits are the options i want to modify in the ui.

@sbs20 sbs20 self-assigned this Feb 24, 2022
@sbs20 sbs20 added this to the v2.21.0 milestone Mar 7, 2022
sbs20 added a commit that referenced this issue Mar 9, 2022
@sbs20 sbs20 added the dev label Mar 9, 2022
@sbs20 sbs20 added the staging label Mar 18, 2022
@sbs20 sbs20 closed this as completed Mar 21, 2022
@tefracky
Copy link

tefracky commented May 28, 2022

Agreed. But would anyone ever need to change --page-height for a specific scanner? i.e. you need yours to be 297 - would you ever change that? If not, then it can go in config.local.js, but if you do need to change it, then it needs to go in the UI / ScanRequest

Well, you are right, I want to use 297 for my scanners and have a problem: For my Fujitsu scanner, I have to set --page-heigt and it works fine using

module.exports = {
  afterConfig(config) {
    config.scanimageAdditionalArguments = {
      '--page-height': 297
    };
  }
}

However, then I cannot use my Samsung scanner (SCX 3405 FW). Hence, page-height must not be set. So is it possible to set '--page-height': 297 per device?

@sbs20 sbs20 reopened this May 29, 2022
@tefracky
Copy link

tefracky commented Jun 3, 2022

Does anyone have an idea how to solve this problem?

@phiresky
Copy link

phiresky commented Jun 5, 2022

I can confirm the same issue happens for a Fujitsu Fi-7160. I can't select A4 even though the scanner supports dimensions of up to 224mm (width) and 2750mm (height). It even detects the page size if you set it higher, but scanservjs cuts the pages off. It doesn't seem to detect the maximum scannable size correctly, in the UI the max I can select is 215.8x279.3

@phiresky
Copy link

phiresky commented Jun 5, 2022

Here's the relevant help section from my scanner:

  Geometry:
    --page-width 0..224.846mm (in steps of 0.0211639) [215.872]
        Specifies the width of the media.  Required for automatic centering of
        sheet-fed scans.
    --page-height 0..2750.47mm (in steps of 0.0211639) [279.364]
        Specifies the height of the media.
    -l 0..215.872mm (in steps of 0.0211639) [0]
        Top-left x position of scan area.
    -t 0..279.364mm (in steps of 0.0211639) [0]
        Top-left y position of scan area.
    -x 0..215.872mm (in steps of 0.0211639) [215.872]
        Width of scan-area.
    -y 0..279.364mm (in steps of 0.0211639) [279.364]
        Height of scan-area.

It seems like the scanservjs takes the ranges from l,t,x,y, which are apparently constrained by the defaults for page-width and page-height (not their respective maximums)

@sbs20 sbs20 modified the milestones: v2.21.0, v2.22.0 Oct 21, 2022
sbs20 added a commit that referenced this issue Dec 22, 2022
Issue #401

The original fix for #401 involved adding additional arguments for `scanimage` but globally. This had a bad side-effect for users with multiple scanners with differing characteristics.

The new solution treats these additional parameters as first class citizens and automatically adds them as required. The UI still does not present the user with the ability to override the values - although the API supports it should that become a requirement in the future. As a result the app always uses the default values provided by SANE.

The net result is that `scanimageAdditionalParameters` has been removed and is ignored. And no customisation should be required at all. However, in the event that the values provided by SANE are unsatisfactory, then it is possible to override the value as per all other device customisation - this has been noted in the `config.md` doc.

Other changes:
* Updated the yml used by swagger to refect the new parameters
* There is more granular checking of the individual geometry elements now - the previous behaviour relied on a bad assumption that `x`, `y`, `t` and `l` were always there or always not.
* Additional unit tests
@sbs20
Copy link
Owner

sbs20 commented Dec 22, 2022

I'm hoping that PR #503 resolves this issue properly. I've added notes about the implementation in the PR. If anyone is able to test, then that would be great. You may still need to tinker with the device settings - how to do so is documented too. You can see the changes in the PR.

@sbs20 sbs20 changed the title Unable to use the full page height and width in FUJITSU fi-6130dj Implement --page-height and --page-width Dec 22, 2022
@sbs20 sbs20 added this to the v2.24.0 milestone Dec 22, 2022
@tefracky
Copy link

Thanks a lot, I will give it a try!

@freeman2706
Copy link

Hi,
I have the same problem, with a canon DR-C125 , where the maximum size in height is 279.3cm. Unable to switch to A4.
I have already added the different lines "module.exports = {"
But nothing works, any idea?

@freeman2706
Copy link

Hi,
update.
I reinstalled Debian, and just installed XSane, and obviously, it's the latter that limits to 27.9cm, if I force it to 29 it works, but on reboot, it goes back to 27.9cm.
Do you have an idea of where we can configure hard 29cm, I did not find anything?

Thank you

sane

@JMacalinao
Copy link

I have a Fujitsu fi-7260. When I change the source to Flatbed, I get the following error:

scanimage: attempted to set inactive option page-height

It seems the page-height option is inactive with the Flatbed source, but I do need this option for ADF source to be able to properly scan Legal-size documents. I've tried both the current implementation and #503 to no avail. Thoughts?

@sbs20
Copy link
Owner

sbs20 commented Dec 30, 2022

I have a Fujitsu fi-7260. When I change the source to Flatbed, I get the following error:

scanimage: attempted to set inactive option page-height

It seems the page-height option is inactive with the Flatbed source, but I do need this option for ADF source to be able to properly scan Legal-size documents. I've tried both the current implementation and #503 to no avail. Thoughts?

@JMacalinao

Thank you - that's really helpful.

Ok. So if the source = Flatbed then I need to exclude --page-height and --page-width. The question is, does it work as is for ADF? Or do the geometry settings (-l, -t, -x and -y) cause problems?

Actually - can you share the output of scanimage -A for this scanner please? I don't have an example with both Flatbed and ADF where one requires --page-height - it will help with unit tests.

@JMacalinao
Copy link

@sbs20 Sure thing. Here's the output. First is the defaults (with Flatbed as source):

scanimage -A
Output format is not set, using pnm as a default.

All options specific to device `net:<IP address>:fujitsu:fi-7260:1208958':
  Standard:
    --source Flatbed|ADF Front|ADF Back|ADF Duplex [Flatbed]
        Selects the scan source (such as a document-feeder).
    --mode Lineart|Halftone|Gray|Color [Lineart]
        Selects the scan mode (e.g., lineart, monochrome, or color).
    --resolution 50..600dpi (in steps of 1) [600]
        Sets the resolution of the scanned image.
  Geometry:
    --page-width 0..224.846mm (in steps of 0.0211639) [inactive]
        Specifies the width of the media.  Required for automatic centering of
        sheet-fed scans.
    --page-height 0..2750.47mm (in steps of 0.0211639) [inactive]
        Specifies the height of the media.
    -l 0..227.809mm (in steps of 0.0211639) [0]
        Top-left x position of scan area.
    -t 0..296.972mm (in steps of 0.0211639) [0]
        Top-left y position of scan area.
    -x 0..227.809mm (in steps of 0.0211639) [215.872]
        Width of scan-area.
    -y 0..296.972mm (in steps of 0.0211639) [279.364]
        Height of scan-area.
  Enhancement:
    --brightness -127..127 (in steps of 1) [0]
        Controls the brightness of the acquired image.
    --contrast -127..127 (in steps of 1) [0]
        Controls the contrast of the acquired image.
    --threshold 0..255 (in steps of 1) [0]
        Select minimum-brightness to get a white point
    --rif[=(yes|no)] [no]
        Reverse image format
    --ht-type Default|Dither|Diffusion [inactive]
        Control type of halftone filter
    --ht-pattern 0..3 (in steps of 1) [inactive]
        Control pattern of halftone filter
    --emphasis -128..127 (in steps of 1) [0]
        Negative to smooth or positive to sharpen image
    --variance 0..255 (in steps of 1) [0]
        Set SDTC variance rate (sensitivity), 0 equals 127
  Advanced:
    --ald[=(yes|no)] [no]
        Scanner detects paper lower edge. May confuse some frontends.
    --df-action Default|Continue|Stop [Default]
        Action following double feed error
    --df-skew[=(yes|no)] [inactive]
        Enable double feed error due to skew
    --df-thickness[=(yes|no)] [inactive]
        Enable double feed error due to paper thickness
    --df-length[=(yes|no)] [inactive]
        Enable double feed error due to paper length
    --df-diff Default|10mm|15mm|20mm [inactive]
        Difference in page length to trigger double feed error
    --df-recovery Default|Off|On [On]
        Request scanner to reverse feed on paper jam
    --paper-protect Default|Off|On [On]
        Request scanner to predict jams in the ADF
    --adv-paper-protect Default|Off|On [On]
        Request scanner to predict jams in the ADF using improved sensors
    --bgcolor Default|White|Black [Default]
        Set color of background for scans. May conflict with overscan option
    --dropoutcolor Default|Red|Green|Blue [Default]
        One-pass scanners use only one color during gray or binary scanning,
        useful for colored paper or ink
    --buffermode Default|Off|On [Off]
        Request scanner to read pages quickly from ADF into internal memory
    --prepick Default|Off|On [Default]
        Request scanner to grab next page from ADF
    --overscan Default|Off|On [Default]
        Collect a few mm of background on top side of scan, before paper
        enters ADF, and increase maximum scan area beyond paper size, to allow
        collection on remaining sides. May conflict with bgcolor option
    --sleeptimer 0..60 (in steps of 1) [0]
        Time in minutes until the internal power supply switches to sleep mode
    --offtimer 0..960 (in steps of 1) [240]
        Time in minutes until the internal power supply switches the scanner
        off. Will be rounded to nearest 15 minutes. Zero means never power off.
    --lowmemory[=(yes|no)] [no]
        Limit driver memory usage for use in embedded systems. Causes some
        duplex transfers to alternate sides on each call to sane_read. Value of
        option 'side' can be used to determine correct image. This option
        should only be used with custom front-end software.
    --side[=(yes|no)] [no] [read-only]
        Tells which side (0=front, 1=back) of a duplex scan the next call to
        sane_read will return.
    --hwdeskewcrop[=(yes|no)] [no]
        Request scanner to rotate and crop pages digitally.
    --swdeskew[=(yes|no)] [no]
        Request driver to rotate skewed pages digitally.
    --swdespeck 0..9 (in steps of 1) [0]
        Maximum diameter of lone dots to remove from scan.
    --swcrop[=(yes|no)] [no]
        Request driver to remove border from pages digitally.
    --swskip 0..100% (in steps of 0.100006) [0]
        Request driver to discard pages with low percentage of dark pixels
  Sensors:
    --top-edge[=(yes|no)] [no] [hardware]
        Paper is pulled partly into ADF
    --a3-paper[=(yes|no)] [no] [hardware]
        A3 paper detected
    --b4-paper[=(yes|no)] [no] [hardware]
        B4 paper detected
    --a4-paper[=(yes|no)] [no] [hardware]
        A4 paper detected
    --b5-paper[=(yes|no)] [no] [hardware]
        B5 paper detected
    --page-loaded[=(yes|no)] [no] [hardware]
        Page loaded
    --omr-df[=(yes|no)] [no] [hardware]
        OMR or double feed detected
    --cover-open[=(yes|no)] [no] [hardware]
        Cover open
    --power-save[=(yes|no)] [no] [hardware]
        Scanner in power saving mode
    --email[=(yes|no)] [no] [hardware]
        Email button
    --manual-feed[=(yes|no)] [no] [hardware]
        Manual feed selected
    --scan[=(yes|no)] [no] [hardware]
        Scan button
    --function <int> [0] [hardware]
        Function character on screen
    --double-feed[=(yes|no)] [no] [hardware]
        Double feed detected
    --error-code <int> [0] [hardware]
        Hardware error code
    --skew-angle <int> [0] [hardware]
        Requires black background for scanning

And here's one with ADF Front as source (truncated since only the Geometry section changed):

scanimage -A --source "ADF Front"
Output format is not set, using pnm as a default.

All options specific to device `net:<IP address>:fujitsu:fi-7260:1208958':
  Standard:
    --source Flatbed|ADF Front|ADF Back|ADF Duplex [ADF Front]
        Selects the scan source (such as a document-feeder).
    --mode Lineart|Halftone|Gray|Color [Lineart]
        Selects the scan mode (e.g., lineart, monochrome, or color).
    --resolution 50..600dpi (in steps of 1) [600]
        Sets the resolution of the scanned image.
  Geometry:
    --page-width 0..224.846mm (in steps of 0.0211639) [215.872]
        Specifies the width of the media.  Required for automatic centering of
        sheet-fed scans.
    --page-height 0..2750.47mm (in steps of 0.0211639) [279.364]
        Specifies the height of the media.
    -l 0..215.872mm (in steps of 0.0211639) [0]
        Top-left x position of scan area.
    -t 0..279.364mm (in steps of 0.0211639) [0]
        Top-left y position of scan area.
    -x 0..215.872mm (in steps of 0.0211639) [215.872]
        Width of scan-area.
    -y 0..279.364mm (in steps of 0.0211639) [279.364]
        Height of scan-area.
...

@sbs20
Copy link
Owner

sbs20 commented Dec 30, 2022

@JMacalinao that is really really helpful.

And kind of bad! It's opened up a whole can of worms in that I did not know you coud run scanimage like that with a source argument. This is going to need some thought.

@sbs20
Copy link
Owner

sbs20 commented Dec 30, 2022

I have a Fujitsu fi-7260. When I change the source to Flatbed, I get the following error:

scanimage: attempted to set inactive option page-height

It seems the page-height option is inactive with the Flatbed source, but I do need this option for ADF source to be able to properly scan Legal-size documents. I've tried both the current implementation and #503 to no avail. Thoughts?

So just looking at this again, I think that #503 will help in that the Flatbed option should not throw an error since it excludes the option. But it won't help with the ADF option since it thinks that --page-height is inactive.

I think I'm going to merge #503 in to mainline for now since it's better than it was and at least enables users to override --page-height per device. I'm going to open a new issue to deal with this new information - see #510

sbs20 added a commit that referenced this issue Dec 30, 2022
Issue #401

The original fix for #401 involved adding additional arguments for `scanimage` but globally. This had a bad side-effect for users with multiple scanners with differing characteristics.

The new solution treats these additional parameters as first class citizens and automatically adds them as required. The UI still does not present the user with the ability to override the values - although the API supports it should that become a requirement in the future. As a result the app always uses the default values provided by SANE.

The net result is that `scanimageAdditionalParameters` has been removed and is ignored. And no customisation should be required at all. However, in the event that the values provided by SANE are unsatisfactory, then it is possible to override the value as per all other device customisation - this has been noted in the `config.md` doc.

Other changes:
* Updated the yml used by swagger to refect the new parameters
* There is more granular checking of the individual geometry elements now - the previous behaviour relied on a bad assumption that `x`, `y`, `t` and `l` were always there or always not.
* Additional unit tests
@tefracky
Copy link

So, I scanned a lot of documents today and the following command worked fine:

scanimage -d fujitsu:fi-7160:1622533 --batch="/home/pi/nextcloud/Scans/1 - Gescannt/filename- %d.tiff" --format tiff --resolution=300 -p --page-width 210 --page-height 297 --source 'ADF Duplex' --mode Lineart

Config:

/* eslint-disable no-unused-vars */

/**
 * This file is ignored. If you want to apply overrides, make a copy in this
 * location and name it `config.local.js`. Then make the necessary changes.
 */
module.exports = {
  /**
   * @param {Configuration} config
   */
  afterConfig(config) {
    /**
     * Override any of the following values
     */
    // config.host = '127.0.0.1';
    config.port = 8090;
    // config.devices = [];
    config.ocrLanguage = 'deu';
    config.log.level = 'DEBUG';
    // config.scanimage = '/usr/bin/scanimage';
    // config.convert = '/usr/bin/convert';
    // config.tesseract = '/usr/bin/tesseract';
    // config.previewResolution = 100;
    config.scanimageAdditionalArguments = {
//      Nur für Fujitsu
//      '--page-height': 297
    };

    config.outputDirectory = '/home/pi/nextcloud/Scans/1 - Gescannt';

    // By default paths with `..` or `/` are not allowed
    config.allowUnsafePaths = true;

    /* When all scans are complete, the filenames are all piped into stdin of the
    first pipeline command. It would be nicer to pipe the binary output of scanimage
    but that doesn't work with multipage scans so we have no choice but to write to
    the filesystem.

    The stdout of each pipeline feeds into the stdin of the next. Although clumsy in
    some respects (especially where we have to write temporary files and then list
    them) it at least provides a means of user configuration with "just" shell
    scripting.

    The overall output of the pipelines (i.e. the last pipeline output) must be a
    list of the files you want kept. The convention is to output files of the form
    `scan-0000.ext` but it's convention only. You can output whatever you want. If
    multiple files are output then the results will be zipped into a single file.

    Each command is executed with the CWD set to the temporary location so no
    directory traversal is required. Pipeline commands are always read from this
    file (and never from the browser request, even though it is sent). It would be
    possible to subvert these commands for malicious use, but it doesn't give any
    further privilege than the user account running scanservjs and still requires
    access to this file. You obviously should not be running as root.

    Some useful pointers:
    - `convert` can read a list of files from a file with the @ argument. The `-`
      file is stdin. So `convert @- -argument output` performs the conversion on
      each file piped into stdin
    - `tesseract` has a similar feature using `-c stream_filelist=true`
    - `convert` can also output multiple files if you use an output filename with
      `%d` in it. C string style formatting is available so you can do things like
      output to `scan-%04d.jpg`. Formats which do not support multiple pages must
      use this option. Multi-page formats including PDF and TIF do not use this
      option.
    - if you just wanted to take a filename from stdin and have its content read out
      you could `xargs cat` provided there were no spaces or commas in the filename
      (which there won't be)
    */

    /**
     * Create a custom pipeline
     */
    const myPipelines = [
    //   {
    //     extension: 'jpg',
    //     description: 'JPG | Super quality',
    //     commands: [
    //       'convert @- -quality 96 scan-%04d.jpg',
    //       'ls scan-*.*'
    //     ]
    //   }
	  {
        extension: 'pdf',
        description: '1 - @:pipeline.ocr | PDF (TIFF | @:pipeline.lzw-compressed)',
        commands: [
          'convert @- -compress lzw tmp-%04d.tif && ls tmp-*.tif',
//          'convert @- tmp-%d.tif && ls tmp-*.tif',
          '${config.tesseract} -l ${config.ocrLanguage} -c stream_filelist=true - - pdf > scan-0001.pdf',
          'ls scan-*.*'
        ]
      },

      {
        extension: 'pdf',
        description: '2 - PDF (TIFF | @:pipeline.lzw-compressed)',
        commands: [
          'convert @- -compress lzw tmp-%04d.tif && ls tmp-*.tif',
//          'convert @- tmp-%d.tif && ls tmp-*.tif',
          'convert @- scan-0000.pdf',
          'ls scan-*.*'
        ]
      }
    ];

    /**
     * Replace all existing pipelines
     */
    // config.pipelines = myPipelines;

    /**
     * Append to existing pipelines
     */
    config.pipelines = myPipelines.concat(config.pipelines);
  },

  /**
   * This method is called after devices have been read (from the scanner or
   * disk) but before being returned to anything else. You can use this to
   * override default settings from the scanner, or resolution options or
   * anything else for that matter.
   *
   * Note that the devices parameter is an array. Most systems will likely just
   * have one scanner, but that's not always true. Therefore you will need to
   * identify the scanner by id or index. It's also possible that the list will
   * be empty if there's an upstream error.
   * @param {ScanDevice[]} devices
   */
  afterDevices(devices) {
    /**
     * Example code below
     */
    devices
      .filter(d => d.id.includes('fujitsu'))
      .forEach(device => {
        device.features['--mode'].default = 'Lineart';
        device.features['--resolution'].default = 300;
      //   device.features['--resolution'].options = [150, 300, 600];
      //   device.features['--brightness'].default = 10;
      //   device.features['--contrast'].default = 20;
        device.features['--page-height'] = {
          default: 297,
          limits:  [0, 297]
        };
        device.features['--page-width'] = {
          default: 210,
          limits:  [5, 215]
        };

        device.features['-l'].limits = [5, 215];
        device.features['-t'].limits = [0, 297];
        device.features['-x'].limits = [0, 210];
        device.features['-y'].limits = [0, 297];

        device.features['-x'].default = 210;
        device.features['-y'].default = 297;
      );

    devices
      .filter(d => d.id.includes('samsung'))
      .forEach(device => {
        device.features['--mode'].default = 'Lineart';
        device.features['--resolution'].default = 300;
      //   device.features['--resolution'].options = [150, 300, 600];
      //   device.features['--brightness'].default = 10;
      //   device.features['--contrast'].default = 20;

        device.features['-l'].limits = [0, 210]
        device.features['-t'].limits = [0, 297];
        device.features['-x'].limits = [0, 210];
        device.features['-y'].limits = [0, 297];

        device.features['-x'].default = 210;
        device.features['-y'].default = 297;
      });
  }
};

@JMacalinao
Copy link

JMacalinao commented Dec 30, 2022

So just looking at this again, I think that #503 will help in that the Flatbed option should not throw an error since it excludes the option. But it won't help with the ADF option since it thinks that --page-height is inactive.

Looks like it's still including --page-height with the Flatbed source:

[2022-12-30T16:10:42.015Z] ERROR (Http): Error: /usr/bin/scanimage -d 'net:<IP>:fujitsu:fi-7260:1208958' --mode 'Color' --source 'Flatbed' --resolution 300 --page-height 356 -l 0 -t 0 -x 216 -y 297 --format 'tiff' --brightness 0 --contrast 0 -o '../server/data/temp/~tmp-scan-0-0001.tif' exited with code: 1, stderr: scanimage: attempted to set inactive option page-height

I can confirm ADF source ignored --page-height since it thought that option was inactive.

I'm on the mainline now, using the config below:

module.exports = {
  //afterConfig(config) {
  //  config.scanimageAdditionalArguments = {
  //    '--page-height': 356
  //  };
  //},
  afterDevices(devices) {
    devices.filter(d => d.id.includes('fujitsu')) 
      .forEach(device => { 
        device.features['--mode'].default = 'Color';
        device.features['--resolution'].default = 300;
        device.features['--page-height'] = {
          default: 356,
          limits: [0, 356]
        };
        device.features['-t'].limits = [0, 356];
        device.features['-y'].limits = [0, 356];
      });
  }
};

Regardless, I'll just have to wait until #510 is resolved since apparently what I uncovered is a whole different ball game (umm... you're welcome? lol). I'm cool with staying at v2.23 for now.

@sbs20
Copy link
Owner

sbs20 commented Dec 30, 2022

That makes sense - you're specifically overriding the --page-height feature so the app thinks it's enabled.

Which has given me an idea (forgive any mistakes, this is freestyle):

module.exports = {
  afterDevices(devices) {
    // Set common defaults for any usage of this scanner
    devices.filter(d => d.id.includes('fujitsu')) 
      .forEach(device => { 
        device.name = 'Fujitsu (Flatbed)';
        device.features['--mode'].default = 'Color';
        device.features['--resolution'].default = 300;
        device.features['-t'].limits = [0, 356];
        device.features['-y'].limits = [0, 356];
      });

    // Create a clone of the flatbed settings
    const fujitsuAdf = JSON.parse(JSON.stringify(devices.filter(d => d.id.includes('fujitsu'))[0]));
    fujitsuAdf.name = 'Fujitsu (ADF)';
    fujitsuAdf.features['--page-height'] = {
      default: 356,
      limits: [0, 356]
    };

    // Add the clone as a whole new device
    devices.push(fujitsuAdf);
  }
};

@JMacalinao
Copy link

JMacalinao commented Dec 31, 2022

That works for Flatbed. Thanks!

Unfortunately, --page-height is still ignored for the ADF device and source. Been trying to debug this in the past hour. I can see in the request that --page-height is included in the device's features, and I can see it in params in local storage, but disappears on params server-side.

@JMacalinao
Copy link

Figured it out. context.getDevice uses id, but with the config above, there are two devices with the same ID, so it gets the first one (Flatbed device, without the --page-height feature). Can't modify the ID to make it unique since it's used for scanimage. To fix this, I created a new method called getDeviceByName. Pretty sure it's self-explanatory :)

@sbs20 I have it on my fork in the meantime, but if you want this merged, just let me know so I can put up a PR.

@sbs20
Copy link
Owner

sbs20 commented Dec 31, 2022

@sbs20 I have it on my fork in the meantime, but if you want this merged, just let me know so I can put up a PR.

Oh nice one! That's really helpful. I'm retiscent to use name for this purpose since it's not guaranteed to be unique. And this "solution" was only a workaround. But this is definitely helping for #510

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants