You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Matteo Gamboz <ga...@medialab.sissa.it> on 2019/03/27 13:28:10 UTC

Re: resize images (XObjects, Inline Images and stencils)

Hi Tilman,

thank you for the corrections (and sorry for the delay in answering, I
was working on other projects...).

I've applied your suggestions and I think they fixed most of my
problems.  Here is the code as I have it now:
https://medialab.sissa.it/nextcloud/index.php/s/FiWX3F7TJDbCT5A

One can call the script with some command line options to play with
different resolutions.

In the source of the java file, one can find how to call the script
https://medialab.sissa.it/nextcloud/index.php/s/FiWX3F7TJDbCT5A?path=%2Fsrc%2Fmain%2Fjava%2Fit%2Fsissa%2Fmedialab%2Fpdfimages

I don't have much experience with java, please be patient if I was
supposed to "deploy" the code in some other way :-)


As you pointed out, I still have some problems with stencils:
my process transforms the stencil into an image, but sometimes the
background of the stencil is black instead of white. You can seen an
example in the file screenshot.png. The screenshot refers to
test-files/d.pdf.

I will work on this an keep the list posted.
m


On Fri, 08 Mar 2019 15:59:39 +0100,
Tilman Hausherr wrote:
> 
> InputStream img_data_stream = helper_img.getCOSObject().createRawInputStream();
> ...
> newBIoperator.setImageParameters(helper_img.getCOSObject());
> 
> 
> Another thing you should fix yourself. If the image is a stencil,
> create a TYPE_BYTE_BINARY BufferredImage (and later call
> setStencil()). If the image is of colorspace DeviceGray, create a
> TYPE_BYTE_GRAY BufferedImage. I not, then RGB, NOT ARGB.
> 
> Please fix that also try finding a PDF that has an inline image where
> something can be seen, the current one is white.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: resize images (XObjects, Inline Images and stencils)

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,

There is at least one bug:

         if (image.isStencil()) {
             stencil = " (stencil)";
             bufferedImageType = BufferedImage.TYPE_BYTE_BINARY;
         }
************
         if (image.getColorSpace() == PDDeviceGray.INSTANCE){
             bufferedImageType = BufferedImage.TYPE_BYTE_GRAY;
         }

The problem is that stencils are of colorspace DeviceGray despite being 
bitonal. So you need to put an "else" at the "************" place to 
avoid the image getting the TYPE_BYTE_GRAY for stencils.

And this:

             if (image.isStencil()) {
                 log.warn("Is stencil; painting red.");
                 bImage = image.getStencilImage(Color.red);
                 // ↑ this is problematic...
                 // it appears to paint the whole stencil
                 // like it's filling the stencil's "holes" also

is definitively wrong, you are "applying" the stencil, this is for 
PDFBox itself when rendering. Just get the image itself and later set 
the flag.

This is just a "dry" analysis, I didn't run your code.

Tilman

Am 27.03.2019 um 14:28 schrieb Matteo Gamboz:
> Hi Tilman,
>
> thank you for the corrections (and sorry for the delay in answering, I
> was working on other projects...).
>
> I've applied your suggestions and I think they fixed most of my
> problems.  Here is the code as I have it now:
> https://medialab.sissa.it/nextcloud/index.php/s/FiWX3F7TJDbCT5A
>
> One can call the script with some command line options to play with
> different resolutions.
>
> In the source of the java file, one can find how to call the script
> https://medialab.sissa.it/nextcloud/index.php/s/FiWX3F7TJDbCT5A?path=%2Fsrc%2Fmain%2Fjava%2Fit%2Fsissa%2Fmedialab%2Fpdfimages
>
> I don't have much experience with java, please be patient if I was
> supposed to "deploy" the code in some other way :-)
>
>
> As you pointed out, I still have some problems with stencils:
> my process transforms the stencil into an image, but sometimes the
> background of the stencil is black instead of white. You can seen an
> example in the file screenshot.png. The screenshot refers to
> test-files/d.pdf.
>
> I will work on this an keep the list posted.
> m
>
>
> On Fri, 08 Mar 2019 15:59:39 +0100,
> Tilman Hausherr wrote:
>> InputStream img_data_stream = helper_img.getCOSObject().createRawInputStream();
>> ...
>> newBIoperator.setImageParameters(helper_img.getCOSObject());
>>
>>
>> Another thing you should fix yourself. If the image is a stencil,
>> create a TYPE_BYTE_BINARY BufferredImage (and later call
>> setStencil()). If the image is of colorspace DeviceGray, create a
>> TYPE_BYTE_GRAY BufferedImage. I not, then RGB, NOT ARGB.
>>
>> Please fix that also try finding a PDF that has an inline image where
>> something can be seen, the current one is white.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org