Is it possible to embed (inline) a zip file in an XHTML document? - xhtml

Images can be embedded inline encoded as base64 in a xhtml document, for example:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAM0AAAD
NCAMAAAAsYgRbAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5c
cllPAAAABJQTFRF3NSmzMewPxIG//ncJEJsldTou1jHgAAAARBJREFUeNrs2EEK
gCAQBVDLuv+V20dENbMY831wKz4Y/VHb/5RGQ0NDQ0NDQ0NDQ0NDQ0NDQ
0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0PzMWtyaGhoaGhoaGhoaGhoaGhoxtb0QGho
aGhoaGhoaGhoaGhoaMbRLEvv50VTQ9OTQ5OpyZ01GpM2g0bfmDQaL7S+ofFC6x
v3ZpxJiywakzbvd9r3RWPS9I2+MWk0+kbf0Hih9Y17U0nTHibrDDQ0NDQ0NDQ0
NDQ0NDQ0NTXbRSL/AK72o6GhoaGhoRlL8951vwsNDQ0NDQ1NDc0WyHtDTEhD
Q0NDQ0NTS5MdGhoaGhoaGhoaGhoaGhoaGhoaGhoaGposzSHAAErMwwQ2HwRQ
AAAAAElFTkSuQmCC" alt="beastie.png"/>
(source)
Is it possible to do the same with an arbitrary attachment (for example a zip file) that can be downloaded (clicking a link or a button) and accessed using javascript?

Yes.
download
application/octet-stream is a generic MIME type for binary data, generally forces browsers to download the file.
The file itself is from here, though doesn't really work as a zip.
download is a more modern way to force download.

Related

Reading an e pub file

