Open MohsinP07 opened 8 months ago
same issue...help me
Hey @niraj8763 , I have solved this issue by using image method, We need to create an image of content first and then print the image which will avoid these issues.
thank for this @MohsinP07 but i have 100 of pages of PDF then that takes time any another solution? my input is this 'जिल्हा परिषद' but I got diffrent output(" जलिहा परषिद") in pdf, pdf.addPage( pw.MultiPage( build: (pw.Context context) {} ) )
@niraj8763 let me share code snippet with so you can try that
FuturecreatePDF(List summaryReport) async { final pdf = pw.Document(); final fontData = await rootBundle.load('assets/fonts/Noto-Regular.ttf'); final font = pw.Font.ttf(fontData); final zpImage = await _textToImage("जिल्हा परिषद", font, 600, 600, 20, 16); pdf.addPage( pw.MultiPage( build: (context) => [ pw.Image(pw.MemoryImage(zpImage)), pw.SizedBox(height: 4), ]), ); return pdf; } Future savePDF(pw.Document pdf) async { final output = await getTemporaryDirectory(); final file = File("${output.path}/Report.pdf" ); await file.writeAsBytes(await pdf.save()); return file.path; } Future _textToImage(String text, pw.Font font, double widthText, int widthInt, int height, double fontsize) async { final recorder = ui.PictureRecorder(); final canvas = Canvas(recorder); final paragraphStyle = ui.ParagraphStyle( fontSize: fontsize, ); final paragraphBuilder = ui.ParagraphBuilder(paragraphStyle) ..pushStyle(ui.TextStyle(color: ui.Color(0xFF000000))) ..addText(text); final paragraph = paragraphBuilder.build() ..layout(ui.ParagraphConstraints(width: widthText)); canvas.drawParagraph(paragraph, Offset(0, 0)); final picture = recorder.endRecording(); final img = await picture.toImage(widthInt, height); final byteData = await img.toByteData(format: ui.ImageByteFormat.png); return byteData!.buffer.asUint8List(); }
Also you can call this as
final pdf = createPDF(summaryReport); final filePath = await savePDF(await pdf); OpenFile.open(filePath);
But this has one drawback as well that it takes little extra time in case of large number of pages and please make sure you change the quality of image as per your requirement.
thank @MohsinP07 👍 :) but I have bulk amount marathi/hindi data in multipage page and also table structure is there it takes lot of time, in this scenario copy does not working from pdf.
@niraj8763 I am also facing the same issue about time and also I have multiple tables in pdf. I tried decreasing the image quality a bit which worked in case of time but its not a long term solution decreasing the quality.
In my project, according to requirements, I need to generate a PDF in multiple languages. I am able to do so in English perfectly, but I am facing issues when it comes to Marathi or Hindi language. I am getting the generated PDF, but the Marathi and Hindi texts are breaking.
For example: The text I want to print is "पेमेंट रजिस्टर", but inside the PDF print, I am getting the text as