You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Ranjeet Kuruvilla <ra...@yandex.com> on 2021/05/25 16:33:45 UTC

flattening

Hallo.
It is clear, that flattening does have a bug. Compare flattening of
PDFBox with IText and you realize, that PDFBox destroys all fields, once
I call

acroform.flatten(fields, true) or acroform.flatten(fields, false)

.

How can I request someone to fix flattening and make it work like in
IText. That is that the right fields are flattened while all the other
fields remain untouched!



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


Re: flattening

Posted by "sahyoun@fileaffairs.de" <sa...@fileaffairs.de>.
Am Mittwoch, dem 26.05.2021 um 07:53 +0200 schrieb Ranjeet Kuruvilla:
> I know how Itext works and PDFBox does not work the same. In Itext the
> result is that only the right fields are flattened. It seems there is a
> bug.

I've created a small test which is running fine:

PDDocument document = Loader.loadPDF(new File(IN_DIR, NAME_OF_PDF));
PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
int numFieldsBefore = acroForm.getFields().size();
    
List<PDField> toBeFlattened = new ArrayList<>();
PDTextField field = (PDTextField) acroForm.getField("AlignLeft-
Filled");
toBeFlattened.add(field);
acroForm.flatten(toBeFlattened,false);

assertEquals(numFieldsBefore, acroForm.getFields().size() + 1, "The
number of form fields shall be reduced by one");

A manual inspection of the result shows that all fields but one are
still accessible.

The file being used was
src/test/resources/org/apache/pdfbox/pdmodel/interactive/form/Multiline
Fields.pdf

Version used was the current trunk.

So please do a similar test with your files. I'm not saying there is no
bug but we have to be able to reproduce it to be able to solve it. With
the files I've tested with the result is fine.

BR
Maruan


> 
> In PdfBox every field is flattened, even though I delivered a list of
> fields, that were meant to be flattened.
> 
> It seems the PDF is destroyed by flattening.
> 
> I have attached the code.
> 
> On 25.05.21 19:27, Tilman Hausherr wrote:
> > Here's a PDF flattened by itext
> > https://github.com/itext/i7js-examples/blob/develop/cmpfiles/sandbox/acroforms/cmp_checkbox_flatten.pdf
> > 
> > and they do something similar to what we do, i.e. remove the fields
> > and converting it to form XObjects.
> > Tilman
> > 
> > Am 25.05.2021 um 19:03 schrieb sahyoun@fileaffairs.de:
> > > Am Dienstag, dem 25.05.2021 um 18:33 +0200 schrieb Ranjeet
> > > Kuruvilla:
> > > > Hallo.
> > > > It is clear, that flattening does have a bug. Compare flattening
> > > > of
> > > > PDFBox with IText and you realize, that PDFBox destroys all
> > > > fields,
> > > > once
> > > > I call
> > > > 
> > > > acroform.flatten(fields, true) or acroform.flatten(fields, false)
> > > > 
> > > > 
> > > the purpose of flatten is that the flattened fields are removed and
> > > become part of the regular page content.
> > > 
> > > If you'd like to keep the field but would like it to be protected
> > > you
> > > have to set the field to read only. Keep in mind that one could use
> > > a
> > > lib and remove the flag and change the content afterwards.
> > > 
> > > Now, if there is really a bug I need to have a clear description
> > > how to
> > > reproduce it together with sample content. If you're able to
> > > provide
> > > that I'm happy to take a look.
> > > 
> > > BR
> > > Maruan
> > > 
> > > > .
> > > > 
> > > > How can I request someone to fix flattening and make it work like
> > > > in
> > > > IText. That is that the right fields are flattened while all the
> > > > other
> > > > fields remain untouched!
> > > > 
> > > > 
> > > > 
> > > > -----------------------------------------------------------------
> > > > ----
> > > > 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
> > > 
> > 
> > 
> > ---------------------------------------------------------------------
> > 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

-- 
-- 
Maruan Sahyoun

FileAffairs GmbH
Josef-Schappe-Straße 21
40882 Ratingen

Tel: +49 (2102) 89497 88
Fax: +49 (2102) 89497 91
sahyoun@fileaffairs.de
www.fileaffairs.de

Geschäftsführer: Maruan Sahyoun
Handelsregister: AG Düsseldorf, HRB 53837
UST.-ID: DE248275827


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


Re: flattening

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

Please tell what PDFBox version you're using and create a MINIMAL 
reproducer. Your current code does not flatten at all (because flatten 
is commented out), and uses an external class do do something that isn't 
related to flattening. Your reproducer should just load the file, select 
some fields, and flatten and produce the problem.

Tilman

Am 26.05.2021 um 07:53 schrieb Ranjeet Kuruvilla:
> I know how Itext works and PDFBox does not work the same. In Itext the
> result is that only the right fields are flattened. It seems there is a bug.
>
> In PdfBox every field is flattened, even though I delivered a list of
> fields, that were meant to be flattened.
>
> It seems the PDF is destroyed by flattening.
>
> I have attached the code.
>
> On 25.05.21 19:27, Tilman Hausherr wrote:
>> Here's a PDF flattened by itext
>> https://github.com/itext/i7js-examples/blob/develop/cmpfiles/sandbox/acroforms/cmp_checkbox_flatten.pdf
>>
>> and they do something similar to what we do, i.e. remove the fields
>> and converting it to form XObjects.
>> Tilman
>>
>> Am 25.05.2021 um 19:03 schrieb sahyoun@fileaffairs.de:
>>> Am Dienstag, dem 25.05.2021 um 18:33 +0200 schrieb Ranjeet Kuruvilla:
>>>> Hallo.
>>>> It is clear, that flattening does have a bug. Compare flattening of
>>>> PDFBox with IText and you realize, that PDFBox destroys all fields,
>>>> once
>>>> I call
>>>>
>>>> acroform.flatten(fields, true) or acroform.flatten(fields, false)
>>>>
>>>>
>>> the purpose of flatten is that the flattened fields are removed and
>>> become part of the regular page content.
>>>
>>> If you'd like to keep the field but would like it to be protected you
>>> have to set the field to read only. Keep in mind that one could use a
>>> lib and remove the flag and change the content afterwards.
>>>
>>> Now, if there is really a bug I need to have a clear description how to
>>> reproduce it together with sample content. If you're able to provide
>>> that I'm happy to take a look.
>>>
>>> BR
>>> Maruan
>>>
>>>> .
>>>>
>>>> How can I request someone to fix flattening and make it work like in
>>>> IText. That is that the right fields are flattened while all the other
>>>> fields remain untouched!
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>>
>>
>> ---------------------------------------------------------------------
>> 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



Re: flattening

Posted by Ranjeet Kuruvilla <ra...@yandex.com>.
I know how Itext works and PDFBox does not work the same. In Itext the
result is that only the right fields are flattened. It seems there is a bug.

In PdfBox every field is flattened, even though I delivered a list of
fields, that were meant to be flattened.

It seems the PDF is destroyed by flattening.

I have attached the code.

On 25.05.21 19:27, Tilman Hausherr wrote:
> Here's a PDF flattened by itext
> https://github.com/itext/i7js-examples/blob/develop/cmpfiles/sandbox/acroforms/cmp_checkbox_flatten.pdf
>
> and they do something similar to what we do, i.e. remove the fields
> and converting it to form XObjects.
> Tilman
>
> Am 25.05.2021 um 19:03 schrieb sahyoun@fileaffairs.de:
>> Am Dienstag, dem 25.05.2021 um 18:33 +0200 schrieb Ranjeet Kuruvilla:
>>> Hallo.
>>> It is clear, that flattening does have a bug. Compare flattening of
>>> PDFBox with IText and you realize, that PDFBox destroys all fields,
>>> once
>>> I call
>>>
>>> acroform.flatten(fields, true) or acroform.flatten(fields, false)
>>>
>>>
>> the purpose of flatten is that the flattened fields are removed and
>> become part of the regular page content.
>>
>> If you'd like to keep the field but would like it to be protected you
>> have to set the field to read only. Keep in mind that one could use a
>> lib and remove the flag and change the content afterwards.
>>
>> Now, if there is really a bug I need to have a clear description how to
>> reproduce it together with sample content. If you're able to provide
>> that I'm happy to take a look.
>>
>> BR
>> Maruan
>>
>>> .
>>>
>>> How can I request someone to fix flattening and make it work like in
>>> IText. That is that the right fields are flattened while all the other
>>> fields remain untouched!
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>

Re: flattening

Posted by Tilman Hausherr <TH...@t-online.de>.
Here's a PDF flattened by itext
https://github.com/itext/i7js-examples/blob/develop/cmpfiles/sandbox/acroforms/cmp_checkbox_flatten.pdf
and they do something similar to what we do, i.e. remove the fields and 
converting it to form XObjects.
Tilman

Am 25.05.2021 um 19:03 schrieb sahyoun@fileaffairs.de:
> Am Dienstag, dem 25.05.2021 um 18:33 +0200 schrieb Ranjeet Kuruvilla:
>> Hallo.
>> It is clear, that flattening does have a bug. Compare flattening of
>> PDFBox with IText and you realize, that PDFBox destroys all fields,
>> once
>> I call
>>
>> acroform.flatten(fields, true) or acroform.flatten(fields, false)
>>
>>
> the purpose of flatten is that the flattened fields are removed and
> become part of the regular page content.
>
> If you'd like to keep the field but would like it to be protected you
> have to set the field to read only. Keep in mind that one could use a
> lib and remove the flag and change the content afterwards.
>
> Now, if there is really a bug I need to have a clear description how to
> reproduce it together with sample content. If you're able to provide
> that I'm happy to take a look.
>
> BR
> Maruan
>
>> .
>>
>> How can I request someone to fix flattening and make it work like in
>> IText. That is that the right fields are flattened while all the other
>> fields remain untouched!
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>


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


Re: flattening

Posted by "sahyoun@fileaffairs.de" <sa...@fileaffairs.de>.
Am Dienstag, dem 25.05.2021 um 18:33 +0200 schrieb Ranjeet Kuruvilla:
> Hallo.
> It is clear, that flattening does have a bug. Compare flattening of
> PDFBox with IText and you realize, that PDFBox destroys all fields,
> once
> I call
> 
> acroform.flatten(fields, true) or acroform.flatten(fields, false)
> 
> 

the purpose of flatten is that the flattened fields are removed and
become part of the regular page content. 

If you'd like to keep the field but would like it to be protected you
have to set the field to read only. Keep in mind that one could use a
lib and remove the flag and change the content afterwards.

Now, if there is really a bug I need to have a clear description how to
reproduce it together with sample content. If you're able to provide
that I'm happy to take a look.

BR
Maruan

> .
> 
> How can I request someone to fix flattening and make it work like in
> IText. That is that the right fields are flattened while all the other
> fields remain untouched!
> 
> 
> 
> ---------------------------------------------------------------------
> 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


Re: flattening

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,
Please read and follow these instructions:
https://pdfbox.apache.org/support.html
Make sure you're using the latest version, and it it happens, please 
open a ticket and attach your file and the flattened file and the itext 
flattened file.
Tilman

Am 25.05.2021 um 18:33 schrieb Ranjeet Kuruvilla:
> Hallo.
> It is clear, that flattening does have a bug. Compare flattening of
> PDFBox with IText and you realize, that PDFBox destroys all fields, once
> I call
>
> acroform.flatten(fields, true) or acroform.flatten(fields, false)
>
> .
>
> How can I request someone to fix flattening and make it work like in
> IText. That is that the right fields are flattened while all the other
> fields remain untouched!
>
>
>
> ---------------------------------------------------------------------
> 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