我正在尝试使用命令行程序转换将PDF转换为图像(JPEG或PNG)。这是我正在转换的pdf文件之一。

我想让程序去掉多余的空白,并返回足够高质量的图像,以便上标可以轻松读取。

这是我目前最好的尝试。正如你所看到的,修剪工作很好,我只是需要锐化的分辨率相当多。这是我正在使用的命令:

convert -trim 24.pdf -resize 500% -quality 100 -sharpen 0x1.0 24-11.jpg

我试着做了以下有意识的决定:

调整它的大小(对分辨率没有影响) 尽可能提高质量 使用-锐化(我已经尝试了一系列值)

任何建议,请在最终的PNG/JPEG图像的分辨率更高,将非常感谢!


当前回答

这里的Linux用户:我尝试了转换命令行实用程序(PDF到PNG),我对结果不满意。我发现这样做更简单,效果也更好:

使用PDFTK提取PDF页面 例如:PDFTK file.pdf cat 3输出page3.pdf 用GIMP打开(导入)该pdf 重要:改变导入分辨率从100到300或600像素/英寸 在GIMP导出为PNG(更改文件扩展名为。PNG)

编辑:

根据评论的要求,添加了图片。转换命令使用:

Convert -density 300 -trim struct2vec.pdf -quality 100 struct2vec.png

GIMP: 300dpi进口(px/in);导出为PNG压缩级别3。

我没有在命令行上使用GIMP(回复:我的评论,在下面)。

其他回答

你附上的PNG文件看起来真的很模糊。如果您需要对生成为PDF预览的每张图像使用额外的后处理,则会降低解决方案的性能。

2JPEG可以将PDF文件转换为一个漂亮的锐化JPG文件,并在一次调用中裁剪空边距:

2jpeg.exe -src "C:\In\*.*" -dst "C:\Out" -oper Crop method:autocrop

从Pdf中获取图像在iOS Swift最佳解决方案

func imageFromPdf(pdfUrl : URL,atIndex index : Int, closure:@escaping((UIImage)->Void)){
    
    autoreleasepool {
        
        // Instantiate a `CGPDFDocument` from the PDF file's URL.
        guard let document = PDFDocument(url: pdfUrl) else { return }
        
        // Get the first page of the PDF document.
        guard let page = document.page(at: index) else { return }
        
        // Fetch the page rect for the page we want to render.
        let pageRect = page.bounds(for: .mediaBox)
        
        let renderer = UIGraphicsImageRenderer(size: pageRect.size)
        let img = renderer.image { ctx in
            // Set and fill the background color.
            UIColor.white.set()
            ctx.fill(CGRect(x: 0, y: 0, width: pageRect.width, height: pageRect.height))
            
            // Translate the context so that we only draw the `cropRect`.
            ctx.cgContext.translateBy(x: -pageRect.origin.x, y: pageRect.size.height - pageRect.origin.y)
            
            // Flip the context vertically because the Core Graphics coordinate system starts from the bottom.
            ctx.cgContext.scaleBy(x: 1.0, y: -1.0)
            
            // Draw the PDF page.
            page.draw(with: .mediaBox, to: ctx.cgContext)
        }
        closure(img)

    }
    
    
}

/ /使用

    let pdfUrl = URL(fileURLWithPath: "PDF URL")
    self.imageFromPdf2(pdfUrl: pdfUrl, atIndex: 0) { imageIS in
        
    }

通常我在原生分辨率下用'pdfimages'提取嵌入图像,然后使用ImageMagick的转换为所需的格式:

$ pdfimages -list fileName.pdf
$ pdfimages fileName.pdf fileName   # save in .ppm format
$ convert fileName-000.ppm fileName-000.png

这将生成最佳和最小的结果文件。

注意:对于有损的JPG嵌入图像,你必须使用-j:

$ pdfimages -j fileName.pdf fileName   # save in .jpg format

最近的“poppler-util”(0.50+,2016),你可以使用-所有保存有损为jpg和无损为png,所以一个简单的:

$ pdfimages -all fileName.pdf fileName

从PDF中提取总是最好的质量内容。

在很少提供的Win平台上,您必须下载最近的(0.68,2018)' popler -util'二进制从: http://blog.alivate.com.au/poppler-windows/

你可以在LibreOffice Draw(这通常是预安装在Ubuntu中)中完成:

在LibreOffice Draw中打开PDF文件。 滚动到需要的页面。 确保文本/图像元素被正确放置。如果没有,可以在页面上进行调整/编辑。 顶部菜单:文件>导出… 在右下角菜单中选择所需的图像格式。我推荐PNG。 命名文件并单击Save。 选项窗口将出现,因此您可以调整分辨率和大小。 单击OK,就完成了。

使用这个命令行:

convert -geometry 3600x3600 -density 300x300 -quality 100 TEAM\ 4.pdf team4.png

这将正确地转换您所要求的文件。