I am developing a small web application in which I have an object element (that contains an embed) that I use to display small documents.
The documents can be PDFs or plain text files (.txt) that I get from a web service in the form of a base64 string. Then, to show the content, I update the data and src attributes for the object and embed respectively. The final result would look something like this (simplified):
object {
border: 1px solid #ccc;
width: 300px;
height: 100px;
}
<object type="text/plain" data="data:text/plain;base64,SGVsbG8gV29ybGQh">
<embed type="text/plain" src="data:text/plain;base64,SGVsbG8gV29ybGQh" />
</object>
All the PDFs look ok (the browser loads them using the plugin), but I am facing some trouble with the text files. The content of the .txt is displayed correctly, but the text looks a bit small and I was asked to make it larger.
I tried changing the font size of the object and embed but the content is not affected by it:
object, embed {
font-size: 32px;
}
In Chrome, I saw that the content of the object is a #document that displays the content of the base64 .txt in a pre. So I tried to style the pre, but only the pre tags outside the object tag take them, not the one inside it:
pre {
font-size: 32px;
}
Is it possible to give styles to the content of an object/embed? How could it be done?
Here is a pseudo-solution that worked for me in firefox (locally) and not chrome. The idea is to access the content of the object and append to its head a custom CSS. The issue with this solution is that you will face cross-origin issue in some browser as the object behave like an iframe that includes an external content.
NB: i used the setTimeout to be sure i run the function after the content of the object is loaded
function addCss() {
$('object').contents().find("head").append($("<style type='text/css'>pre{font-size:32px;}</style>"));
}
setTimeout(function(){addCss()},2000);
object {
border: 1px solid #ccc;
width: 300px;
height: 100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<object type="text/plain" data="data:text/plain;base64,SGVsbG8gV29ybGQh">
<embed type="text/plain" src="data:text/plain;base64,SGVsbG8gV29ybGQh" />
</object>
Maybe your problem will be how to avoid this cross-origin issue since the content will be yours and server from the same site.
Related
I have the following code
<div class="content">
<p>
Arbeitszeugnisse.pdf
</p>
</div>
where content looks like this
<head>
<style type="text/css">
.content {
width: 35%;
float: left;
padding: 0px;
border: 0px solid #8511ae;
margin-top: 0%;
margin-bottom: 0%;
margin-left: 2%;
margin-right: 3%;
background-color: #faf9d8;
}
</style>
</head>
When clicking on the link, the tab title used to be Arbeitszeugnisse.pdf.
After adding a page to the Arbeitszeugnisse.pdf with PDF Arranger 1.4.2 under Ubuntu 20.04.4 and replacing existing file with the new one, the tab title now prints
Layout 1 - Arbeitszeugnisse.pdf
Similarly I have
Bildungsweg.pdf
Bildungsweg.pdf is made up also of multiple files that were concatenated with PDF Arranger. When clicking on Bildungsweg.pdf, the tab title prints
G0-034-F1-20190701130851 - Bildungsweg.pdf
Is there a way to get clean tab titles with no extra text?
You can use the command line exiftool after every PDF edition. For example:
exiftool -Title="" Bildungsweg.pdf
Leave the flag -Title="" empty, without a string. That way, the web browsers will display the filename instead of the metadata incrusted into the PDF.
Take a look at this Gist about anonymising PDFs.
You could achieve the desired result by setting window.status but if it’s an external file I’d have a look at the meta properties of the file generated.
My understanding of the way files are prepared by the PDF parser is that this can be problematic but I think this is where you should begin your bug hunt.
In case you embed the file here is the JavaScript:
<script type=“text/javascript”>
window.status = ‘hello, world’;
</script>
So I know in HTML you can do
<script src="myscripts.js"></script>
But is it possible to somehow link a html page? For example:
<html src="testing.html"></html>
Well, I'd use an iframe. The <iframe> tag specifies an inline frame. An inline frame is used to embed another document within the current HTML document.
Try this:
<body>
<iframe src="testing.html" frameborder="0" scrolling="yes"></iframe>
</body>
You'll also need some CSS, as follows:
body{
border: 0;
}
iframe {
width: 100vw;
height: 100vh;
}
So, building on the code above here's an example snippet:
body {
border: 0;
}
iframe {
width: 100%;
height: 100%;
}
<body>
<iframe src="https://example.com" frameborder="0" scrolling="yes"></iframe>
</body>
Hope I could help
There some ways you may try, but you may need to read bout it:
<template/> , placeholder tags for you to write new elements
Try using Javascript (limited that you must abide to CORs and also no inline scripts). E.g.
fetch('https://url.com/something.html').then(data => document.getElementById('x').innerHTML = data.text())
Use IFrames. <iframe src=""/>
Use some templating engine depending on languages, like
PUG/Jade (template generator),
Freemarker (Java),
React, angular (JS).
The second 2) option will always introduce security issues and you will also hit some roadblocks in future, e.g. executing scripts, etc.
The third 3) might be a better option if you are putting whole html. Your worries will be in interaction between current page and resize.
But directly injecting HTML on runtime introduces risks, you won't know what will the contents are and it's not a recommended way. You'll also risk into mismatch Html child, e.g.
<html><title><html><title></title></html><body>..
On my site, I recently found a strange new automatically generated div. when I look at it in development tools in chrome I says:
<div id="dp_swf_engine" style="position: absolute; width: 1px; height: 1px;"><embed style="width: 1px; height: 1px;" type="application/x-shockwave-flash" src="http://www.ajaxcdn.org/swf.swf" width="1" height="1" id="_dp_swf_engine" name="_dp_swf_engine" bgcolor="#336699" quality="high" allowscriptaccess="always"></div>
I really don't know what it is, and where it's coming from.
I already had a similar problem and the div came from a chrome extension, check which extension can modify your pages.
Sometimes it will be automatically adding from your web hosting
server
If you are using an external plugins it will be coming from it
I could see you are using google fonts.... Try removing and check your site
You can run your website on a local server...
To hide the DIV, Try adding this css:
<style type="text/css">
dp_swf_engine {
display:none;
}
</style>
Thanks
On the document ready event :
var element = document.getElementById("dp_swf_engine");
document.body.removeChild(element)
if your div is directly in your body element else, find his parent for call removeChildFunction...
I hope that help !
I use google swiffy for convert my swf file to html5.
But now google is upgraded runtime to v 5.2 and can't use transparent background.
Before i use runtime v 4.9 of google swiffy html5 from swf file and in google code i remove this from my javascript file for use transparenty background:
"backgroundColor":-1,
But now runtime is upgraded to v5.2 and i can`t remove background color from swiffy file
https://www.gstatic.com/swiffy/v5.2/runtime.js
This solution work perfectly with flash cs5 -> swiffy v5.3!
#swiffycontainer rect {
background: none !important;
display:none !important;
}
To expand this answer: I'm running Swiffy 5.2.0 and this didn't work at the very beginning since the internal generated code is different in my case, it looks like this:
<div id="my-container">
<!-- Begins Swiffy generated code -->
<div style="position: relative; height: 100%; overflow: hidden; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); background-color: rgb(102, 121, 14); cursor: default; background-position: initial initial; background-repeat: initial initial;">
<svg color-interpolation-filters="sRGB" style="fill-rule: evenodd; pointer-events: none; -webkit-user-select: none; width: 100%; height: 100%;">
<!-- svg contents here -->
</svg>
<!-- Ends Swiffy generated code -->
</div>
</div>
Note that my-container is the container that I assigned in the stage constructor, not generated by Swiffy.
Just check for the generated code and adjust css selector as necessary, the original idea still remains the same:
<style type="text/css">
#my-container div {
background-color: transparent !important;
}
</style>
Roger's solution worked perfectly for me: I'm using Swiffy in a Wordpress Environment, so here's what I did:
1) Add the Swiffy-generated code into the header.php file (actually header-home.php so I could call it for only one page).
2) Before the Swiffy , add Roger's code:
<style type="text/css">
#swiffycontainer div {
background-color: transparent !important;
}
</style>
3) Place the Swiffy-generated code that came AFTER the (before the close of the tag) into the footer.php file (again, footer-home.php in my case).
4) Put the Swiffy container ('id="swiffycontainer"' by default) Div on the WordPress page.
Tah-Dah! I would have simply voted Roger up, but I don't have the rep to do so. Plus I thought my WordPress situation might help others.
<style type="text/css" media="screen">
#div *:first-child {
background-color: transparent !important;
}
</style>
GOOGLE HAVE THE ANSWER:
https://www.google.com/doubleclick/studio/swiffy/faq.html
How can I make the background transparent?
If you need to make the background transparent, as done by the wmode="transparent" attribute, you can insert the following code snippet in the Swiffy output, just before the call to stage.start():
stage.setBackground(null);
You can also replace the null with any valid CSS color specification string to override the background color from the one defined in the conversion.
After searching and searching in the web, and try everything, also described in this post, finally I've find the solution!!
When you export and .swf in flash CS6 to html5 (canvas), open the .html file exported in a html editor and change the background-color attribute to #transparent"
Example:
<body onload="init();" style="background-color:#transparent">
<canvas id="canvas" width="550" height="300" style="background-color:#transparent"></canvas>
</body>
Well, it works fine for me!
You can invoke the "setBackground" method to null after starting up the stage. Like so,
stage.start();
stage.setBackground(null);
I need to display the PDF files from a third party on a webpage. I have links to the documents as they appear on the source pages. Unfortunately, none of the links are actual links to the documents, but rather GET requests with certain parameters, or other indirect references like so:
http://cdm.unfccc.int/UserManagement/FileStorage/SNM7EQ2RUD4IA0JLO3HCZ8BTK1VX5P
If the website does not enforce the download with Content-Disposition: attachment; tag in the response headers, as the one above, then I can easily achieve the necessary display by:
<object width="90%" height="600" type="application/pdf"
data="http://cdm.unfccc.int/UserManagement/FileStorage/SNM7EQ2RUD4IA0JLO3HCZ8BTK1VX5P"
id="pdf_content">
<p>Can't seem to display the document. Try <a href="http://cdm.unfccc.int/UserManagement/FileStorage/SNM7EQ2RUD4IA0JLO3HCZ8BTK1VX5P">
downloading</a> it.</p>
<embed type="application/pdf" src="http://cdm.unfccc.int/UserManagement/FileStorage/SNM7EQ2RUD4IA0JLO3HCZ8BTK1VX5P"
width="90%" height="600" />
</object>
This "stands" and "falls" very gracefully in majority of the browsers. The use of <object> and <embed> at the same time works for me, and, as far as I've tested, does not effect the problem that I describe below (tell me if I'm wrong).
The problem begins when the website does require the download with the above mention tag in the HTTP-headers. For instance, the document on the following link:
http://mer.markit.com/br-reg/PublicReport.action?getDocumentById=true&document_id=103000000000681
would not be displayed through the HTML structure I showed above. It falls gracefully and the link for downloading works just fine, but I need to view it!
I've been banging my head on the wall for 3 days now, can't figure it out.
Maybe there is a way to catch the headers of the request somehow and ignore them, or maybe force the "viewability" into the GET request.
For general information, this is a part of Ruby on Rails application, so the solution should be coming from along those lines. I'm not giving any ROR code in here, because it doesn't seem to be a source of concerns.
Any straight-forward solution would be prayed upon, while any others - heavily appreciated.
The alternative solutions I thought of and discarding comments:
Download all those files to local storage in advance and just serve them from there.
The necessary storage capacity would be around ~1TB and growing, so storing it on the server would be expensive for a small commercial SaaS that it is.
Cache those documents around the time when they might be needed. For instance, when someone opens the page of the project, the process in the background downloads the related PDFs, so if the user clicks the document link he is served the document which was just downloaded to the local storage. Cache could be kept for a few hours/days just in case of user return.
This might be viable, but if the user base would be significant, then this solution would have the same problem as the one above. Also at this moment, I would not know how to go about implementing this kind of algorithm (very much a beginner, you see)
You may want to look into using http://pdfobject.com or maybe just adapt some of its code as it seems to be able to do what you want. I whipped up a proof-of-concept:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Embedding a PDF using PDFObject: Simple example with basic CSS</title>
<!-- This example created for PDFObject.com by Philip Hutchison (www.pipwerks.com) -->
<style type="text/css">
body
{
font: small Arial, Helvetica, sans-serif;
color: #454545;
background: #F8F8F8;
margin: 0px;
padding: 2em;
}
h1
{
font-weight: normal;
font-size: x-large;
}
a:link, a:visited
{
color: #3333FF;
text-decoration: none;
border-bottom: 1px dotted #3333FF;
}
a:hover, a:visited:hover
{
color: #FF3366;
text-decoration: none;
border-bottom: 1px solid #FF3366;
}
#pdf
{
width: 500px;
height: 600px;
margin: 2em auto;
border: 10px solid #6699FF;
}
#pdf p
{
padding: 1em;
}
#pdf object
{
display: block;
border: solid 1px #666;
}
</style>
<script type="text/javascript" src="pdfobject.js"></script>
<script type="text/javascript">
window.onload = function () {
var success =
new PDFObject({ url: "http://mer.markit.com/br-reg/PublicReport.action?getDocumentById=true&document_id=103000000000681" }).embed("pdf");
};
</script>
</head>
<body>
<h1>
Embedding a PDF using PDFObject: Simple example with basic CSS</h1>
<p>
This example uses one line of JavaScript wrapped in a <em>window.onload</em> statement,
with a little CSS added to control the styling of the embedded element.
</p>
<div id="pdf">
It appears you don't have Adobe Reader or PDF support in this web browser. <a href="http://mer.markit.com/br-reg/PublicReport.action?getDocumentById=true&document_id=103000000000681">
Click here to download the PDF </a>
</div>
</body>
</html>