请教各位大侠,如何用代码将图片(各种格式,bmp,jpg,等等)转化成PDF格式?
本人已安装了Acrobat_8_Pro_SC,在VS.NET中组件Acrobat Distiller的File2PDF函数时,入口文件必须是PS(PostScript)格式。请问如何把图片转成PS格式,是不是要安装PS打印驱动,如果安装了驱动如何在程序中调用该驱动生成PS文件?
Acrobat_8_Pro_SC还包含了另一个组件PDFMAKER,该组件可以将MS OFFICE生成的格式文档直接转换成PDF,可是没有找到把图片转化成PDF的方法,但我觉得这组件应该可以转图片成PDF的。
这个问题已经困惑我1整天了,在此请各位大侠指点迷津,谢谢了。
如果哪位能提供下Acrobat的开发文档,不盛感激。
本人已安装了Acrobat_8_Pro_SC,在VS.NET中组件Acrobat Distiller的File2PDF函数时,入口文件必须是PS(PostScript)格式。请问如何把图片转成PS格式,是不是要安装PS打印驱动,如果安装了驱动如何在程序中调用该驱动生成PS文件?
Acrobat_8_Pro_SC还包含了另一个组件PDFMAKER,该组件可以将MS OFFICE生成的格式文档直接转换成PDF,可是没有找到把图片转化成PDF的方法,但我觉得这组件应该可以转图片成PDF的。
这个问题已经困惑我1整天了,在此请各位大侠指点迷津,谢谢了。
如果哪位能提供下Acrobat的开发文档,不盛感激。
解决方案 »
- 高手帮我看看这是怎么回事?
- 新闻正文关键词链接问题
- 电子商务网站的两个基本问题
- 关于DataGrid导出Excel表的问题。
- 江湖救急
- TREEVIEW 如何击节点时展开(当时是闭合的),其它一个节点就闭合(当时是展开的)
- 问个简单问题。你门一定要回答啊。
- ?????????????gridview的复选框如何让其在选定后,当翻页或者刷新后仍然保持选中的状态,请给位大侠指点迷精?
- 求一将<img src="imges/01.jpg">替换成<img src="http://www.cncyw.net/imges/01.jpg">的正则表达式
- 发布的网站数据库连接问题
- IP数据库怎么使啊??
- [高分求解]自定义错误处理不了401.2吗?
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using Microsoft.Office.Interop.Word;public partial class _Default : System.Web.UI.Page
{ protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ }
}
protected void Button1_Click(object sender, EventArgs e)
{
string filepath = Server.MapPath("images");
string[] strFiles = Directory.GetFiles(filepath, "*.tif");
string newpath = filepath + "\\temp.pdf";
process(strFiles, newpath);
} private void process(string[] files, string newpdf)
{
iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25); try
{
iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(newpdf, FileMode.Create, FileAccess.ReadWrite)); document.Open();
iTextSharp.text.Image image;
for (int i = 0; i < files.Length; i++)
{
image = iTextSharp.text.Image.GetInstance(files[i]); if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
{
image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
}
else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
{
image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
}
image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE; document.NewPage();
document.Add(image);
}
}
catch (Exception ioe)
{
throw ioe;
}
document.Close();
Page.ClientScript.RegisterStartupScript(this.GetType(), "js", "<script type='text/javascript'>alert('转换成功!');</script>");
} protected void Button2_Click(object sender, System.EventArgs e)
{
string filepath = Server.MapPath("images");
string[] strFiles = Directory.GetFiles(filepath, "*.pdf");
string newpath = filepath+"\\hebing1.pdf";
mergePDFFiles(strFiles, newpath);
} /// <summary>
/// 合并pdf文档
/// </summary>
/// <param name="fileList"></param>
/// <param name="outMergeFile"></param> private void mergePDFFiles(string[] fileList, string outMergeFile)
{
try
{
//outMergeFile = Server.MapPath(outMergeFile);
PdfReader reader;
iTextSharp.text.Document document = new iTextSharp.text.Document();
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(outMergeFile, FileMode.Create));
document.Open();
PdfContentByte cb = writer.DirectContent;
PdfImportedPage newPage;
for (int i = 0; i < fileList.Length; i++)
{ //reader = new PdfReader(Server.MapPath(fileList[i]));
reader = new PdfReader(fileList[i]);
int iPageNum = reader.NumberOfPages;
for (int j = 1; j <= iPageNum; j++)
{
document.NewPage();
newPage = writer.GetImportedPage(reader, j);
cb.AddTemplate(newPage, 0, 0);
}
}
document.Close();
Page.ClientScript.RegisterStartupScript(this.GetType(), "js", "<script type='text/javascript'>alert('合并成功!');</script>"); }
catch (Exception de)
{
Response.Write(de.Message);
} }
}