日期:2014-05-20 浏览次数:21119 次
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Reflection;
using Aspose.Words;
using Aspose.Words.Drawing;
namespace ImageToPdf
{
class Program
{
public static void Main(string[] args)
{
// Sample infrastructure.
string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar;
string dataDir = new Uri(new Uri(exeDir), @"../../Data/").LocalPath;
ConvertImageToPdf(dataDir + "Test.jpg", dataDir + "TestJpg Out.pdf");
ConvertImageToPdf(dataDir + "Test.png", dataDir + "TestPng Out.pdf");
ConvertImageToPdf(dataDir + "Test.wmf", dataDir + "TestWmf Out.pdf");
ConvertImageToPdf(dataDir + "Test.tiff", dataDir + "TestTiff Out.pdf");
ConvertImageToPdf(dataDir + "Test.gif", dataDir + "TestGif Out.pdf");
}
/// <summary>
/// Converts an image to PDF using Aspose.Words for .NET.
/// </summary>
/// <param name="inputFileName">File name of input image file.</param>
/// <param name="outputFileName">Output PDF file name.</param>
public static void ConvertImageToPdf(string inputFileName, string outputFileName)
{
// Create Aspose.Words.Document and DocumentBuilder.
// The builder makes it simple to add content to the document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Read the image from file, ensure it is disposed.
using (Image image = Image.FromFile(inputFileName))
{