请教各位大侠,如何用代码将图片(各种格式,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的开发文档,不盛感激。

解决方案 »

  1.   


    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);
            }    }
    }
      

  2.   

    主要是引用第三方控件iTextSharp.dll
      

  3.   

    请问iTextSharp.dll是否可以把OFFIECE文档和XML文档转换成PDF文件吗?