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

PdfPreview renders inaccurate colors on Android #1640

Open
4 tasks
malo-leon-adeo opened this issue Apr 2, 2024 · 0 comments
Open
4 tasks

PdfPreview renders inaccurate colors on Android #1640

malo-leon-adeo opened this issue Apr 2, 2024 · 0 comments
Labels
bug Something isn't working needs triage

Comments

@malo-leon-adeo
Copy link

malo-leon-adeo commented Apr 2, 2024

Describe the bug
The colors don't seem to be correct when applying transparency to colors on Android in the previewPdf. Here's an example you can easily reproduce. When there's no transparency, the color displayed on the web and on Android are the same; however, as soon as transparency is applied, it differs on Android. Note that the color is correct when opening the PDF in the native PDF viewer on Android. The bug only appears in the PDF preview.

To Reproduce
Code snippet to reproduce the behavior:

import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:printing/printing.dart';
import 'package:syncfusion_flutter_pdf/pdf.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PdfPreview(build: (format) => _generatePdf()),
    );
  }

  Future<Uint8List> _generatePdf() async {
    final document = PdfDocument();

    // Global page settings
    document.pageSettings.size = PdfPageSize.a4; // 595
    document.pageSettings.setMargins(28.8, 28.8, 25.9, 28.8);
    document.fileStructure.incrementalUpdate = false;

    // Add first page
    document.pages.add();

    final graphics = document.pages[0].graphics;
    final state = graphics.save();

    graphics.setTransparency(0.5, alphaBrush: 0.5, mode: PdfBlendMode.darken);
    graphics.drawString(
        'Hello World !', PdfStandardFont(PdfFontFamily.helvetica, 50),
        brush: PdfSolidBrush(PdfColor(60, 165, 85)),
        bounds: const Rect.fromLTWH(10, 10, 300, 500));
    graphics.restore(state);

    final saved = document.saveSync();
    document.dispose();
    return Uint8List.fromList(saved);
  }
}

Expected behavior
I expect the pdfPreview to display the same colors on Android as on other platforms when applying transparency.

Screenshots
Android result using printing:
Capture d’écran 2024-04-02 à 11 02 15

Web result using printing:
Capture d’écran 2024-04-02 à 11 02 22

Android native viewer result:
Capture d’écran 2024-04-02 à 11 02 41

Flutter Doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.9, on macOS 14.2.1 23C71
darwin-arm64, locale fr-FR)
[✓] Android toolchain - develop for Android devices (Android SDK
version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.5)
[✓] VS Code (version 1.87.2)
[✓] Connected device (4 available)
! Error: Browsing on the local area network for iPad de
Hugo. Ensure the device is unlocked and attached with a
cable or associated with the same local area network as
this Mac.
The device must be opted into Developer Mode to connect
wirelessly. (code -27)
[✓] Network resources

• No issues found!

Desktop (please complete the following information):

  • iOS
  • [X ] Android
  • Browser
  • Windows
  • Linux

Smartphone (please complete the following information):

  • Device: sdk_gphone64_arm64
  • OS: Android 14
@malo-leon-adeo malo-leon-adeo added bug Something isn't working needs triage labels Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant