-
Notifications
You must be signed in to change notification settings - Fork 64
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
Allow horizontal pages #9
Comments
Basically, PdfViewerParams.layoutPages function is to layout pages with custom logic. But it still lacks of page caching control and not fully working so far. |
@espresso3389 could you provide sample please? I also trying to move from your previous package pdf_render and there I did via
|
The following code is the simplest PdfViewer.uri(
Uri.parse('https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf'),
controller: controller,
displayParams: PdfViewerParams(
layoutPages: (pages, templatePage, params) {
final height = pages.where((p) => p != null).fold(
templatePage.height,
(prev, page) => max(prev, page!.height)) +
params.margin * 2;
final pageLayouts = <Rect>[];
double x = params.margin;
for (var page in pages) {
page ??= templatePage; // in case the page is not loaded yet
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),
);
},
),
), If you use the older plugin version, there're small breaking changes on the API. |
@espresso3389 How I can change size of pages? I need to do small pages with height 60 and width 30 for example |
@TarasBounty By default, the margin is 8 pixel. So height should be 60+8*2. SizedBox(
height: 60+8*2,
child: PdfViewer.uri(...),
params: PdfViewerParams(
scaleEnabled: false,
),
), |
@espresso3389 I just want to say that I already used I've tried cope and paste your sample above but it not showing pdf file it's just emptu box with 60 height. Maybe a problem with |
On README.md on 0.4.2 illustrates how to do horizontal layout. But for your purpose, I just introduced PdfViewerParams.enableRealSizeRendering. You had better set it to false to improve the performance. |
0.4.2 also has breaking changes and some "key" features, so the final code will be like: SizedBox(
height: 100,
child: PdfViewer.uri(
Uri.parse(
'https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf'),
controller: controller,
// IMPORTANT: fit thumbnails into the SizedBox's view
anchor: PdfPageAnchor.all,
displayParams: PdfViewerParams(
// disable scale changes by user
scaleEnabled: false,
// disable high resolution rendering (because we just use thumbnails)
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),
);
},
),
),
), |
Thank you so much! |
@espresso3389 One more point: Is it possible to align items to the left side? |
|
Ah, sorry, I'm forget the centering issue and reopen the issue anyway. |
@TarasBounty for the centering issue, I created another issue #32. |
I'm still pretty new to pdfrx, so I might just be missing something, but is there a way to lay pages out horizontally?
If not, that would be a nice feature to have.
The text was updated successfully, but these errors were encountered: