简体   繁体   English

使用数据URI的Base64编码的OpenType字体

[英]Base64 encoded OpenType font-face using data URI

I want to add a base64 encoded OpenType font as a data URI in font-face. 我想添加base64 encoded OpenType字体作为font-face中的数据URI。

I have this so far: 到目前为止,我有:

@font-face {
    font-family: 'test';
    src: url(data:font/otf;base64,
        // Base64 string here ...
    ) format('opentype');
}

But I believe it does not include the font correctly to my style. 但是我认为它没有正确包含我的字体。

Any help with this would be really appreciated. 任何帮助,将不胜感激。

Data URIs are always of this format: 数据URI始终采用以下格式:

data:[<mediatype>][;base64],<data>

The very first part of every data URI is the media-type , which in the case of an Open Type font is: 每个数据URI的第一部分是media-type ,对于Open Type字体,它是:

font/opentype

So, you may use it like this: 因此,您可以这样使用它:

@font-face{
    font-family: test;
    src: url(data:font/opentype; base64, [base64 string here]);
}

Replacing 更换

[base64 string here]

with the exact copy-pasted version of your base-64 encoded string. 与您的base-64编码字符串的复制粘贴版本完全相同。

Notes 笔记

Please note that: 请注意:

  • you should use font/opentype for the data , not otf . 您应该对data使用font/opentype otf ,而不是otf
  • you should copy-paste the exact base-64 encode string, without any changes like added spaces, etc (I believe there are some spaces in it) 您应该复制粘贴确切的base-64编码字符串,而无需进行任何更改,例如添加空格等(我相信其中有一些空格)

Online Encoding Tool 在线编码工具

You may use this tool, to convert your font file to the encoded string. 您可以使用工具将字体文件转换为编码的字符串。