I have files in e pub format. I have to show their contents to the user. How do I read them in asp.net? Can it be done through javascript?
Authoritative? What could be better then a StackOverflow answer? I started from this question ( https://stackoverflow.com/questions/4870594/is-there-a-c-sharp-epub-library ) and gleaned a few usefull links:
Usefull information on displaying text in a web browser using javascript so it paginates nicely: HTML book-like pagination
A C# open source library for reading ePub files, the sample code on the home page includes how to get the contents as HTML: http://epubreader.codeplex.com/
There are other libraries which may come in handy if the ePub reader library on codeplex doesn't pan out: http://sourceforge.net/projects/epubsharp/, and http://www.aspose.com/categories/.net-components/aspose.words-for-.net/default.aspx
You can't do this with just JavaScript of course, you'll have a server side like a web service or code behind on your asp.net webpage which opens the epub file, extracts the contents as HTML and returns it to the client, but I think there is enough here to get you started.
Just to add then i suggest the steps:
Step 1: unzip the file using C#,.net code having some third party library.
Refer : recommend a library/API to unzip file in C#
Step 2: Check whether in the extracted folder there is only one file or more.
Refer: How do I find out how many files are in a directory?
Step 3 :Read the file using stream reader in c#.net
Refer: http://msdn.microsoft.com/en-us/library/aa328963(v=vs.71).aspx
http://www.dotnetperls.com/streamreader
Epub file is actually a zip archive that contains
xml files for meta data, table of contents etc
xhtml or dtbook (xml) + gif, jpeg, png, svg + css for content
To be able to display epub you will have to be able to handle all of the above. Here Reading ePub format you'll find what you have to do to open epub step by step - it's an example for iphone, but it should be enough.

Embedding web fonts in HTML/CSS

Is it possible to embed web fonts in a standalone HTML page using a dataURL or something similar, without having to load them from an external file or address?
that's when you encode the font in base64. you will technically have a "gibberish string" representing that font. this will increase load times since base64 is very long.
there are tools online that do that for you. essentially, it takes the font file, encodes it in base64 and replaces the font location with the base64 encoded version.

adding images to openxml doc created from altchunk

I need an automated process for creating docx files from xhtml source. The xhtml files contain images (<img> elements) whose "src" attributes point to an external reference. But the docx files need to be readable without a network connection, so I need to find a way to embed the images directly into the docx package (namely, in the /media folder).
So far I've used the altChunk method (as described by Eric White) to create the .docx file. I had hoped to use the OpenXML SDK to insert the image parts into the package. But to do that I need to insert paragraphs (<p> nodes) into the document. Unfortunately the document part contains nothing but a reference to the altChunk (stored separately in the docx package). Of course, once the docx is opened, edited and saved, the altChunk part is removed and it’s contents are embedded properly in the document.xml. But I don’t know of any way to do that programatically, so that doesn't help.
Other options I’ve considered:
Partitioning the xhtml into segments, separated between each image, then adding each altChunk one at a time, with the appropriate image reference between each one. (Tedious but seems possible)
Inserting the images into the media folder, and then find way to embed WordProcessingML directly into the xhtml so that the <img> references the packaged image file. (Questionable at best)
Can anyone think of a better approach?
Well, I sorta solved my own problem: I decided to convert the document to mHtml (which can contain images embedded directly in the file) and then use the altchunk to create the final docx file. However, I still wanted to do some post-processing on the file (to insert endnotes in the Word document), but as mentioned above, this is not possible until after the altchunk has been transformed into docx, which cannot be done programmatically.
So it dawned on me that I could bypass the altchunk path altogether and simply use mHtml as the "gateway" from xHtml to docx. I just transformed the xHtml into mHtml, complete with embedded images and endnotes, then renamed the file with a .doc extension. The resulting document can be opened directly by Word (and will be converted more properly on subsequent save). So far it works great (albeit with some bugs in Mac's version of Word, as well as Word2003).

How to embed audio file in HTML if it's being sent as octet-stream?

I'm trying to write a Greasemonkey script that will convert all "Play" links on a page to embedded audio (using the <embed> tag).
When I use a link that I get from a GMail attachment, it works like a charm.
When I use a link from another site (Digium Switchvox), the HTTP response header has ContentType set to "application/octet-stream" instead of "audio/x-wav" (like GMail's link). This confuses Firefox, which decides that I don't have the right plugin installed. If I set the type attribute in the <embed> tag to "audio/x-wav", Firefox uses Quicktime to load the file. Quicktime gets confused, however, and won't play the file.
Does anyone know of a clever way to solve this problem?
have you tried overrideMimeType?
overrideMimeType
String (Compatibility: 0.6.8+) Optional.
A MIME type to specify with the request (E.G. "text/html; charset=ISO-8859-1").

What are the best practices for using HTML with XML based languages like SVG?

From browsing on this site and elsewhere, I've learned that serving websites as XHTML at present is considered harmful.
Delivering XHTML and serving it as application/xhtml+xml isn't supported by the majority of people browsing at present, delivering xhtml as text/html is at best a placebo for myself, and at worst a recipe for breaking sites usually when you least need it happening.
So we end up back at html 4.01. If I instead serve my pages as html 4.01, is it possible to use SVG or any other XML-based language on the page?
If so, how?
In HTML you won't be able to insert SVG directly.
You can embed SVG files with <object>/<embed> and in cutting-edge browsers (Opera, Safari) also <img> and CSS background-image.
You can put SVG in data: URI to avoid using external files.
Simple mathematical expressions can be written with help of Unicode and basic HTML/CSS (Opera 9.5 supports large chunk of MathML via CSS). For anything more complex you'll need to use images, like Wikipedia does.
HTML misinterprets namespace prefixes, so you won't be able to (properly) use other XML markup with HTML DOM. HTML5 has data-* attributes for application-specific markup additions. For metadata consider Microformats.
However if you want to embed XML only for non-browsers (robots), then you could use HTML-compatible XHTML subset and HTTP content negotiation to send proper XML with proper type to clients that understand it (if you thoroughly test page in both XML and HTML modes, then it won't be harmful).
You may (read I haven't tried this myself) to use an embedded object and type it accordingly.

Resources