• 先安装PDF Creator。

  http://rj.baidu.com/soft/detail/10500.html?ald

  • 把他设置为默认打印机。
  • 在IE中设置打印页面的边距,页眉页脚等。

Powershell脚本

[CmdletBinding()]
param ( [Parameter(Mandatory=$False, Position=0, ValueFromPipeline=$false, HelpMessage='Define the Key')]
[ValidateNotNullOrEmpty()]
[string]$WorkPlace,
[Parameter(Mandatory=$False, Position=0, ValueFromPipeline=$false, HelpMessage='Mail to users split with , ')]
[ValidateNotNullOrEmpty()]
[string[]]$MailTos ) # provide the location where the PDF file will be created #
$OUTPUT_FOLDER="D:\TimeJob\" # a name for the PDF file without the extension #
# without a name the file name is the current timestampt #
$OUTPUT_FILENAME="" # comment following line to add a timestamp to each file gets created
if($OUTPUT_FILENAME.length -eq 0) {$OUTPUT_FILENAME="$WorkPlace" +"_" + (get-date).tostring("yyyyMMdd_HHmmss")} #website
$website="http://www.baidu.com" #$website="https://www.baidu.com/"
###############################################################
# DO NOT WRITE ANYTHING BELOW THIS LINE #
###############################################################
$ErrorActionPreference="Stop"
$WarningPreference="Stop"
$PDFINFOPATH="HKCU:\Software\PDFCreator\Program"
$AUTOSAVEFNAMEPROPERTY="AutoSaveFilename"
$AUTOSAVEDIRPROPERTY="AutoSaveDirectory"
$USEAUTOSAVEPROPERTY="UseAutoSave"
################################################################ function WriteScreenLog {
##
## Write a log entry to the screen
## Usage:
## WriteScreenLog -Message "Message text" [-Type OK|Warning|Error|Info|Verbose] [-printTime] Param (
[Parameter(Mandatory=$True,Position=0)]
[string]$Message, [ValidateSet("OK","Warning","Error", "Info", "Verbose")]
[string]$Type, [switch]$printTime
)
$screenXpos = [Math]::Truncate($Host.UI.RawUI.WindowSize.Width - 11) # Write the message to the screen
$now = ""
if($printTime -eq $true){
$now = (Get-Date -Format "yyyy-MM-dd HH:mm:ss")
$now = "$now | "
}
$Message = $now + $Message
Write-Output $Message if($Type -ne "") {
[Console]::SetCursorPosition($screenXpos, $Host.UI.RawUI.CursorPosition.Y-1)
}
switch ($Type) {
"OK" {Write-Host -BackgroundColor Green -ForegroundColor Black " OK "}
"Warning" {Write-Host -BackgroundColor Yellow -ForegroundColor Black " Warning "}
"Error" {Write-Host -ForegroundColor Yellow -BackgroundColor Red " Error "}
"Info" {Write-Host -BackgroundColor $Host.UI.RawUI.ForegroundColor -ForegroundColor $Host.UI.RawUI.BackgroundColor " Info "}
"Verbose" {Write-Host -BackgroundColor $Host.UI.RawUI.ForegroundColor -ForegroundColor $Host.UI.RawUI.BackgroundColor " Verbose "}
}
} ################################################################
$LogFile="D:\TimeJob\Log\$OUTPUT_FILENAME.txt"
Start-Transcript -Path $LogFile try
{
get-itemproperty -path $PDFINFOPATH -name $AUTOSAVEDIRPROPERTY |out-null
set-itemproperty -path $PDFINFOPATH -name $AUTOSAVEDIRPROPERTY -value $OUTPUT_FOLDER |out-null
}
catch
{
new-itemproperty -path $PDFINFOPATH -name $AUTOSAVEDIRPROPERTY -value $OUTPUT_FOLDER |out-null }
try
{
get-itemproperty -path $PDFINFOPATH -name $USEAUTOSAVEPROPERTY |out-null
set-itemproperty -path $PDFINFOPATH -name $USEAUTOSAVEPROPERTY -value "" |out-null
}
catch
{
new-itemproperty -path $PDFINFOPATH -name $USEAUTOSAVEPROPERTY -value "" |out-null }
finally
{
try
{
$ie=new-object -com internetexplorer.application
$ie.navigate($website)
#depending upon the website sleep parameters here onwards may need adjustment
start-sleep -seconds 5
try
{
get-itemproperty -path $PDFINFOPATH -name $AUTOSAVEFNAMEPROPERTY |out-null
set-itemproperty -path $PDFINFOPATH -name $AUTOSAVEFNAMEPROPERTY -value "$OUTPUT_FILENAME.pdf" |out-null }
catch
{
new-itemproperty -path $PDFINFOPATH -name $AUTOSAVEFNAMEPROPERTY -value "$OUTPUT_FILENAME.pdf" |out-null
}
start-sleep -seconds 5
$ie.execWB(6,2)
start-sleep -seconds 5
$ie.quit()
WriteScreenLog -Message "Success:Save $OUTPUT_FOLDER$OUTPUT_FILENAME.pdf"
#WriteScreenLog -Message "" -Type INFO -printTime
}
catch
{
WriteScreenLog -Message "Error:Save $OUTPUT_FOLDER$OUTPUT_FILENAME.pdf" -Type ERROR -printTime
}
finally
{
try
{
WriteScreenLog -Message "Start to sleep 10 seconds for save PDF report"
Start-Sleep -s 10
WriteScreenLog -Message "Success:Send $OUTPUT_FOLDER$OUTPUT_FILENAME.pdf to $MailTos"
#Start-Sleep -s 60
}
catch
{
WriteScreenLog -Message "Error:Send $OUTPUT_FOLDER$OUTPUT_FILENAME.pdf to $MailTos"
sendReportEmailError "Error:Send $OUTPUT_FOLDER$OUTPUT_FILENAME.pdf to $MailTos"
}
try
{
set-itemproperty -path $PDFINFOPATH -name $AUTOSAVEFNAMEPROPERTY -value "" |out-null
set-itemproperty -path $PDFINFOPATH -name $AUTOSAVEDIRPROPERTY -value "" |out-null
set-itemproperty -path $PDFINFOPATH -name $USEAUTOSAVEPROPERTY -value "" |out-null
}
catch
{
WriteScreenLog -Message "Error:Set item property path value"
}
}
if($LogFile)
{
Stop-Transcript
}
}

