htmlRenderer.PDFSharp not converting labels - html

I am trying to get familiar with htmlRenderer.pdfsharp and have come across an issue that I am trying to figure out. It is not rendering the following HTML:
<td><label for=\"Date\">Date</label></td>
The code I am using to generate the PDF is from one of their examples but it is as follows:
PdfDocument pdf = PdfGenerator.GeneratePdf(html, PageSize.Letter);
The rest of the HTML is populating just fine and am not sure where to go from here with the HTML Renderer. Anyone else ran into this issue and have a fix?
Edit: I removed calling it PDFSharp's html render and linked to the nuget package I am using for htmlRender.pdfsharp.

Related

Getting Image through HTML and using Python Code

I am trying to make a website that gets the user image and uses
facelandmark code(python) to tell the user about user's face shape and etc.
How can I get the imange through html and use the image file in python code and show the result to the user again? Is using django the only way? I have tried to study django in many ways and most of the stuffs I found were not directly helping on my planning website. Thank you for reading
You can use this code to directly embed the image in your HTML: Python 3
import base64
data_uri = base64.b64encode(open('Graph.png', 'rb').read()).decode('utf-8')
img_tag = '<img src="data:image/png;base64,{0}">'.format(data_uri)
print(img_tag)

splinter nested <html> documents

I am working on some website automation. Currently, I am unable to access a nested html documents with Splinter. Here's a sample website that will help demonstrate what I am dealing with: https://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_select
I am trying to get into the select element and choose the "saab" option. I am stuck on how to enter the second html document. I've read the documentation and saw nothing. I'm hoping there is a way with Python.
Any thoughts?
Before Solution:
from splinter import Browser
exe = {"executable_path": "chromedriver.exe"}
browser = Browser("chrome",**exe, headless=False)
url = "https://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_select"
browser.visit(url)
# This is where I'm stuck. I cannot find a way to access the second (nested) html doc
innerframe = browser.find_by_name("iframeResult").first
innerframe.find_by_name("cars")[0]
Solution:
from splinter import Browser
exe = {"executable_path": "chromedriver.exe"}
browser = Browser("chrome",**exe, headless=False)
url = "https://www.w3schools.com/html/tryit.asp?filename=tryhtml_elem_select"
browser.visit(url)
with browser.get_iframe("iframeResult") as iframe:
cars = iframe.find_by_name("cars")
cars.select("saab")
I figured out that these are called iframes. Once I learned the terminology, it wasn't too hard to figure out how it interact with it. "Nested html documents" was not returning the results I needed to find the solution.
I hope this helps someone out in the future!

Saving R timevis timeline in html webpage

I'm sure I'm missing a basic issue but I'm not currently able to find my way out of this problem.
Is there a way to save a simple (not Shiny) Timevis timeline in html webpage from the code?
I've successfully tried by using RStudio export button but I would like to include the function in the code.
htmlwidgets::saveWidget() doesn't work properly as the webpage is incomplete e.g. zoom buttons are missing (see incomplete webpage print screen) even with a minimal code:
myTimeline<-timevis(
data.frame(id = 1:2,
content = c("one", "two"),
start = c("2016-01-10", "2016-01-12"))
)
htmlwidgets::saveWidget(myTimeLine,"myTimeLine.html")
Thank in advance for any help and advice!
There is an open issue on github about this.
The workaround is to use selfcontained = FALSE:
htmlwidgets::saveWidget(myTimeline, "myTimeLine.html", selfcontained = F)
If you want to use a selfcontained version (e.g. because you want to offer this htmlwidget via plumber), the issue is the lack of zoom buttons.
If you modify the output HTML content to re-include the zoom buttons properly, everything works fine.

What is the best way to scrape this webpage? fromJSON doesnt seem to work

I have been happily scraping parts of this mobile app website using getURL and fromJSON (jsonlite package in R). For example, I have been using this code and it is fairly straight forward:
CardURL = getURL("http://m.racingpost.com/#cards-horse/horse_id=901690& race_id=639116&r_date=2015-12-07")
CardDATA = fromJSON(CardURL)
CardDATA[["tab-card"]][["runners"]]
However when i got to this particular part of the webpage it doesn't work in same way as other sections:
http://m.racingpost.com/#cards-horse/horse_id=901690&race_id=639116&r_date=2015-12-07
It seems to return with text like 'your browzer isn't optimised' rather than returning the actual text I want to scrape. What is the best way to scrape data like this?
thanks

Rendering PDF using object/embed/iframe is not working properly

I am trying to display PDF for preview using object/embed/iframe html tags, but its not working as expected.
Can someone point out what is going wrong here?
Here is my bit of code:
In HTML _PDFPreview.cshtml:
#model byte[]
<div style="width: 875px;">
<object id="previewPdf" data="data:application/pdf;base64,#Convert.ToBase64String(Model)" style="overflow: visible;"/>
</div>
In Controller action:
public ActionResult SomeActionMethod()
{
// some logic to get pdfResult object
return View("~/View/_PDFPreview.cshtml", pdfResult.BuildPdf(ControllerContext));
}
Note: I am using Rotativa NuGet package for generating the PDF. The action method returns view with proper data. But in browser it ends up in getting blank screen.
Test Case: On changing object tag to iFrame it works in Chrome but not in FireFox.
I will appreciate any kind of relevant suggestions.
Thanks in Advance.
Got the fix!
"Test Case: On changing object tag to iFrame it works in Chrome but not in FireFox."
My bad. It was due the FF browser setting that was directly downloading the file instead of previewing. On changing the setting the issue got fixed.
Thanks.