Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
showdown是一個基于Javascript編寫的開源Markdown和HTML相互轉換器,showdown可以用在客戶端(瀏覽器)或者服務端(nodejs)。shodown還支持原始規范中未定義為opt-in特性的“額外”語法。默認情況下不會啟用新的語法元素,需要使用者通過配置啟用它們!
https://github.com/showdownjs/showdown
沒有硬依賴或特殊的安裝說明,只需下載(或使用CDN)并將其包含在您的文件中。
開箱即用,支持許多流行的Markdown風格,如原生的、GFM、commonmark。其他特性,如表、元數據等,可以通過配置啟用。
在服務器端(nodejs)和客戶端(瀏覽器)中都可以使用
它很容易定制和擴展,這意味著你可以添加新的語法或通過擴展或配置修改它的行為
Showdown兼容新舊版本(如IE8+和nodejs0.12)。
用es5編寫,意味著你可以按原樣在項目中使用它,而不需要轉換。
可以使用bower或者npm安裝使用
bower install showdown
npm install showdown
也可以直接使用cdn直接引入以便于直接使用,以下便是線上demo,可實現邊寫邊預覽
showdown的優勢就在于其強大的功能和其非常強的兼容性,而且使用也非常簡單,通過很少的配置就能實現很多豐富的功能!具體如何使用可參考官方文檔,官方文檔就是在一個實時預覽的編輯器中進行展現的!
.NET的SelectPdf Html到Pdf轉換器-社區版是.NET的SelectPdf庫中提供的功能強大的html到pdf轉換器的免費版本。
轉換器提供了許多強大的選項(將任何網頁轉換為pdf,將任何html字符串轉換為pdf,html5 / css3 / javascript支持,頁眉和頁腳支持等),唯一的限制是它最多可以生成pdf文檔。5頁長。
.NET的免費HTML至Pdf轉換器–社區版功能:最多生成5頁pdf文檔,將任何網頁轉換為pdf,將任何原始html字符串轉換為pdf,設置pdf頁面設置(頁面大小,頁面方向,頁面邊距) ,在轉換過程中調整內容大小以適合pdf頁面,設置pdf文檔屬性,設置pdf查看器首選項,設置pdf安全性(密碼,權限),設置轉換延遲和網頁導航超時,自定義頁眉和頁腳,在頁眉中支持html和頁腳,自動和手動分頁符,在每個頁面上重復html表頭,支持@media類型屏幕和打印,支持內部和外部鏈接,基于html元素自動生成書簽,支持HTTP標頭,支持HTTP cookie,支持需要身份驗證的網頁,支持代理服務器,啟用/禁用javascript,修改顏色空間,多線程支持,HTML5 / CSS3支持,Web字體支持等等。
1、nuget 引用
Install-Package Select.HtmlToPdf
2、方法
using SelectPdf;
using System.Collections.Specialized;
using System.IO;
using System.Web;
namespace BQoolCommon.Helpers.File
{
public class WebToPdf
{
public WebToPdf()
{
//SelectPdf.GlobalProperties.LicenseKey="your-license-key";
}
/// <summary>
/// 將 Html 轉成 PDF,並儲存成檔案
/// </summary>
/// <param name="html">html</param>
/// <param name="fileName">絕對路徑</param>
public void SaveToFileByHtml(string html, string fileName)
{
var doc=SetPdfDocument(html);
doc.Save(fileName);
}
/// <summary>
/// 傳入 Url 轉成 PDF,並儲存成檔案
/// </summary>
/// <param name="url">url</param>
/// <param name="fileName">絕對路徑</param>
/// <param name="httpCookies">Cookies</param>
public void SaveToFileByUrl(string url, string fileName, NameValueCollection httpCookies)
{
var doc=SetPdfDocument(url, httpCookies);
doc.Save(fileName);
}
/// <summary>
/// 將 Html 轉成 PDF,並輸出成 byte[] 格式
/// </summary>
/// <param name="html">html</param>
/// <returns></returns>
public byte[] GetFileByteByHtml(string html)
{
var doc=SetPdfDocument(html);
return doc.Save();
}
/// <summary>
/// 傳入 Url 轉成 PDF,並輸出成 byte[] 格式
/// </summary>
/// <param name="url">url</param>
/// <param name="httpCookies">Cookies</param>
/// <returns></returns>
public byte[] GetFileByteByUrl(string url, NameValueCollection httpCookies)
{
var doc=SetPdfDocument(url, httpCookies);
return doc.Save();
}
/// <summary>
/// 將 Html 轉成 PDF,並輸出成 Stream 格式
/// </summary>
/// <param name="html">html</param>
/// <returns></returns>
public Stream GetFileStreamByHtml(string html)
{
var doc=SetPdfDocument(html);
var pdfStream=new MemoryStream();
doc.Save(pdfStream);
pdfStream.Position=0;
return pdfStream;
}
/// <summary>
/// 傳入 Url 轉成 PDF,並輸出成 Stream 格式
/// </summary>
/// <param name="html">html</param>
/// <returns></returns>
public Stream GetFileStreamByUrl(string url, NameValueCollection httpCookies)
{
var doc=SetPdfDocument(url, httpCookies);
var pdfStream=new MemoryStream();
doc.Save(pdfStream);
pdfStream.Position=0;
return pdfStream;
}
private PdfDocument SetPdfDocument(string html)
{
var converter=new HtmlToPdf();
converter.Options.WebPageWidth=1200;
html=HttpUtility.HtmlDecode(html);
return converter.ConvertHtmlString(html);
}
private PdfDocument SetPdfDocument(string url, NameValueCollection httpCookies)
{
var converter=new HtmlToPdf();
converter.Options.WebPageWidth=1200;
if (httpCookies != && httpCookies.Count !=0)
{
converter.Options.HttpCookies.Add(httpCookies);
}
return converter.ConvertUrl(url);
}
}
}
3、調用
/// <summary>
/// 下載pdf
/// </summary>
public void Downpdf(string data)
{
var stream=new BQoolCommon.Helpers.File.WebToPdf().GetFileStreamByHtml(Gethtml(data));
Response.Clear();
//二進制流數據(如常見的文件下載)
Response.ContentType="application/octet-stream";
//通知瀏覽器下載文件而不是打開
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("Profit and Loss Statement.pdf", System.Text.Encoding.UTF8));
var bytes=StreamToBytes(stream);
Response.BinaryWrite(bytes);
Response.Flush();
stream.Close();
stream.Dispose();
Response.End();
}
那么如何獲取指定頁面的html 呢 傳入對應的model 獲得指定動態的html
private string Gethtml(string data)
{
string str="";
str=this.ControllerContext.RenderViewToString("ProfitDetails", data);
return str;
}
using BQoolCommon.Helpers.Format;
using Newtonsoft.Json;
using OrdersManager.Models.ViewModel.Report;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace OrdersManager.Web.Infrastructure
{
public static class HelperExtensions
{
public static string RenderViewToString(this ControllerContext context, string viewName, string data)
{
if (string.IsOrEmpty(viewName))
viewName=context.RouteData.GetRequiredString("action");
context.Controller.ViewData.Model=JsonConvert.DeserializeObject<ProfitDetailsmodel>(StringTools.Base64Decode(StringTools.Base64Decode(data)));
using (var sw=new StringWriter())
{
ViewEngineResult viewResult=ViewEngines.Engines.FindPartialView(context, viewName);
var viewContext=new ViewContext(context,
viewResult.View,
context.Controller.ViewData,
context.Controller.TempData,
sw);
try
{
viewResult.View.Render(viewContext, sw);
}
catch (Exception ex)
{
throw;
}
return sw.GetStringBuilder().ToString();
}
}
}
}
https://www.nuget.org/packages/Select.HtmlToPdf/
大家知道HTML格式嗎?我們通常上網瀏覽的網頁就是HTML格式。而PDF格式是我們常用的一種文件格式,在不同的設備上打開,既不會影響到PDF內容的排版,也不容易被修改。在工作中,有時為了查看PDF文件在網頁狀態下的排版,以及對內容進行編輯修改,我們需要將PDF轉成HTML。可能有些小伙伴們不知道如何轉換。別著急,今天這期PDF轉HTML轉換器推薦,給大家做一下詳細介紹。
轉換方法一:借助“萬能文字識別軟件”完成轉換
安利指數:★★★★☆
安利理由:功能豐富,支持多種格式進行轉換
這款軟件主打文字識別功能,它能夠準確識別圖片、視頻、音頻中的文字內容,并將它們轉換成文字。不止這些,它還能實現全能翻譯、AI修復照片、PDF轉換處理等操作。
像PDF轉成HTML就可以使用這款軟件完成。它的轉換速度很快,如果文件數量較多也不用擔心,我們可以將文件批量上傳,大大提高我們的效率。
轉換流程:
步驟一:打開軟件,找到【PDF轉換處理】,選擇【PDF轉HTML】按鈕。
步驟二:將需要轉換的PDF文件直接拖拽進軟件。
步驟三:點擊【開始轉換】,轉換后的HTML文件默認保存到電腦桌面。轉換成功后,可以點擊查看。
告訴大家一個好消息,我們除了可以在電腦上操作,也可以在手機下載它的APP進行使用哦。如果遇到需要進行翻譯、掃描、PDF轉換處理等情況,也可以使用APP來操作,非常方便!
轉換方法二:借助“WPS”完成轉換
安利指數:★★★☆☆
安利理由:支持文檔表格編輯處理
WPS作為我們經常使用的辦公軟件,擁有對word,PPT等文檔進行編輯的能力,那你知道它還能實現PDF轉HTML的操作嗎?
轉換流程:
首先打開WPS軟件,新建文檔。然后將PDF文件的內容復制到word文檔后保存。保存的格式選擇【單一網頁文件】即可。
以上就是今天的PDF轉HTML轉換器推薦。看完這篇文章,大家知道如何轉換了嗎?有需要的小伙伴,趕快收藏起來吧!
*請認真填寫需求信息,我們會在24小時內與您取得聯系。