Bat 调用

ping 127.0.0.1 -n 6 > nul

powershell "D:\TimeJob\PDF.ps1" -WorkPlace "XXXXX" -MailTos "xxxxxxx,xxxxxxx"

ping 127.0.0.1 -n 2 > nul

使用PDFCreate 和 Powershell 自动保存网页为PDF的更多相关文章

  1. 使用 PowerShell 自动登录Azure

    PowerShell 是管理 Azure 的最好方式之一,通过使用 PowerShell 脚本可以把很多的工作自动化.比如对于 Azure 上的虚拟机,可以设置定时关机操作,并在适当的时间把它开机,这 ...

  2. 一键保存网页为PDF

    一键保存网页为PDF_V1.2   福利来了,“一键保存网页为PDF”发布以来最给力的功能来了: 1.支持大部分浏览器了(添加书签方式),测试IE8\IE9.谷歌.火狐可用: 2.转换组件“ephtm ...

  3. Azure 基础:用 PowerShell 自动登录

    PowerShell 是管理 Azure 的最好方式,因为我们可以使用脚本把很多的工作自动化.比如把 Azure 上的虚拟机关机,并在适当的时间把它开机,这样我们就能节省一些开支,当然我们同时也为减少 ...

  4. 使用PowerShell 自动安装IIS 及自动部署网站

    执行环境:Windows Server 2012 R2 安装iis核心代码,可自定义安装项 注意这里不能使用add-windowsfeature  "Web-Filtering", ...

  5. Azure 基础:用 PowerShell 自动发布 CloudServices

    在软件的开发过程中,自动化的编译和部署能够带来很多的优势.下面我们聊聊如何自动发布云应用程序到 azure 上的 cloud services. 打包要发布的内容 首先使用 msbuild 编译 *. ...

  6. 将HTML页面自动保存为PDF文件并上传的两种方式(一)-前端(react)方式

    一.业务场景 公司的样本检测报告以React页面的形式生成,已调整为A4大小的样式并已实现分页,业务上需要将这个网页生成PDF文件,并上传到服务器,后续会将这个文件发送给客户(这里不考虑). 二.原来 ...

  7. 谷歌浏览器保存网页为pdf和.mhtml文件

    注:需要安装chrome谷歌浏览器,尽可能安装最新版的浏览器: 一:保存为pdf 打开要加载的网页 空白处右键-----打印 配置要打印的pdf网页 点击  左边----> 保存按钮  即可: ...

  8. 使用PowerShell自动部署ASP.NetCore程序到IIS

    Windows PowerShell 是一种命令行外壳程序和脚本环境,使命令行用户和脚本编写者可以利用 .NET Framework的强大功能.有关于更多PowerShell的信息,可参阅百度词条 接 ...

  9. PowerShell自动部署ASP.NET Core程序到 IIS

    Windows PowerShell 是一种命令行外壳程序和脚本环境,使命令行用户和脚本编写者可以利用 .NET Framework的强大功能.有关于更多PowerShell的信息,可参阅百度词条 接 ...

