• 先安装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. ssl证书生成:cer&jks文件生成摘录

    一.生成.jks文件 1.keystore的生成: 分阶段生成:     keytool -genkey -alias yushan(别名) -keypass yushan(别名密码) -keyalg ...

  2. QT学习笔记1

    不准备用MFC了,想切换到QT.所以跟着网上的一个笔记学习. 1 开发环境是VS2008+QT4.7+VassistX 具体如何配置看这个帖子:http://qimo601.iteye.com/blo ...

  3. Android Studio的git功能的使用介绍

    本文介绍Android Studio(下面简称AS)中git工具的一些简单使用.因为AS为git的使用提供了很多人性化的图形界面操作,在很大程度上可以增加开发效率.本文面向新手,题主自己也是新手一枚, ...

  4. 图论 ---- spfa + 链式向前星 ---- poj 3268 : Silver Cow Party

    Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12674   Accepted: 5651 ...

  5. C# 与 Java 中的枚举

    C#代码: 利用扩展方法,扩展枚举功能 using System; using System.Collections.Generic; using System.Text; using System. ...

  6. IIS MIME类型大全

    文件如果下载不了,可能是iis中的MIME设置问题.格式前面为后辍名,后面为对应的MIME型(例如:rar application/x-rar-compressed 表示.RAR对应的是applica ...

  7. css异常

    1.0 样式的引用顺序不对会导致样式显示不正常.个人推荐:把别人写好的样式引用在最前面,自己写的放在后面. 2.0 UC手机浏览器 UC手机浏览器在识别到页面文字很多的情况下会自动放大字体优化阅读体验 ...

  8. Razor练习3

    Razor语法中,物质循环处理,它使用到三种: for, while,foreach. 下面Insus.NET分别在ASP.NET MVC环境中列举一个例子,附加源代码: while:<br / ...

  9. 一些sql二

    1.说明:复制表(只复制结构,源表名:a 新表名:b) (Access可用)法一:select * into b from a where 1<>1(仅用于SQlServer)法二:sel ...

  10. DokuWiki用storage的模式在sae上部署后速度太慢

    利用sae做的io wrapper接口,对dokuwiki做了基于sae的分布式storage存储改造,能正常安装和运行,但速度太慢,基本没什么用. 定义一个常量: define('SAESTORE_ ...