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

solve pdf export problem #584

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions app/lib/cubits/current_index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -637,21 +637,46 @@ class CurrentIndexCubit extends Cubit<CurrentIndex> {
if (area == null || page == null) {
continue;
}
final pageFormat =
PdfPageFormat(area.width * quality, area.height * quality);

final image = await render(document, page, info,
width: area.width,
height: area.height,
x: area.position.x,
y: area.position.y,
quality: quality,
renderBackground: renderBackground);
if (image == null) continue;
pdf.addPage(pw.Page(
pageFormat: pageFormat,
build: (context) {
return pw.Image(pw.MemoryImage(image.buffer.asUint8List()));
}));

// * * use this variable for set landscape
bool landscape = false;
if (landscape == true) {
if (image == null) continue;
pdf.addPage(pw.Page(
pageFormat: PdfPageFormat.a4.landscape,
orientation: pw.PageOrientation.landscape,
build: (pw.Context contex) {
return pw.FullPage(
ignoreMargins: true,
child: pw.Image(
pw.MemoryImage(image.buffer.asUint8List()),
fit: pw.BoxFit.fill,
),
);
}));
} else {
if (image == null) continue;
pdf.addPage(pw.Page(
// pageFormat: PdfPageFormat.a4.landscape,orientation: pw.PageOrientation.landscape,
pageFormat: PdfPageFormat.a4,
build: (pw.Context contex) {
return pw.FullPage(
ignoreMargins: true,
child: pw.Image(
pw.MemoryImage(image.buffer.asUint8List()),
fit: pw.BoxFit.fill,
),
);
}));
}
}
return pdf;
}
Expand Down
11 changes: 8 additions & 3 deletions app/lib/selections/tools/area.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ class AreaToolSelection extends ToolSelection<AreaTool> {

@override
List<Widget> buildProperties(BuildContext context) {
final dpi = MediaQuery.of(context).devicePixelRatio;
final tool = selected.first;
return [
...super.buildProperties(context),
ExactSlider(
header: Text(AppLocalizations.of(context).width),
value: tool.constrainedWidth,
value: tool.constrainedWidth * dpi,
min: 0,
max: 500,
defaultValue: 0,
Expand All @@ -19,9 +20,10 @@ class AreaToolSelection extends ToolSelection<AreaTool> {
selected
.map((e) => e.copyWith(constrainedWidth: value))
.toList())),

ExactSlider(
header: Text(AppLocalizations.of(context).height),
value: tool.constrainedHeight,
value: tool.constrainedHeight * dpi,
min: 0,
max: 500,
defaultValue: 0,
Expand All @@ -30,6 +32,8 @@ class AreaToolSelection extends ToolSelection<AreaTool> {
selected
.map((e) => e.copyWith(constrainedHeight: value))
.toList())),


ExactSlider(
header: Row(
children: [
Expand All @@ -39,7 +43,7 @@ class AreaToolSelection extends ToolSelection<AreaTool> {
textAlign: TextAlign.center,
),
),
PopupMenuButton<AspectRatioPreset>(
PopupMenuButton<AspectRatioPreset>(// *? You should use a popup to allow the user to select the landscape, setting landscape = true in current_index.dart
itemBuilder: (context) => AspectRatioPreset.values
.map((e) => PopupMenuItem(
value: e,
Expand All @@ -56,6 +60,7 @@ class AreaToolSelection extends ToolSelection<AreaTool> {
)
],
),
// ! not use
value: tool.constrainedAspectRatio,
min: 0,
max: 10,
Expand Down
Loading