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

Remaining issue with form flattening #1047

Closed
Lonzak opened this issue Feb 13, 2024 · 4 comments
Closed

Remaining issue with form flattening #1047

Lonzak opened this issue Feb 13, 2024 · 4 comments
Labels

Comments

@Lonzak
Copy link
Contributor

Lonzak commented Feb 13, 2024

Recently I added some code to fix form flattening problems with certain PDF documents (#992). It improved a lot of things however our QA found a bug. I added red rectangles to show the problem. Without the rectangle it was difficult to spot:

Original with form fields:
grafik

Flattened document:
grafik

The content of the form fields are minimally shifted to the top. I checked the code but couldn't spot it on a first glance. @mkl-public Maybe you have an idea? The document is landscape - maybe this is the cause?

Example-SmallShift.pdf

@Lonzak Lonzak added the bug label Feb 13, 2024
@mkl-public
Copy link
Contributor

The page has a page rotation value of 270. My guess would be that the issue is related to that.

@Lonzak
Copy link
Contributor Author

Lonzak commented Feb 14, 2024

I commented the following line. And it works.

rotation = rotation % 360; 
if (rotation == 90 || rotation == 270) {
   //x += box.getWidth();
}

So probably the following might be correct. This really needs testing...

rotation = rotation % 360; 
if (rotation == 90) {
   x += box.getWidth();
}

@mkl-public
Copy link
Contributor

mkl-public commented Feb 14, 2024

Indeed, it seems to be the 270° rotation.

In com.lowagie.text.pdf.PdfStamperImp.flatFields() starting at line 993 there is

rotation = rotation % 360; 
if (rotation == 90 || rotation == 270) {
    x += box.getWidth();
}
if (rotation == 180 || rotation == 270) {
    y += box.getHeight();
}

but I think it should be

rotation = rotation % 360; 
if (rotation == 90 || rotation == 180) {
    x += box.getWidth();
}
if (rotation == 180 || rotation == 270) {
    y += box.getHeight();
}

That error sneaked in while discussing and improving #992. But please test before integrating.


Ah, I see you spotted the problem, too.

But I think that the x correction also should be there for 180° rotations, simply try it on paper...

@Lonzak
Copy link
Contributor Author

Lonzak commented Feb 14, 2024

Yes you were right - I tested it with 0, 90, 180, 270 and 360° and it works with your suggested solution. Thanks for sparing with me...

andreasrosdal pushed a commit that referenced this issue Feb 14, 2024
* Fixed issues discussed in #992

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

No branches or pull requests

3 participants