作者:乔山办公网日期:
返回目录:word文档
对于文档处理控件Aspose.words,它的具有代表性的功能是在没有安装Microsoft Word的情况下,也能实现生成、打印、渲染、邮件合并,文档格式转换等功能。今天在使用Aspose.Words过程中,意外的发现这款文档处理软件的另外一个功能,它可以将图像转换为PDF文件,接下来就为大家分享一下实e69da5e887aae79fa5e98193339现这一功能的具体代码:
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))
{
// Find which dimension the frames in this image represent. For example
// the frames of a BMP or TIFF are "page dimension" whereas frames of a GIF image are "time dimension".
FrameDimension dimension = new FrameDimension(image.FrameDimensionsList[0]);
// Get the number of frames in the image.
int framesCount = image.GetFrameCount(dimension);
// Get the number of frames in the image.
int framesCount = image.GetFrameCount(FrameDimension.Page);
// Loop through all frames.
for (int frameIdx = 0; frameIdx < framesCount; frameIdx++)
{
// Insert a section break before each new page, in case of a multi-frame TIFF.
if (frameIdx != 0)
builder.InsertBreak(BreakType.SectionBreakNewPage);
// Select active frame.
image.SelectActiveFrame(dimension, frameIdx);
// We want the size of the page to be the same as the size of the image.
// Convert pixels to points to size the page to the actual image size.
PageSetup ps = builder.PageSetup;
ps.PageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);
ps.PageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);
// Insert the image into the document and position it at the top left corner of the page.
builder.InsertImage(
image,
RelativeHorizontalPosition.Page,
0,
RelativeVerticalPosition.Page,
0,
ps.PageWidth,
ps.PageHeight,
WrapType.None);
}
}
// Save the document to PDF.
doc.Save(outputFileName);
}
}
}
怎么把png格式转换为pdf格式
用虚拟打印机制作和转换PDF文件,软件有:
1.PDFFactory Pro虚拟打印机,安装后,在任何文档中,选择打印时,选择打印机为pdfFactoryPro,就能生成PDF文件,并可以进行安全设置。
2.InstallTinyPDF虚拟打印机.
3.tinypdf是免费的pdf虚拟打印机;
4.虚拟打印机(Virtual Printer);
5.SmartPrinter(Doc Pdf xls to pdf/tiff/bmp/jpg/png)一款大家非常熟悉的经典产品,专为转换文件
而研发的高品质打印驱动,以运行稳定、转换速度快和图像质量高而著称,通过虚拟打印技术可以完美的将任e79fa5e98193e59b9ee7ad94331意可打印文档转换成 PDF、TIFF、JPEG,BMP、PNG、EMF、GIF、TXT格式。
6.雪莹DocConvert虚拟打印转换。雪莹DocConvert是一款文档转化工具,它通过虚拟打印的技术将任何文档转化为PDF,JPG,BMP,TIFF,PCX,PNG等等文档格式。
当然还可以用:
1.用Solid Converter PDF Professional 可以在PDF与WORD互相转换,也就可以编辑了;
2.abobe acrobat Professional 也有部分编辑功能,网上有PJ的软件。
方法一:是先e69da5e887aae799bee5baa6e79fa5e98193333将JPG图片方到word或WPS中编辑好,然后再由word转换成成PDF。
具体方法:首先打开word或WPS并插入需要转换成PDF的图片,编辑排版好。然后选择文件—另存为—输出为PDF格式。
这种方法在需要编辑多张图片是比较麻烦,需要排版编辑好,对于文字形式的图片也只能以图片的形式放入到word中进行编辑,不能对途中的文字进行编辑,对于想编辑图片中文字的来说只能在word中打字加上截图。
方法二:直接使用JPG转换成PDF转换器进行转换,jpg转换成PDF转换器 。
具体方法:首先选择您需要使用的模式,如果需要将文件转化为PDF,点击左上角的"图片转PDF"模式。
然后点击左下角的的"添加文件",把需要转换的文件添加进来,一次可添加多个文件。同时选择转换后文件需要保存的位置。
最好点击右边"开始转换"按钮,等待片刻即可。
这种方法方便快捷,可以一次批量转换多种图片,可以将图片分别转换PDF文档或是将所有图片合并成一个PDF文档,在转换时选择对应的选项即可。
方法三:使用FreePic2Pdf软件,进行批量转换;
方法四:使用虚拟打印机pdf factory即可,而且其他格式文件只要是能够打印,选择这个虚拟打印机,都可以做成PDF文件,很简单实用;用其他虚拟打印机转成PDF文件。