-
Notifications
You must be signed in to change notification settings - Fork 848
[syncfusion_flutter_pdf] Can not insert a page at specific index #2353
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
Comments
Hi @marcsanny , Yes, it's possible to insert a PDF page at a specific index in a newly created PDF document using Syncfusion Flutter PDF package. There are a couple of ways to achieve this based on your requirements. Method 1: Inserting an Empty Page at a Specific Index You can insert an empty page at any specific index in a PDF document using the insert method:
Method 2: Inserting a Page from Another PDF Document To insert a page from an existing PDF at a specific index in your document:
The key part is using document.pages.insert(index) to add an empty page at the specified index, or you can use it to insert and then immediately add content from another PDF document using templates. To read PDF files from your Flutter project, you'll need to set up proper file handling as
This allows you to insert pages from existing PDFs at specific indexes in your newly created PDF document |
Please share with us your complete requirements so that we can assist with you further in this |
Hi @irfanajaffer, thanks for your response :). In my use case I had to draw an image outside the margins. I finally achieved what I needed with templates
My pseudo code for that looks like this: // Get templates from pages.
final templates = [
for (int index = 0; index < document.pages.count; index++)
document[index].createTemplate(),
];
// Draw pages and image on a new document without margins.
final documentWithoutMargins = PdfDocument()..pageSettings.setMargins(0);
for (int index = 0; index < templates.length; index++) {
final template = templates[index];
final page = documentWithoutMargins.pages.add();
page.graphics.drawPdfTemplate(template, Offset.zero);
if (index == pageIndex) {
// Draw image on page.
page.layers.add(name: layerName).graphics.drawImage(
PdfBitmap(properties.imageData),
properties.rectForImage(page.size),
);
}
} We can close this issue, but the actual reason I created it was that |
Hi @marcsanny , Thank you for providing the feedback. Please let us know if you need any further assistance. Regards, |
Uh oh!
There was an error while loading. Please reload this page.
Bug description
We are not able to insert a page at specific index (
add()
method works as expected). We get: Null check operator used on a null valueIt seems like the line is causing the error:
Steps to reproduce
Code sample
Minimal reproducible code:
Code sample
The text was updated successfully, but these errors were encountered: