qzind / qz-print

Archive for legacy qz-print versions (1.8, 1.9). See https://github.com/qzind/tray for modern versions.
Other
141 stars 101 forks source link

Unable to change image size #152

Closed klabarge closed 8 years ago

klabarge commented 8 years ago

Tested on Windows 10, QZ Tray 2.0 alpha-5

I was unable to change the size of an image (base64) by adjusting the width and height values.

Changing the units between mm and in did result in different sizes, but the height and width values seemed to be ignored.

Here is the configuration I was using:

var config = qz.configs.create('Microsoft XPS Document Writer', {units: 'mm',  size: { width: 58, height: 32 }});
akberenz commented 8 years ago

Just to be clear, width and height affect the page size, not image sizes. I've had to make some changes, but it should work out that the print job will find the closest valid page size (available to that printer) to what you want to print and then the drawable area will be set to the specified size, cutting off anything drawn outside that range.

klabarge commented 8 years ago

Thanks for the clarification on the size option. After your change, I can now see the page size being increased or decreased as I adjust the width and height values.

A client reported that unexpected boundaries are created with the size option. One thing I have noticed is that changing one of these values, for example height, also affects the width.

  1. The image below shows the difference in the size by changing the height value from 10 to 20 (mm). It appears as though the size is being scaled, even though I am not using the scaling option. I am also unable to get my width to be larger than my height.

    image

  2. Here is the code I was using:

    function printBase64() {
       var config = qz.configs.create('Microsoft XPS Document Writer', {interpolation: 'nearest-neighbor', units: 'mm',  size: { width: 58, height: 20 }, density: 25 });
       var printData = [
           {
               type: 'image',
               format: 'base64',
               data: 'iVBORw0KGgoAAAANSUhEUgAAAJIAAABaCAYAAABTwA9XAAAC4ElEQ' +
       'VR4Ae2dwW4CMQwFdyt+l/8/Ui3qq5LIlXB4rVS96YFgxzF4drQ9U' +
       'JXzOI7HcT08nstxnucVfsfP4OtBe8rpjOJrVU21p7pXalTL6iUg9' +
       'mtXXS/tKx7r1r0x/hgLeQ6BXQKItEuOcxMBRJpwEOwSQKRdcpybC' +
       'CDShINglwAi7ZLj3EQAkSYcBLsEEGmXHOcmAog04SDYJYBIu+Q4N' +
       'xFApAkHwS4BRNolx7mJwG2K/jgYP/TTS1c57WlVjeLxA0btVbm1X' +
       'rXKa63OKqczP8XqsdYpP65VTZUbz+i56hRr1ftSrLo1r33Xyh3JR' +
       'TK8DyKFC+AaH5FcJMP7IFK4AK7xEclFMrwPIoUL4BofkVwkw/sgU' +
       'rgArvERyUUyvA8ihQvgGh+RXCTD+yBSuACu8RHJRTK8DyKFC+AaH' +
       '5FcJMP7IFK4AK7xEclFMrwPIoUL4BofkVwkw/sgUrgArvERyUUyv' +
       'A8ihQvgGh+RXCTD+yBSuACu8RHJRTK8DyKFC+AaH5FcJMP7IFK4A' +
       'K7xEclFMrwPIoUL4BofkVwkw/sgUrgArvERyUUyvA8ihQvgGh+RXC' +
       'TD+yBSuACu8a+vi3z5GyRdL/qf+qz/zHON/9Ms777XdfYx5o70Ll3' +
       'OPwkgEiJYCCCSBSNNEAkHLAQQyYKRJoiEAxYCiGTBSJPb/X6fKKzx' +
       'tBkYrDzWOAnJOvsYn4/f/tqcJNLBs/KrLfjiO0dHJCfN4F6IFHzxn' +
       'aMjkpNmcC9ECr74ztERyUkzuBciBV985+iI5KQZ3AuRgi++c3REct' +
       'IM7nU7juvPtvmpCJygqbCUOe5IJRaSXQKI1CVGfUkAkUosJLsEEKl' +
       'LjPqSACKVWEh2CSBSlxj1JQFEKrGQ7BJApC4x6ksCiFRiIdklgEhd' +
       'YtSXBBCpxEKySwCRusSoLwkgUomFZJcAInWJUV8SQKQSC8kuAUTqE' +
       'qO+JIBIJRaSXQKI1CVGfUkAkUosJLsEPgHpkWVZ2ZEW6gAAAABJRU' +
       '5ErkJggg=='
           }   
       ];
         qz.print(config, printData).catch(function(e) { console.error(e); });
    }

I would like to note that I am testing using the Microsoft XPS Printer, but my results should still be valid.

akberenz commented 8 years ago

Some further changes have been made to finding the page size, so it should be a bit more stable now. Scaling content is set to true by default, so unless you set scaleContent to false, it will scale your image to the closest edge. The size value is expecting standard paper sizes, so if you wish to print to the wider edge, you'll have to set orientation to landscape.

klabarge commented 8 years ago

Thanks Brett, landscape was what we were looking for :+1: Another question...

Do we support fractions for the density? We were trying to use a fraction when using MM and it didn't seem to make a difference.

akberenz commented 8 years ago

The printer resolution attribute requires integers, so no we don't.

tresf commented 8 years ago

The printer resolution attribute requires integers, so no we don't.

That's a bug then, since 72 dpi is 2.834645669291 dots/mm, and we can't specify decimals. Edit: (or we remove the dots per mm altogether?). We noticed this when trying to get an image to scale properly to a custom label size (one we defined). We kept tweaking the density, but the precision wasn't fine enough to get it scaled exactly. It was always either too small or two large (by a few pixels).

akberenz commented 8 years ago

Looking into the code around density more, we do convert the value to dpi first, so I've changed it to accept decimals (43cef2e3ac71b4f8f9ae286309f26667d49352af). But this will only be of use to dpcm and dpmm, since it will still end up as an integer in dpi form.

klabarge commented 8 years ago

I tested this out and decimals are working :+1:

tresf commented 8 years ago

Closed via 43cef2e.

klabarge commented 8 years ago

I'm having a hard time setting the paper size for images.

I have added a custom page size to my OS:

image

  1. Using size option: When I provide these dimensions with the config, a much different page size is chosen.

    var config = qz.configs.create('Microsoft XPS Document', { units: 'in', size: {width: 2.28, height: 1.26} });
    • Even when I make this custom paper size the default paper size on the printer, this size is chosen. So, it doesn't seem that it is using the default paper size on printer
    • No matter what dimensions I use, this is the paper size that is displayed

    Below is the result (reduced size to 60%): image

  2. Removing size option When this custom paper size is the default page size of my printer and I do not define a size in the config, the page size is correct. However, it does not appear that the image is scaling properly.

    image

    When I set scaleContent to false it is a little easier to see the margins that are set:

    image

This is the original image:

image

akberenz commented 8 years ago

A change has been made (under c33c741a67f61f9ff7e720e603606b2bc7c5ba4b) that should be more accepting of custom page sizes. The issue before is that it was only able to use predefined constants for the sizes.

tresf commented 8 years ago

Thanks @klabarge and myself will test and report back. :+1: :+1: :+1:

klabarge commented 8 years ago

This seems to be working great now! Both mm and in result in the same page size. :+1:

Are custom page sizes fully supported now? Even when I removed my custom page size from my OS, I was able to print a custom page size to my XPS printer.

IN
var size = {width: 2.28, height: 1.26};
var config = qz.configs.create('Microsoft XPS Document', { units: 'in', size: size });

image

MM
var size = {width: 58, height: 32};
var config = qz.configs.create('Microsoft XPS Document', { units: 'mm', size: size });

image

Edit: The dimensions supplied are not exact for the image. I just used them to test that the page size is properly set.

tresf commented 8 years ago

@klabarge thanks. We'll close this out and continue testing.