• 先安装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. 聚合索引(clustered index) / 非聚合索引(nonclustered index)

    以下我面试经常问的2道题..尤其针对觉得自己SQL SERVER 还不错的同志.. 呵呵 很难有人答得好.. 各位在我收集每个人擅长的东西时,大部分都把SQL SERVER 标为Expert,看看是否 ...

  2. 25套用于 Web UI 设计的免费 PSD 网页元素模板

    Web 元素是任何网站相关项目都需要的,质量和良好设计的元素对于设计师来说就像宝贝一样.如果您正在为您的网站,博客,Web 应用程序或移动应用程序寻找完美设计的网页元素,那么下面这个列表会是你需要的. ...

  3. 使用James搭建一个自己的邮箱服务器

    ---第一天开发--- 下载Apache James 3.0邮箱服务器,解压到响应的目录 可以看到目录结构: H:\code\JavaCode\James\apache-james-3.0-beta4 ...

  4. C#--静态字段

  5. Think different

    Here's to the crazy ones.The misfits.The rebels.The troublemakers.The round pegs in the square holes ...

  6. rtf格式的一些说明,转载的

    RTF是Rich TextFormat的缩写,意即多文本格式.这是一种类似DOC格式(Word文档)的文件,有很好的兼容性,使用Windows"附件"中的"写字板&quo ...

  7. SQLServer存储过程中事务的使用

    create proc usp_Stock @GoodsId int, @Number int, @StockPrice money, @SupplierId int, @EmpId int, ), ...

  8. Type 'Insus.NET.PictureObject' in Assembly 'App_Code, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

    昨晚想实现一个功能,需要把一个对象存储于ViewState中去,但在运行时,出现下面的异常. Type 'Insus.NET.PictureObject' in Assembly 'App_Code, ...

  9. Nancy 学习-自宿主 继续跨平台

    Nancy简介 Nancy是一个轻量级的独立的框架,下面是官网的一些介绍: Nancy 是一个轻量级用于构建基于 HTTP 的 Web 服务,基于 .NET 和 Mono 平台,框架的目标是保持尽可能 ...

  10. c#初学-多线程中lock用法的经典实例

    本文转载自:http://www.cnblogs.com/promise-7/articles/2354077.html 一.Lock定义     lock 关键字可以用来确保代码块完成运行,而不会被 ...