如何将 Base64 编码的 PDF 数据 URI 嵌入到 HTML 5 `<object> `数据属性?<div id="text_translate"><p> 因此,在我的应用程序中,用户可以选择将文件上传到&lt;input type = "file" id = "my-file"&gt; (HTML 5 文件输入)。 我随后可以使用以下 Javascript 获取此文件:</p><pre> var files = $("#my-file").files; var file = files[0];</pre><p> 我可以以某种方式将此var file用作&lt;object&gt;标记中的data吗? 这是 object 标签的示例,其中 PDF 通过点击 URL 并联系服务器来获取。</p><pre> &lt;object data="data/test.pdf" /*&lt;-- I want the var file here */ type="application/pdf" width="300" height="200"&gt; &lt;/object&gt;</pre><p> 我怎样才能做到这一点? 请注意,我必须支持 Internet Explorer 11。</p><p> <strong>更新:</strong></p><p> 我尝试过一些最终以失败告终的事情。 我使用 FileReader 将 PDF 转换为 data-uri,然后在&lt;object&gt;标记的data属性中使用它,该属性在 Chrome 中完美呈现,但在 Internet Explorer 中完全不呈现。</p><pre> var files = $(e.currentTarget.files); file = files[0]; var reader = new FileReader(); reader.onloadend = function() { var data = reader.result; console.log(data); $("#content").prepend('&lt;object id="objPdf" data="'+data+'" type="application/pdf"&gt;&lt;/object&gt;'); }; reader.readAsDataURL(file);</pre><p> 读取器数据的输出如下所示:</p><pre> data:application/pdf;base64,JVBERi0xLjQKJe...</pre><p> <a href="https://msdn.microsoft.com/en-us/library/cc848897(v=vs.85).aspx" rel="nofollow noreferrer">这是 PDF 不能在 Internet Explorer 中使用这种方法的原因</a>(仅限图像)......太伤心了:(</p><p> <strong>更新 2:</strong></p><p> 尝试了<a href="https://github.com/mozilla/pdf.js" rel="nofollow noreferrer">pdf.js</a>并取得了一些成功......它在页面上显示 PDF,尽管它在 Internet Explorer 11 中非常慢(单页 5 秒)。它也一次只显示一页,而&lt;object&gt;标签在一个漂亮的可滚动容器中立即显示所有页面。 虽然这是一个极端的后备选项,但我不想 go 沿着这条路线走。</p><p> 任何人对我如何预览用户直接在网页中上传的 PDF 有任何其他想法吗?</p></div></object> - How to embed a Base64 encoded PDF data URI into a HTML 5 `<object>` data attribute?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用@ font-face - using @font-face 如何将 Base64 编码的 PDF 数据 URI 嵌入到 HTML 5 `<object> `数据属性?<div id="text_translate"><p> 因此,在我的应用程序中,用户可以选择将文件上传到&lt;input type = "file" id = "my-file"&gt; (HTML 5 文件输入)。 我随后可以使用以下 Javascript 获取此文件:</p><pre> var files = $("#my-file").files; var file = files[0];</pre><p> 我可以以某种方式将此var file用作&lt;object&gt;标记中的data吗? 这是 object 标签的示例,其中 PDF 通过点击 URL 并联系服务器来获取。</p><pre> &lt;object data="data/test.pdf" /*&lt;-- I want the var file here */ type="application/pdf" width="300" height="200"&gt; &lt;/object&gt;</pre><p> 我怎样才能做到这一点? 请注意,我必须支持 Internet Explorer 11。</p><p> <strong>更新:</strong></p><p> 我尝试过一些最终以失败告终的事情。 我使用 FileReader 将 PDF 转换为 data-uri,然后在&lt;object&gt;标记的data属性中使用它,该属性在 Chrome 中完美呈现,但在 Internet Explorer 中完全不呈现。</p><pre> var files = $(e.currentTarget.files); file = files[0]; var reader = new FileReader(); reader.onloadend = function() { var data = reader.result; console.log(data); $("#content").prepend('&lt;object id="objPdf" data="'+data+'" type="application/pdf"&gt;&lt;/object&gt;'); }; reader.readAsDataURL(file);</pre><p> 读取器数据的输出如下所示:</p><pre> data:application/pdf;base64,JVBERi0xLjQKJe...</pre><p> <a href="https://msdn.microsoft.com/en-us/library/cc848897(v=vs.85).aspx" rel="nofollow noreferrer">这是 PDF 不能在 Internet Explorer 中使用这种方法的原因</a>(仅限图像)......太伤心了:(</p><p> <strong>更新 2:</strong></p><p> 尝试了<a href="https://github.com/mozilla/pdf.js" rel="nofollow noreferrer">pdf.js</a>并取得了一些成功......它在页面上显示 PDF,尽管它在 Internet Explorer 11 中非常慢(单页 5 秒)。它也一次只显示一页,而&lt;object&gt;标签在一个漂亮的可滚动容器中立即显示所有页面。 虽然这是一个极端的后备选项,但我不想 go 沿着这条路线走。</p><p> 任何人对我如何预览用户直接在网页中上传的 PDF 有任何其他想法吗?</p></div></object> - How to embed a Base64 encoded PDF data URI into a HTML 5 `<object>` data attribute? 压缩base64数据uri图像 - Compressing base64 data uri images 在运行时从 base64 编码字符串应用字体 - Apply font at runtime from base64 encoded string 在 svg 文件中嵌入带有 @font-face 的 base 64 truetype 字体,在 IE 中不起作用 - Embedding a base 64 truetype font with @font-face in a svg file, does not work in IE 在 HTML 中使用 @font-face - Using @font-face in HTML 使用base64编码文本而不是multipart / form-data上传文件 - 好主意? - File upload using base64 encoded text instead of multipart/form-data - good idea? 使用get方法编码的表单数据库base64 - Form data base64 encoded with get method 如何从html图像中获取base64编码数据 - How to get base64 encoded data from html image 如何在元标记中提供 base64 编码的数据 url - How to provide base64 encoded data url in meta tag
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM