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

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

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

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

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

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

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


当前回答

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

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

其他回答

convert -density 300 * airbnb.pdf

在我看来很完美

这适用于从多个PDF和图像文件创建单个文件:

php exec('convert -density 300 -trim "/path/to/input_filename_1.png" "/path/to/input_filename_2.pdf" "/path/to/input_filename_3.png" -quality 100 "/path/to/output_filename_0.pdf"');

地点:

-density 300 = dpi

-trim =一些关于透明度的东西-使边缘看起来光滑

质量100 =质量vs压缩(100%质量)

平……对于多页,不要使用“压平”

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

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

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

另一个建议是您可以使用GIMP。

只需在GIMP->中加载PDF文件,另存为.xcf,然后你就可以对图像做任何你想做的事情了。

从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
        
    }