pdfrx 0.4.3 copy "pdfrx: ^0.4.3" to clipboard
pdfrx: ^0.4.3 copied to clipboard

Yet another PDF renderer for Flutter using PDFium.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:pdfrx/pdfrx.dart';

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

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final searchTextFocusNode = FocusNode();
  final searchTextController = TextEditingController();
  final controller = PdfViewerController();
  bool showSearchToolbar = false;

  @override
  void dispose() {
    searchTextController.dispose();
    searchTextFocusNode.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Pdfrx example')),
        body: Stack(
          children: [
            PdfViewer.asset(
              'assets/sample2.pdf',
              controller: controller,
              anchor: PdfPageAnchor.all,
              displayParams: const PdfViewerParams(
                  //scaleEnabled: false,
                  //enableRealSizeRendering: false,
                  // // code to display pages horizontally
                  // layoutPages: (pages, params) {
                  //   final height =
                  //       pages.fold(0.0, (prev, page) => max(prev, page.height)) +
                  //           params.margin * 2;
                  //   final pageLayouts = <Rect>[];
                  //   double x = params.margin;
                  //   for (var page in pages) {
                  //     pageLayouts.add(
                  //       Rect.fromLTWH(
                  //         x,
                  //         (height - page.height) / 2, // center vertically
                  //         page.width,
                  //         page.height,
                  //       ),
                  //     );
                  //     x += page.width + params.margin;
                  //   }
                  //   return PdfPageLayout(
                  //     pageLayouts: pageLayouts,
                  //     documentSize: Size(x, height),
                  //   );
                  // },
                  ),
            ),
            AnimatedPositioned(
              duration: const Duration(milliseconds: 300),
              right: 2,
              top: showSearchToolbar ? 2 : -80,
              child: Container(
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(8),
                  color: Colors.white,
                  boxShadow: const [
                    BoxShadow(
                        color: Colors.black45,
                        blurRadius: 4,
                        offset: Offset(2, 2))
                  ],
                ),
                padding: const EdgeInsets.all(8),
                width: 300,
                height: 60,
                child: Row(
                  children: [
                    Expanded(
                      child: TextField(
                        controller: searchTextController,
                        focusNode: searchTextFocusNode,
                      ),
                    ),
                    IconButton(
                      onPressed: () {},
                      icon: const Icon(Icons.arrow_downward),
                    ),
                    IconButton(
                      onPressed: () {},
                      icon: const Icon(Icons.arrow_upward),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
        floatingActionButton: Column(
          mainAxisAlignment: MainAxisAlignment.end,
          children: [
            FloatingActionButton(
              onPressed: () {
                controller.zoomUp();
              },
              child: const Icon(Icons.add),
            ),
            FloatingActionButton(
              onPressed: () {
                controller.zoomDown();
              },
              child: const Icon(Icons.remove),
            ),
            FloatingActionButton(
              child: const Icon(Icons.first_page),
              onPressed: () => controller.goToPage(pageNumber: 1),
            ),
            FloatingActionButton(
              child: const Icon(Icons.last_page),
              onPressed: () =>
                  controller.goToPage(pageNumber: controller.pages.length),
            ),
            FloatingActionButton(
                child: const Icon(Icons.search),
                onPressed: () =>
                    setState(() => showSearchToolbar = !showSearchToolbar))
          ],
        ),
      ),
    );
  }
}
96
likes
0
pub points
96%
popularity

Publisher

verified publisherespresso3389.jp

Yet another PDF renderer for Flutter using PDFium.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

ffi, flutter, http, js, rxdart, synchronized, vector_math

More

Packages that depend on pdfrx