try { var mergeFilePath = string.Format("{0}mergepdf.pdf", tempDownDir); PDFPrintHelper.MergePDFFile(pdfList, mergeFi
winform 按顺序连续打印多个PDF文件
关于PDF打印的问题,前面有篇文章(点这里查看)也叙述过,今天来谈谈另外一种方法
其实方法很简单,因为需要把多个PDF文档按顺序连续打印,为此我们为什么不把要打印的pdf文档按顺序合并成一个PDF打印呢?如此就简单多了哦。
这里文章写出来并不是为了炫耀什么,只是觉得发现些好东西就分享出来而已,同时也做个记录,方便以后查找
开始正文
1、为了方便,打印方法就不另寻他路了,和前面一致,具体如下:
Process proc = new Process();
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.FileName = itemPath;//打印文件路径(本地完整路径包括文件名和后缀名)
proc.StartInfo.Verb = "print";
proc.Start();
proc.Close();
2、就是重点了,合并PDF文档,方法很简单,网上一搜一大把,因为我的需求需要把jpg图片和pdf一起打印,因此合并方法中包含图片
使用此方法需要第三方控件iTextSharp.dll(点击这里下载)
/// <summary>
/// 把多个PDF文件和JPG/PNG图合并成一个PDF文档
/// </summary>
/// <param name="fileList">需要合并文件的完整路径列表</param>
/// <param name="outMergeFile">输出文件完整路径</param>
public static void MergePDFFile(List<string> fileList, string outMergeFile)
{
PdfReader reader;
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(outMergeFile, FileMode.Create));
document.Open();
PdfContentByte cb = writer.DirectContent;
PdfImportedPage newPage;
foreach (var itemFile in fileList)
{
if (!File.Exists(itemFile))
{
string fileName = Path.GetFileName(itemFile);
LogMessageWrite.WriteMessage(string.Format("文件打印合并__{0} 文件不存在", fileName));
continue;
}
FileInfo fInfo = new FileInfo(itemFile);
if (fInfo.Length < 1)
{
string fileName = Path.GetFileName(itemFile);
LogMessageWrite.WriteMessage(string.Format("文件打印合并__文件内容为空,无法打印,{0}", fileName));
return;
} var ext = Path.GetExtension(itemFile).ToLower();
if (".pdf".Equals(ext))
{
reader = new PdfReader(itemFile);
int iPageNum = reader.NumberOfPages;
for (int j = 1; j <= iPageNum; j++)
{
document.NewPage();
newPage = writer.GetImportedPage(reader, j);
cb.AddTemplate(newPage, 0, 0);
}
}
else if (".jpg".Equals(ext) || ".jpge".Equals(ext) || ".png".Equals(ext))
{
FileStream rf = new FileStream(itemFile, FileMode.Open, FileAccess.Read);
int size = (int)rf.Length;
byte[] imext = new byte[size];
rf.Read(imext, 0, size);
rf.Close();
Image img = Image.GetInstance(imext);
//调整图片大小,使之适合A4
var imgHeight = img.Height;
var imgWidth = img.Width;
if (img.Height > iTextSharp.text.PageSize.A4.Height)
{
imgHeight = iTextSharp.text.PageSize.A4.Height;
}
if (img.Width > iTextSharp.text.PageSize.A4.Width)
{
imgWidth = iTextSharp.text.PageSize.A4.Width;
}
img.ScaleToFit(imgWidth, imgHeight);
//调整图片位置,使之居中
img.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
document.NewPage();
document.Add(img);
}
}
document.Close();
}
3、打印合并后的文件
try
{
var mergeFilePath = string.Format("{0}mergepdf.pdf", tempDownDir);
PDFPrintHelper.MergePDFFile(pdfList, mergeFilePath);
Process proc = new Process();
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.FileName = mergeFilePath;//打印文件路径(本地完整路径包括文件名和后缀名)
proc.StartInfo.Verb = "print";
proc.Start();
proc.Close();
}
catch (Exception ex)
{
LogMessageWrite.WriteMessage(ex.Message);
}
至此 大功告成
一、CSS兼容代码
|
1
2
3
4
5
6
|
.transparent { filter:alpha(opacity=50); /* IE */ -moz-opacity:0.5; /* FireFox old version*/ -khtml-opacity: 0.5; /* Sarfari old version */ opacity: 0.5; /* FireFox */} |
二、Javascript兼容代码
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
if (!window.jasen.core.Util) { window.jasen.core.Util = {}; } var $ = function (id) { return document.getElementById(id); } function style(element, key, value) { if (typeof element == "string") { element = $(element); } if (value) { element.style[key] = value; } else { return element.style[key]; } }; function opacity(element, /*0-100*/opacityValue) { var opacityValue = parseInt(opacityValue); style(element, "filter", "alpha(opacity=" + opacityValue + ")"); opacityValue /= 100.0; style(element, "MozOpacity", opacityValue); style(element, "KhtmlOpacity", opacityValue); style(element, "opacity", opacityValue); }; var Util = window.Util = window.jasen.core.Util; Util.opacity = opacity; Util.style = style; |
三、范例

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
#content
{
width:300px;
margin:20px auto;
}
</style>
<script src="Scripts/jasen.Core.Util.js" type="text/javascript"></script>
<script type="text/javascript">
window.onload = function () {
var seletor = document.getElementById("opacitySeletor");
seletor.options.add(new Option("--请选择--", "100")); for (var i = 0; i <= 100; i++) {
seletor.options.add(new Option(i, i));
} seletor.onmousewheel = function (event) {
event = event || window.event;
var currentIndex = seletor.selectedIndex - event.wheelDelta / 120; if (currentIndex < 0) {
seletor.selectedIndex = seletor.options.length - 1;
}
else if (currentIndex > seletor.options.length - 1) {
seletor.selectedIndex = 0;
}
else {
seletor.selectedIndex = currentIndex;
} seletor.onchange();
return false;
}
} function changeOpacity() {
var element = document.getElementById("opacitySeletor"); if (element.selectedIndex < 0) {
return;
} var opacityValue = element[element.selectedIndex].value; if (opacityValue != "") {
Util.opacity("opacityImg", opacityValue);
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="content">
<select id="opacitySeletor" onchange="return changeOpacity();"></select>
<img id = "opacityImg" src="Images/car.jpg" title="car opacity" alt="car opacity" />
</div>
</div>
</form>
</body>
</html>

try { var mergeFilePath = string.Format("{0}mergepdf.pdf", tempDownDir); PDFPrintHelper.MergePDFFile(pdfList, mergeFi的更多相关文章
- 工作总结 @{var sas = String.Format("{0:yyyy-MM-dd}", Model.DemandTime.GetValueOrDefault());}
可空DateTime类型 无法Tostring 或者 格式化时间格式 需要转换 为DateTime Nullable<T>.GetValueOrDefault() 方法 返回对应的 ...
- 这种写法用过没:string.Format("{0,-10}", 8)
1 2 3 4 var s1 = string.Format("{0,-10}", 8); var s2 = string.Format("{0,10}", 8 ...
- String.format("%0"+length+"d", arr)中的%0和"d"分别代表什么
public static void main(String[] args) { int a = 8; String s = String.format("%04d", a); S ...
- C# string.Format("{0:C3}", 2)
- C# String.Format的格式限定符与Format方法将多个对象格式化一个字符串原理
Format方法将多个对象格式化成一个字符串Format方法解析格式字符串的原理: (1).格式字符串中的{0}会被替换成格式字符串之后的第一个参数,以此类推 (2).Format方法解析格式字符串时 ...
- C#:String.Format数字格式化输出 {0:N2} {0:D2} {0:C2}等等
int a = 12345678; //格式为sring输出// Label1.Text = string.Format("asdfadsf{0}adsfasdf",a); / ...
- C# String.Format大全 去 decimal 后面的 0
转 http://kwon.iteye.com/blog/1068255 http://blog.csdn.net/tvvbbb/article/details/47256943 public st ...
- String.Format数字格式化输出 {0:N2} {0:D2} {0:C2
//格式为sring输出 // Label1.Text = string.Format("asdfadsf{0}adsfasdf",a); // Label2.Text = ...
- 【转】C# String.Format数字格式化输出各种转换{0:N2} {0:D2} {0:C2}...
; //格式为sring输出 // Label1.Text = string.Format("asdfadsf{0}adsfasdf",a); // Label2.Text = & ...
随机推荐
- hdu 新生晚会
Problem Description 开学了,杭电又迎来了好多新生.ACMer想为新生准备一个节目.来报名要表演节目的人很多,多达N个,但是只需要从这N个人中选M个就够了,一共有多少种选择方法? ...
- HTML DOM的nodeName,nodeValue,nodeType介绍
将HTML DOM中几个常用的属性做下介绍,工作中作为参考. nodeName 属性可依据节点的类型返回其名称. 元素节点的 nodeName 是标签名称 属性节点的 nodeName 是属性名称 文 ...
- Jenkins + robot framework + git持续集成
安装略过... 一.Jenkins安装插件 进入系统管理—插件管理—可选插件下安装以下插件Git Client Plugin.GIT plugin.GitHub API Plugin.GitHub p ...
- bigdata_一篇文看懂Hadoop
本文转载:暂未找到原出处,如需署名 请联系 我们很荣幸能够见证Hadoop十年从无到有,再到称王.感动于技术的日新月异时,希望通过这篇内容深入解读Hadoop的昨天.今天和明天,憧憬下一个十年. 本文 ...
- svnclient本地化和异常处理
svn中国本土化,首次安装client.然后下载语言包的相应版本,然后将语言设置为英文! 我碰到汉化失败的案例:client与语言包版本号不匹配 之前安装的语言包: 下载相应语言包: 假设之前安装了, ...
- 【Java编码准则】の #12不要使用不安全或者强度弱的加密算法
安全性要求高的应用程序必须避免使用不安全的或者强度弱的加密算法,现代计算机的计算能力使得攻击者通过暴力破解能够攻破强度弱的算法.比如,数据加密标准算法DES是极度不安全的,使用类似EFF(Electr ...
- 完全用Linux工作,抛弃windows
录一篇旧文 作者:王垠 完全用Linux工作,抛弃windows 我已经半年没有使用 Windows 的方式工作了.Linux 高效的完成了我所有的工作. GNU/Linux 不是每个人都想用的.如果 ...
- 网页动态切换母版页(MasterPage)
原文:网页动态切换母版页(MasterPage) 是否可以变更网页的母版页(MasterPage)呢?某.aspx在创建时,已经附加入某一母版页(MasterPage)了,现需要.aspx动态变更母版 ...
- 部分PC端安卓管理器使用强行断开重连的方法来连接手机,容易丢书数据,损坏数据
最近发现部分PC端的安卓管理器,貌似是百度影音以及PPTV的安卓客户端,使用强行断开手机连接,然后重新连接手机的方法,来实现客户端程序连接手机. 此时,如果刚好正在复制文件,则复制的文件会损坏,并且基 ...
- 页面中引入js的几种方法
通常大家最为熟悉的是一下两种方法: 在页面中直接写入<script type="text/javascript">js代码</script>. 在页面中引入 ...