How to draw pdf content in flutter canvas - flutter

I'm using Flutter with pdf package. In the readme it says use printing to show pdf in app.
However, I want to draw in front of the pdf content(taking notes/make annotations). So I guess I have to draw pdf content in my CustomPaint widget to get more control to it.
I searched around and didn't found any useful experience. Please let me know it my approach is correct/reasonable and if there's any better approach.
Thanks!

I think the part of the README you're talking about is this one :
Use the printing package https://pub.dev/packages/printing for full
flutter print and share operation.
This printing package is meant for printing to a real printer.
The pdf package you're using is only meant for creating a pdf in a flutter application, not for displaying it as a widget.
What you want to achieve is to display a pdf and annote on top of it. Your approach is a correct one:
Use a CustomPainter
Add a PDF widget as its child
Paint your annotations on the foreground painter.
To display a pdf as a widget you'll need another package like advance_pdf_viewer.
Painting on the foreground painter is important because as stated in the CustomPaint class documentation:
When asked to paint, CustomPaint first asks its painter to paint on
the current canvas, then it paints its child, and then, after painting
its child, it asks its foregroundPainter to paint.
The code should look like :
PDFDocument doc = await PDFDocument.fromAsset('assets/test.pdf');
return CustomPaint(
child: PDFViewer(doc: document)),
foregroundPainter: AnnotationsPainter(),
);

Related

Add margins in a png file

I have a generated png file with a barcode, I need to save the file on the device, can I add margins on the sides to the picture so that the barcode is read correctly
One way to achieve this can be using the screenshot package (that takes a screenshot of the child widget and saves it as a .png file) to take a screenshot of the image widget inside a padding widget. Give the padding the value you want to see as a margin in the image.
Another approach can be generating that barcode in .svg format and modifying its code before saving.
Or give RepaintBoundary a try.

Is there a way to print the same exact page on flutter web?

i'm trying to make a page with flutter widgets and i want the user to be able to print the same exact page.
I have tried:
syncfusion_flutter_pdf library
Which is work fine but i cant make complex designs.
PDF library
Unfortunately i couldn't figure it out because i'm using dart:html
If you want to output a Flutter scene exactly as they appear on the screen, you can use a RepaintBoundary widget, to save the widget into a PNG file.
You can insert RepaintBoundary at any level of the widget tree. So if you put it near the root of the widget tree, you will be able to capture the whole screen.
Take a look at this answer for how to use RepaintBoundary.

Flutter: Live Mirror Content of Widget to another Widget

I'm trying to live copy the content 1:1 to another widget. Is there some Widget that already has this functionality?
For some Context: I have the Surface Duo and the hinge blocks some of the content in the middle (under the hinge) when spanning the app across both screens. There seems no way to avoid that, so I'm trying to build an app that prevents this as follows:
Build a custom browser
Render at full screen resolution
Copy content to second widget
Overlay/stack second widget on top of first widget, clip/crop and move it so that the content continues without loss of information.
I'm happy to elaborate on the problem if you have any questions. Of course any other solution that you might come up with is appreciated (for example, if there is some way to skip rendering a Widget for part of the screen).
Thanks in advance and best,
Daniel

How Create Curl Page

I want to animate a widget in a "page curl" fashion like in this video.
There is already a pub.dev package page_turn that does this, but it converts the widget into an image, which I don't want to do.
Is there any other way to create this animation without converting the widget to an image?

Flutter box decoration in a container

How can I use svg image in a container's box decoration? Seems it only allows the png/jpg files in AssetImage(). I am trying to display two images on top of the background image set through the box decoration. I am trying to dodge the method of stack. So is there a way?
Flutter has no inbuilt support for SVG as of now..
But you can try this package -> https://pub.dev/packages/flutter_svg
final Widget svg = new SvgPicture.asset(
"assets/image.svg",
);
However, I'd recommend not using an SVG, instead convert your image to a png format