Print a pdf downloaded through a webservice in Flutter / Dart - pdf

I'm working with Flutter.
I have a pdf document that I download from a webservice.
The http body response of this pdf sent by http package is typed as Uint8List.
Then, I would like to print it with printing which is working with pdf package.
So I need an instance of a PdfDocument from this class.
Is there a way that I can convert this Uint8List to pdf ? I tried some other dart packages, but they didn't answer my needs because I need to print pdf, not just view them.
I also looked with flutter_downloader in order to simply get pdf file without bothering myself with Uint8List, but it seems the package is not working at the moment: https://github.com/fluttercommunity/flutter_downloader/issues/132
Thank you very much for answering.

Use:
var data = await getThePdfData(); // obtain the Uint8List
Printing.sharePdf(bytes: data);

Related

How can i generate and download PDFs in Flask without saving them in my Webapp?

im trying to get a PDF with the ReportLab Module which works fine so far. My problem is that im saving the PDF with the .build()-method in my Webapps directory. What i want is that i can send the PDF for downloading without saving it before. That is somehow possible with the wkhtmltopdf module, but i dont want to use any other servers for this.
The process would be like: User presses a button 'download as pdf', a pdf is generated and instant returned as a download without saving it first.
Do you know if this is possible?
You want to create the PDF server side, return it to the client, without saving the PDF (for example, in S3)?
Yes, this is possible, you create the PDF in memory using
buffer = io.BytesIO()
myPDF = canvas.Canvas(buffer, pagesize=letter)
Then after creating your pdf you save it using
myPDF.save()
buffer.seek(0)
Then when you are ready to return the PDF as a reponse you can return it with:
response = HttpResponse(buffer, content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="{}"'.format("myFile.pdf")
return response

download pdf file of blade instead of view in browser

I would like the browser to download file on button click of blade page. The following is used in controller and and added in provider file, but its showing in browser console but not downloading file.
use PDF;
// this controller
function sensorChartPDF(){
$pdf = PDF::loadView('sensorchartpdf');
return $pdf->download('invoice.pdf')->header('Content-Type','application/pdf');;
}
///// sensorchartpdf.blade.php this is view ///
https://canvasjs.com/javascript-charts/multi-series-spline-chart/
chart static code appened in this file
To signify to the web browser that the file should be downloaded and not displayed in line you have to specify the content-disposition header with a value of attachment.
Your question, however, does not appear to be purely a question regarding Dompdf. With Dompdf you would merely use the following:
$dompdf->stream("output.pdf", array('Attachment' => 1));
I'm providing this for anyone looking for similar issue when working with the library directly.
Since you're not using Dompdf directly but via another library so you'll need to specify exactly which library or framework you're using before somebody can provide an accurate answer.

Render HTML or GSP as a PDF and save it on server

I have an html template which I need to render as a .PDF and then save that pdf file on server. I'm using "rendering" plugin of grails. I'm able to render file as PDF but I don't understand how to save it on server location and not on user's system. Can anybody please help me ?
The pdfRenderingService provided by the plugin allows you to call render and get back an OutputStream. Using that output stream you can write that to a file on your server. The documentation explains the basics of using the service.
Your code may look something like this:
new File("report.pdf").withOutputStream { outputStream ->
outputStream << pdfRenderingService.render(template: '/report/report', model: [serial: 12345])
}
Well, actually I changed my plugin. Got Wkhtmltopdf plugin of grails more helpful. you can find it here --
https://github.com/quorak/grails-wkhtmltopdf
Also instructions regarding using this plugin you can find on the same link or here --
[https://github.com/quorak/grails-wkhtmltopdf]
Using this you can get "bytes" which you can write to file system.

How can I generate and download a pdf file in WebDynpro for ABAP?

I've got a task to create a webdynpro that given some inputs, can generate a pdf file with questions and the user should be able to download it somewhere. My question is, how can i generate a PDF in WDs and how do i prompt the download?
I do not know how to do it with Adobe Forms but I surely have seen that done using SmartForms.
When you execute the function module assigned to a smartform there is an EXPORTING parameter for it job_output_info.
With this parameter you execute then the function module CONVERT_OTF with following parameters.
EXPORTING
format = 'PDF'
IMPORTING
bin_file = e_file_as_xstring
TABLES
otf = job_output_info-otfdata[]
lines = lt_pdf_file_lines
Then if you are using WebDynpro for ABAP use the following method to let the user download the file.
wdr_task=>client_window->client->attach_file_to_response(
i_filename = 'Filename.pdf'
i_content = e_file_as_xstring
i_mime_type = 'pdf/application'
)
Not sure how it might work with Adobe Forms, but if you are able to generate the OTF content you should be able to do it as well. On the other hand maybe you are just able to get the PDF as xstring, then the OTF part will not be needed at all.
Maybe this article will help you to know how convert the Adobe Form to xstring: Getting a PDF in an xstring format in the ABAP environment

Yii: Generating PDF document from server response by streaming HTML into PDF

I am new to web development and remember from past that a friend of mine once had an implementation in which Server response stream of HTML was stored in a variable and then output as PDF, this was JSP some ages ago. I don't know how to achieve this in Yii rather bit skeptical if I even remember it right. I have explored TCPDF and can produce the PDF by coding the HTML tags, however, I am looking into the option to stream the output of a URL response in a variable and then use that to generate the PDF. I did the following but it is not working. I receive error at filesize($filename):
$pdf->AddPage();
$filename = 'http://localhost/webapp/index.php/link/to/some/page';
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
$pdf->writeHTML($contents ,true);
I am bit lost on how to achieve this, all the help is much appreciated. Thanks in advance.
If you really want to get the content of a webpage you could achieve that by rendering the page into the controller and assign it to a variable which you can then store in the PDF file
I got the solution with help from other forum. I hope it help those who may wish to achieve the same. The solution is to use Yii-pdf. I have successfully tested it with html2pdf and it works like a charm.