dart_pdf icon indicating copy to clipboard operation
dart_pdf copied to clipboard

IOS 15 ignore PdfPageFormat

Open Oleksandr32 opened this issue 3 years ago • 6 comments

When I try to use Printing.layoutPdf with IOS 15 it looks like format of my page is ignoring so I get a very long result.

Screenshot 2022-02-10 at 17 27 24

For example, if I print saved pdf file via sharing, the result is ok. In that case I see paper size option.

Screenshot 2022-02-10 at 17 23 05

Printing works ok in IOS 14 and lower. What do you think? any idea?

Oleksandr32 avatar Feb 10 '22 15:02 Oleksandr32

@Oleksandr32 any code to share?

DavBfr avatar Feb 10 '22 15:02 DavBfr

@DavBfr here how I use this plugin

final format = PdfPageFormat(
    50 * PdfPageFormat.mm,
    54 * PdfPageFormat.mm,
    marginAll: 2 * PdfPageFormat.mm,
  );
  
Uint8List data = await Printing.convertHtml(
      format: format,
      html: response.body, // here result of api call
      baseUrl: '',
    );
    
return Printing.layoutPdf(
        format: format,
        onLayout: (format) {
          return data;
        },
        dynamicLayout: true,
      );

Oleksandr32 avatar Feb 10 '22 15:02 Oleksandr32

I have fixed that by adding this code to ios plugin implementation PrintJob class

// Workaround
    public func printInteractionController(_ printInteractionController: UIPrintInteractionController, choosePaper paperList: [UIPrintPaper]) -> UIPrintPaper {
        if currentSize == nil {
            return paperList[0]
        }
        
        return UIPrintPaper.bestPaper(forPageSize: currentSize!, withPapersFrom: paperList)
    }

where currentSize is size from

func printPdf(name: String, withPageSize size: CGSize, andMargin margin: CGRect, withPrinter printerID: String?, dynamically dyn: Bool)

I found this workaround here https://developer.apple.com/forums/thread/30197

@DavBfr This behaviour I only notice in IOS 15. Please let me know if you will investigate this.

Oleksandr32 avatar Feb 11 '22 13:02 Oleksandr32

Looks good, can you create a PR?

DavBfr avatar Feb 11 '22 13:02 DavBfr

@DavBfr of course, here PR https://github.com/DavBfr/dart_pdf/pull/944

Oleksandr32 avatar Feb 11 '22 14:02 Oleksandr32

I have same Problem. Any news about the PR?

luttmfra avatar Apr 16 '22 18:04 luttmfra

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Apr 15 '23 00:04 github-actions[bot]

Closing this stale issue because it has no activity.

github-actions[bot] avatar Apr 21 '23 00:04 github-actions[bot]