DavBfr / dart_pdf

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

PDF printing raster or pdf_crypto parsing issue #1572

Open garrettApproachableGeek opened 6 months ago

garrettApproachableGeek commented 6 months ago

Describe the bug

Particular PDF only rendering the top right quarter of the PDF (on iOS and web at least)

To Reproduce Code snippet to reproduce the behavior:

final pdf = pw.Document.load(
   pdf_crypto.PdfDocumentParser(bytes),
);
Uint8List pdfBytes = await pdf.save();

Expected behavior

Full page of the PDF is converted to a new PDF

Screenshots

top_right_of_pdf

It seems like the issue is with the parsing of only the 2 and 3rd index of MediaBox within pdf_crypto document.dart mergeDocument() , but the code below doesn't solve the issue for some reason

double lowerLeftX = (mb.values[0] as PdfNum).value.toDouble().abs();
double lowerLeftY = (mb.values[1] as PdfNum).value.toDouble().abs();
double upperRightX = (mb.values[2] as PdfNum).value.toDouble().abs();
double upperRightY = (mb.values[3] as PdfNum).value.toDouble().abs();
format = PdfPageFormat(
   lowerLeftX + upperRightX,
   lowerLeftY + upperRightY,
);

Inspecting the contents of the pdf it looks like the CropBox and MediaBox 0 and 1 index are negative values

/CropBox[-1224 -792 1224 792]/MediaBox[-1224 -792 1224 792]

Full image correctly rasterized (edited for confidentiality) full_image

Flutter Doctor

[✓] Flutter (Channel stable, 3.10.5, on macOS 14.2.1 23C71 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.85.1)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

Desktop (please complete the following information):

Smartphone (please complete the following information):

garrettApproachableGeek commented 1 month ago

@DavBfr Updated description with more details and likely source of the issue