我想将几个图像放在PDF文件中,带有ImageMagick
convert small.png big1.jpeg big2.jpeg -compress jpeg -quality 80 -resize '1240x1753>' -page A4 out.pdf
小图像不集中:它在页面的左下角,我的PDF阅读器上没有相同大小的页面(首页较小),
pdfinfo out.pdf | grep -a size
Page size: 112.441 x 159.118 pts
Page size: 595.304 x 841.89 pts (A4)
我尝试使用
-gravity
和
-density
,但是在我的测试中产生了奇怪的结果:它们似乎适用于整个PDF,并且使图像在页面外(带有
-gravity
-density
-extent
可能被排除在外,因为它在图像中添加了像素(周围)。 我的请求
我可以使用ImageMagick还是
convert
? (或可能与一个或其他一个或其他简单命令行工具一起)我不是在寻求建议。我有一个问题和一个复杂的工具(ImageMagick)。我很确定该工具可以解决问题,但我不知道该如何使用它。
我曾经使用称为Ghostscript.net
.
的库来进行UPWork作业。步骤One
从其官方
website中安装在Windows Machine中。 步出两
创建了一个新的Visual Studio项目,并安装
GhostScript.net,然后使用该库中内置的类,称为GhostScriptrasterizer将文档中的所有pdf页面转换为您的PDF页面,以您的首选形式将文档中的所有PDF页面转换为image Files。这是您可以用来实现这一目标的示例代码。
using System;
using System.Drawing;
using System.Imaging;
using System.IO;
//add a reference to the pdf rasterizer
using GhostScript.NET.Rasterizer;
class program{
//entry method for the program
static void Main(string args[]){
//declare a relative path to the location of PDF
var pdf = @"document.pdf";
//declare a folder to store the images
var imageFolder = @"images\\";
//check if the folder exists, if not create it
if (!Directory.Exists(imageFolder))
{
//create the folder if it does not exist
Directory.CreateDirectory();
}
//create a new instance of GhostScript Rasterizer
using(var rasterizer = new GhostScriptRasterizer()){
//open the pdf doucument using the rasterizer
rasterizer.Open(pdf);
//iterate through each page while generating
//a bitmap object from each
for(int i=0;i<rasterizer.PageCount;i++){
//create a new Bitmap from the current page
using(Bitmap bmp = rasterizer.GetPage(300,300, i){
//create a full path for the image
var outPath = Path.Combine(imageFolder $"Page-{i}.png");
//save the bitmap to the file
img.Save(outPath, ImageFormat.Png);
//write the console the process completed
Console.WriteLine($"Saved: {outPath}");
}
}
}
}
}