DavBfr / dart_pdf

Pdf creation module for dart/flutter
https://pub.dev/packages/pdf
Apache License 2.0
1.41k stars 631 forks source link

Does not apply PdfColor in alpha #1643

Open michael-kim-korea opened 7 months ago

michael-kim-korea commented 7 months ago

Describe the bug When setting the color in Container's BoxDecoration, PdfColor.fromInt(0x00000000) is applied, but transparent is not applied to the screen and is displayed in black. However, it applies if you specify a color. PdfColor.fromInt(0x01FF0000) or PdfColor.fromInt(0x010000FF).

I don't know if this is a bug or intentional, but alpha is applied in the flutter widget.

To Reproduce pw.Container( width: 100.0, height: 100.0, decoration: pw.BoxDecoration( // color: PdfColor.fromInt(0x00000000), // not apply color: PdfColor.fromInt(0x01000000), // not apply // color: PdfColor.fromInt(0x010000FF), // alpha apply border: pw.Border.all(color: PdfColor.fromInt(0xFF00FF00)) ), child: Text("Test"), );

Desktop (please complete the following information):

image

DavBfr commented 6 months ago

Yes, there is no alpha component in PDF. Use the Opacity widget instead.

grahamsmith commented 3 weeks ago

We've just bumped into this issue, any ideas where we could contribute a PR? Is there some background to help resolve this?

DavBfr commented 3 weeks ago

same answer: There is no alpha component in PDF. Use the Opacity widget instead.

grahamsmith commented 3 weeks ago

How does opacity work? Could PdfColor when using alpha with components add then Opacity widget automatically?

A bit like how container uses DecoratedBox automatically if you provide a colour.

DavBfr commented 3 weeks ago

It's not exactly the same. If you add an opacity widget, any children will be transparent. Think of it like changing the opacity of a photoshop or inkscape layer

grahamsmith commented 3 weeks ago

Yeah we have a widget that adds opacity, then the child, then a 100% opacity and then the rest of the children.

grahamsmith commented 3 weeks ago

Just trying to help vs complain about the issue happy to contribute as the library is one of the best in Flutter/Dart.

DavBfr commented 3 weeks ago

Could be implemented for BoxDecoration, why not. https://github.com/DavBfr/dart_pdf/blob/a6f0d9f05e6c2ff7f2bb00aaf0f8986691f9345f/pdf/lib/src/widgets/decoration.dart#L255