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.
Related
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);
I am unable to upload a file using selenium. I employ the below code:
Browser.FindElement(By.XPath(XPath)).SendKeys(path);
However, all that happens is that the file browse form comes up. The file does not get selected.
Does anyone know what I need to do to get this working, or a workaround? Many Thanks.
Refer to(saucelabs.com/resources/selenium-file-upload)
WebElement upload = driver.findElement(By.id("myfile"));
upload.sendKeys("/Users/sso/the/local/path/to/darkbulb.jpg");
driver.findElement(By.id("submit")).click();
driver.findElement(By.tagName("img"));
Also make sure you have given the path correctly. For example if the file is in d:\abc\pqr.txt, then path needs to be given as
"d:\\abc\\pqr.txt"
Mark this as an answer if this answers your question.
If not, please post your query!
Regards,
Sakshi
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.
This question already has answers here:
Images not showing up on PDF created from HTML
(3 answers)
Closed 7 months ago.
I want to convert HTML emails into a PDF. I have written the following piece of code.
var txt = msgs[i].getBody();
/* We need two blob conversions - one from text to HTML and the other from HTML to PDF */
var blob = Utilities.newBlob(txt, 'text/html',"Test PDF");
Logger.log(txt);
var tempDoc = DocsList.createFile(blob);
var pdf = tempDoc.getAs('application/pdf');
pdf.setName('Email As PDF');
DocsList.createFile(pdf);
The above piece of code first creates a Blob out of the HTML from a Gmail message and uses the getAs() function to convert it to a PDF. However, images in the HTML are not to be found in the PDF. Any ideas on how to get these images would be appreciated.
Any alternative ideas on how to convert a gmail message to PDF is also welcome.
Interesting problem. Makes sense as to why this doesn't work - PDF conversion doesn't bother "rendering" the HTML to go fetch the image src.
I did a quick test and confirmed that Data URI's (inline images without requiring a separate HTTP call) worked with images.
So, one hacky solution could be go fetch the images and then convert them to Data URI. This has a few downsides - hard to find these images (regex would be fragile or not comprehensive), lots of UrlFetch calls (even with some caching, most automated email senders add trackers so that you end up re-fetching the same image) and slow.
Convert -
<img src="http://images.myserver.com/myimage.png..."/>
To (you can check the content type dynamically as well)-
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhE..."/>
I would like to create a webpage data parser and for that needs, I would like it to run in a Dekstop application.
I would like to know if we can import php_curl.dll in a VB.NET applications ?
And if you guys have a little example.. :P I'll enjoy reading it.
Thank you!
Have you seen System.Net.WebClient? This should let you download html (and other content) from the web.
Dim html As String
Using wc As New WebClient()
html = wc.DownloadString("http://stackoverflow.com")
End Using
You have curl on windows so you dont need to take php curl curl download page