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

How to get Uint8List data of page? #1964

Closed
xyzbilal opened this issue Jul 4, 2024 · 4 comments
Closed

How to get Uint8List data of page? #1964

xyzbilal opened this issue Jul 4, 2024 · 4 comments
Labels
pdf viewer PDF viewer component waiting for customer response Cannot make further progress until the customer responds.

Comments

@xyzbilal
Copy link

xyzbilal commented Jul 4, 2024

Use case

Create thumbnail of pdf for certain page.

Proposal

Hi,
I m workin on a e-newspaper app with serverpod and I try to create an image thumbnail when user uploads a pdf, I want to get first page and create jpeg image from it. its possible to create with pdfrx page on client site but because it requires flutter ui, I cant use it server side. My question is if I can get Uint8List data of page in pdf. I share my example function for reference. regards.

Future<void> savePdfFirstPageAsImage(String pdfPath) async {

  final pdfDocument = await PdfDocument.openFile(pdfPath);
  
  final page = await pdfDocument.pages.first;


  final pageImage = await page.render( // this requires ui
    width: page.width,
    height: page.height,
  );


  Uint8List pageData = pageImage!.bytes;
  

  final image = img.decodePng(pageData);

  
  final directory = await getApplicationDocumentsDirectory();
  final imagePath = '${directory.path}/first_page.png';
  final imageFile = File(imagePath);
  
  await imageFile.writeAsBytes(img.encodePng(image!));

  // Kaydedilen yol
  print('Image saved at: $imagePath');

}
@xyzbilal xyzbilal changed the title How to Uint8List data of page? How to get Uint8List data of page? Jul 4, 2024
@VijayakumarMariappan VijayakumarMariappan added pdf PDF component open Open labels Jul 5, 2024
@immankumarsync
Copy link
Contributor

Hi @xyzbilal,
At present, we do not support exporting a page as an image using the PdfPage API. However, you can extract the PDF page as an image using the syncfusion_flutter_pdfviewer package.

You can find the sample code in the issue #1879. Please confirm us whether the solution worked for you

@chinnumuniyappan chinnumuniyappan added pdf viewer PDF viewer component and removed pdf PDF component labels Jul 5, 2024
@Deepak1799 Deepak1799 added waiting for customer response Cannot make further progress until the customer responds. and removed open Open labels Jul 9, 2024
@xyzbilal
Copy link
Author

xyzbilal commented Jul 9, 2024

Actually this is not exact solution because it requires ui and in serverpod server side ui is not available. I was looking for solution without importing dart ui. Your suggestion works in client side. if you do not have solution in pdf then we will implement this in client site with pdf viewer. thanks.

@immankumarsync
Copy link
Contributor

Unfortunately, extracting the PDF page image without using the Dart UI library is not currently possible. If you need further assistance or have other questions, please feel free to ask.

@Deepak1799
Copy link
Collaborator

@xyzbilal As we have not heard back from you regarding the details shared in our last update, we are closing this issue. You can reopen this anytime and share the requested details to proceed further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pdf viewer PDF viewer component waiting for customer response Cannot make further progress until the customer responds.
Projects
None yet
Development

No branches or pull requests

5 participants