導航:首頁 > 文檔加密 > htmltopdf在線

htmltopdf在線

發布時間:2022-07-30 08:48:50

⑴ 如何利用js或php將html網頁轉為pdf

首先需要安裝wkhtmltopdf這個軟體 需要執行shell_exec函數的php文件和安裝的wkhtmltopdf.exe可執行文件在同一目錄下,不然php找不到這個執行文件

shell_exec("wkhtmltopdf.exe --page-size A4 --outline 網頁地址 pdf文件名");
--page-size 以A4紙的尺寸顯示pdf內容
--outline 顯示目錄(網頁中h1,h2來定)
網頁地址 需要轉成pdf的網頁地址
pdf文件名 生成pdf的文件名,可以使用絕對路徑

⑵ 把網頁轉成PDF[html to pdf]

使用 TuesPechkin (C#)類庫, 這個是將wkhtmltopdf(C++) 使用?C# 進行的封裝

使用方便 ,

publicpartialclassDefault:System.Web.UI.Page
{

privateIConverterconverter=
newStandardConverter(
newPdfToolset(
newWin64EmbeddedDeployment(
newTempFolderDeployment())));

protectedvoidPage_Load(objectsender,EventArgse)
{
stringhtmlPath=Server.MapPath("~/index.html");
stringhtmlContext=System.IO.File.ReadAllText(htmlPath);


vardoc=newHtmlToPdfDocument();
doc.Objects.Add(newObjectSettings(){HtmlText=htmlContext});
doc.Objects.Add(newObjectSettings{PageUrl="http://news.ifeng.com/history/special/yuanshikai/

});

varresult=converter.Convert(doc);
varpath=@"d: ext.pdf";

System.IO.File.WriteAllBytes(path,result);
}
}

源碼地址: https://github.com/tuespetre/TuesPechkin

⑶ 使用wkhtmltopdf把html轉成pdf,怎麼生成書簽或目錄

輪廓選項
--mp-outline <file> 轉儲目錄到一個文件
--outline 顯示目錄(文章中h1,h2來定)
--outline-depth <level> 設置目錄的深度(默認為4)
以下是舉例(可能需要修改參數,確保頁面內有h1標簽)
wkhtmltopdf.exe --page-size A4 --outline 網頁地址 pdf文件名

⑷ 怎樣用java把html轉為pdf

java中利用第三方jar包iText 5.4.2就可以實現html轉為pdf。

比如有如下index.html文件:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<title>HTML to PDF</title>

<link href="style.css" rel="stylesheet" type="text/css" />

</head>

<body>

<h1>HTML to PDF</h1>

<p>

<span class="itext">itext</span> 5.4.2 <span class="description"> converting HTML to PDF</span>

</p>

<table>

<tr>

<th class="label">Title</th>

<td>iText - Java HTML to PDF</td>

</tr>

<tr>

<th>URL</th>

<td>http://hmkcode.com/itext-html-to-pdf-using-java</td>

</tr>

</table>

</body>

</html>

樣式文件:

h1 {

color:#ccc;

}

table tr td{

text-align:center;

border:1px solid gray;

padding:4px;

}

table tr th{

background-color:#84C7FD;

color:#fff;

width:100px;

}

.itext{

color:#84C7FD;

font-weight:bold;

}

.description{

color:gray;

}

後台轉換的介面:

package com.hmkcode;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import com.itextpdf.text.Document;

import com.itextpdf.text.DocumentException;

import com.itextpdf.text.pdf.PdfWriter;

import com.itextpdf.tool.xml.XMLWorkerHelper;

public class App

{

public static void main( String[] args )throws DocumentException, IOException

{

// step 1

Document document =new Document();

// step 2

PdfWriter writer = PdfWriter.getInstance(document,new FileOutputStream("pdf.pdf"));

// step 3

document.open();

// step 4

XMLWorkerHelper.getInstance().parseXHtml(writer, document,

new FileInputStream("index.html"));

//step 5

document.close();

System.out.println("PDF Created!" );

}

}

轉換結果:

⑸ java怎麼把HTML界面做成pdf格式列印

public boolean convertHtmlToPdf(String inputFile, String outputFile)
throws Exception {

OutputStream os = new FileOutputStream(outputFile);
ITextRenderer renderer = new ITextRenderer();
String url = new File(inputFile).toURI().toURL().toString();

renderer.setDocument(url);

// 解決中文支持問題
ITextFontResolver fontResolver = renderer.getFontResolver();
fontResolver.addFont("C:/Windows/Fonts/SIMSUN.TTC", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
//解決圖片的相對路徑問題
renderer.getSharedContext().setBaseURL("file:/D:/");
renderer.layout();
renderer.createPDF(os);

os.flush();
os.close();
return true;
}

上面這段代碼是這樣的,輸入一個HTML地址URL = inputFile,輸入一個要輸出的地址,就可以在輸出的PDF地址中生成這個PDF。

⑹ 如何用Aspose.Pdf將html轉換為pdf格式

安裝adobe
acrobat之後在瀏覽器上就會有轉換插件,可以直接把網頁轉成PDF文件,如果找不到插件,也可以打開adobe
acrobat從創建菜單下面「從網頁創建PDF「選項即可。網上還有HtmltoPDF轉換都可以把html文件轉成PDF。

⑺ 請教一個關於 wkhtmltopdf 實現 html 轉 pdf 的小問題

wkhtmltopdf 很好用,但也有些不盡人意。就是當一個html頁面很長我需要在指定的地方分頁那怎麼辦呢? wkhtmltopdf 開發者在開發的時候並不是沒有考慮到這一點,
wkhtmltopdf 有個很好的方法,就是在那個div的樣式後添加一個:page-break-inside:avoid;就ok了。

⑻ WkHtmlToPdf在windows環境下怎麼用,php語言實現

安裝wkhtmltopdf
# apt-get install wkhtmltopdf

從HTML生成PDF文件的基本語法如下:
# wkhtmltopdf input-file output-file

我們可以從任何網頁生成PDF:
# wkhtmltopdf example.com example.pdf

或從本地html文件:
# wkhtmltopdf example.html example.pdf

以上命令只能在Linux box 圖形環境中使用。如果我們在一個VPS或專用伺服器上生成PDF,如果我們執行該命令,我們將得到從下錯誤:
wkhtmltopdf: cannot connect to X server

為了解決這個問題,我們需要使用一個名為 xvfb 的工具。
Xvfb是一個 X 伺服器,能夠運行在沒有顯示硬體和沒有物理輸入設備的機器上。它使用虛擬內存來模擬一個mb framebuffer。
回到頂部
安裝 xvfb
# apt-get install xvfb

接下來,我們需要創建一個shell腳本:
xvfb-run --server-args="-screen 0, 1024x768x24" /usr/bin/wkhtmltopdf $*

然後將它保存在 /usr/bin/wkhtmltopdf.sh 下
下一步,我們將創建一個 symbolic 鏈接,這樣我們就可以執行腳本而不用編寫的完整路徑:

# ln -s /usr/bin/wkhtmltopdf.sh /usr/local/bin/wkhtmltopdf2

讓我們嘗試執行shell腳本,並看看會發生什麼。
# wkhtmltopdf2 example.com example.pdf
Loading page (1/2)
Printing pages (2/2)
Done

好,如果能夠正確運行。就可以用以下自定義PHP腳本來生成一個PDF文件。
//Turn on output buffering
ob_start();

echo "<html>";
echo "<head>";
echo "<link href='http://example.com/style.css' rel='stylesheet' type='text/css'>";
echo "</head>";
echo "<body>";
echo "<p>custom HTML to PDF report</p>";
echo "</body>";
echo "</html>";

//return the contents of the output buffer
$html = ob_get_contents();
$filename = date('YmdHis');

//save the html page in tmp folder
file_put_contents("/tmp/{$filename}.html", $html);

//Clean the output buffer and turn off output buffering
ob_end_clean();

//convert HTML to PDF
shell_exec("wkhtmltopdf2 -q /tmp/{$filename}.html /tmp/{$filename}.pdf");
if(file_exists("/tmp/{$filename}.pdf")){
header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename='{$filename}.pdf'");
echo file_get_contents("/tmp/{$filename}.pdf");
}else{
exit;
}

⑼ 如何把另存為的網頁(顯示為一個文件夾和一個瀏覽頁面那種)轉為PDF 或word

其實你找個抓圖軟體或者用QQ截圖抓全屏或者資料位置,反正你製作成PDF也是圖片,還不如抓圖片變成JPG圖像呢,反正你要的就是資料,東西是死的,人是活的,如何靈活應用就看你自己了,JPG比HTML更容易製作PDF文件,而且圖片插入WORD你也懂的。

如果確實要網頁轉換,那就建議網路搜索 HTML to PDF 或者 HTML TO WORD

⑽ 如何將html頁面轉成pdf

1安裝Adobe Acrobat後會默認在IE瀏覽器中添加PDF工具欄。
該工具可以方便的將網頁轉化成PDF文檔,或者添加入已有的PDF文檔,Adobe PDF Explorer工具欄則可以在IE的收藏夾界面內管理window內的HTML文檔與PDF文檔的轉化。


2、安裝單獨的pdf虛擬列印機(pdffactory、ultra pdf等),通過網頁的列印功能轉換。



3使用客戶端軟體HTML2PDF_Pilot。
HTML2PDF_Pilot的截面如上圖,很簡潔。
如果只是要完成最簡單的工作只需如箭頭所示,點擊上方的添加按鈕添加HTML文檔然後點擊轉換,稍等既可以完成一個HTML文檔的轉化工作。
兩種方法的比較
靈活性:
PDF工具欄的方式相比客戶端的方式要靈活許多。
在使用的過程中發現HTML2PDF_Pilot不能通過URL(網址)直接轉化PDF文檔,而工具欄只需在瀏覽的過程隨意使用。
功能:在功能的環節上,客戶端方式的HTML2PDF_Pilot就明顯要比PDF工具欄要強大許多
工具欄只提供了最基本的保存和添加入已有文檔的功能,而HTML2PDF_Pilot則提供了更為豐富的選項。
另外,如果需要批量轉化網頁文件的話,工具欄的方式也無法提供對應的功能。
其實還是有很多可以選擇的方式,比如把網頁轉化為WORD的文件格式然後通過WPS軟體來轉化文檔等,只要能靈活運用,html文件轉PDF是非常簡單的事情。

閱讀全文

與htmltopdf在線相關的資料

熱點內容
c語言常用演算法pdf 瀏覽:960
編程如何讓畫面動起來 瀏覽:865
大齡女程序員未來發展 瀏覽:976
數學書籍pdf 瀏覽:506
加密門禁卡寫入成功無法開門 瀏覽:464
齒輪傳動pdf 瀏覽:52
alpinelinux 瀏覽:150
手機端app的掃碼功能在哪裡 瀏覽:227
少兒編程中小班英語教案 瀏覽:452
鎖屏密碼加密手機怎麼解除 瀏覽:205
linuxlostfound 瀏覽:135
征途伺服器ip地址 瀏覽:330
git提交代碼命令行 瀏覽:165
什麼叫瀏覽器伺服器結構 瀏覽:157
於謙聊天哪個app 瀏覽:449
小鵬汽車nlp演算法工程師薪資 瀏覽:881
代碼加密與隱藏 瀏覽:649
fordfulkerson演算法 瀏覽:352
京東熱app在哪裡可以下載 瀏覽:877
彩報圖書app哪個好 瀏覽:303