随机推荐

  1. ASP.NET和IIS工作原理

    图为iis6.0运行asp.net的原理. browser向iis发送HTTP请求,HTTP.SYS将其分发给W3SVC(World Wide Web Publishing Service),后者解析 ...

  2. .NET 三层架构的简单规划

    今天心血来潮简单看了下petshop4.0的源代码,他就是用三层架构来实现的.现在简单的做下总结. 首先我们先看下petshop的三层架构. 1 WEB 表示层 2 Model 业务实体 3 BLL ...

  3. Testing - 测试基础 - 自动

    自动化测试模型 一个自动化测试框架就是一个集成体系,在这一体系中包含测试功能的函数库.测试数据源.测试对象识别标准,以及种可重用的模块. 自动化测试框架在发展的过程中,不断有新的模型(概念)被提出,目 ...

  4. Anliven - 如何逼疯你的小伙伴

    如果你也曾为某人某事"发疯发狂,懵逼连连". . 无礼:随意牵扯他人,不了解实际情况,却对他人工作横加点评甚至是指责. 无知:自我感觉良好,自己总是最正确最合理的,除了自己,没人会 ...

  5. Android序列化之Serializable和Parcelable

    PS:还有几天就开学了.先来一发. 学习内容: 1.序列化的目的 2.Android中序列化的两种方式 3.Parcelable与Serializable的性能比较 4.Android中如何使用Par ...

  6. 使用log4j配置不同文件输出不同内容

    敲代码中很不注意写日志,虽然明白很重要.今天碰到记录日志,需要根据内容分别输出到不同的文件. 参考几篇文章: 感觉最详细:http://blog.csdn.net/azheng270/article/ ...

  7. HT for Web基于HTML5的图像操作(二)

    上篇介绍了HT for Web采用HTML5 Canvas的getImageData和setImageData函数,通过颜色乘积实现的染色效果,本文将再次介绍另一种更为高效的实现方式,当然要实现的功能 ...

  8. 【转载】HTTP 错误 500.19 - Internal Server Error

    windows 2008下IIS7 安装ASP.NET 遇到如下错误: HTTP 错误 500.19 - Internal Server Error 无法访问请求的页面,因为该页的相关配置数据无效. ...

  9. Winform 显示Gif图片

    代码如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data ...

  10. Vimium 下载 像个 Geek 一样去浏览

    插件地址(被墙):https://chrome.google.com/webstore/detail/dbepggeogbaibhgnhhndojpepiihcmeb 本地下载:http://file ...