cyanfish / naps2-wia

Low-level WIA 2.0/1.0 application library for .NET
MIT License
17 stars 5 forks source link

How to setup paper size? #13

Open JohnDoe2193 opened 1 month ago

JohnDoe2193 commented 1 month ago

I have a Windows Forms application targeting .Net Framework 4.7.2. The function of application is to scan documents using document scanner (flatbed or feeder), display documents on the screen and save the result to PDF. Note that the stack of documents placed in the feeder may contain a mix of Letter and Legal sized pages.

I use NAPS2.Wia component for scanning. If I don't explicitly specify paper size everything works except when Legal size paper is put in the feeder it is treated as a Letter sized paper and bottom of the page is cutoff.

I did find a solution but it is a bit of kludge:

// executed always
int scanResolution = 300; // dpi, user selectable
documentSource.SetProperty(WiaPropertyId.IPS_XRES, scanResolution);
documentSource.SetProperty(WiaPropertyId.IPS_YRES, scanResolution);

Then if the paper source is a feeder I additionally execute this:

int LegalPaperHeight = 14; 
documentSource.SetProperty(WiaPropertyId.IPS_YEXTENT, LegalPaperHeight*scanResolution);

Is there a better way to achieve the same result (I don't really like specifying paper height like that)? Something like paperSize=Auto

cyanfish commented 1 month ago

WIA_IPS_PAGE_SIZE can be set to WIA_PAGE_AUTO, though I don't have those constants predefined in NAPS2.Wia right now so you'd have to define them yourself. documentSource.SetProperty(3097, 100);

Whether it works or not depends on your scanner.

JohnDoe2193 commented 1 month ago

Thanks, the scanner I use is Xerox Duplex Combo Scanner and when I tried what you suggested following exception is thrown:

"Value does not fall within the expected range."