需要以编程方式将 JPG 图像转换为 PDF 文件?借助Aspose.Words for Java,任何开发人员只需几行 Java 代码即可轻松将 JPG 转换为 PDF 格式。
现代图像处理 Java API 从 JPG 图像高速创建 PDF。直接在浏览器中测试 JPG 到 PDF 转换的质量。强大的 Java 库允许将 JPG 图片转换为许多流行的文档格式。
以下示例演示了如何在 Java 中将 JPG 转换为 PDF。
按照简单的步骤将 JPG 图像转换为 PDF 格式。从本地驱动器读取 JPG 图像,然后将其简单保存为 PDF,通过 PDF 扩展名指定所需的文档格式。对于 JPG 读取和 PDF 写入,您可以使用完全限定的文件名。输出的 PDF 内容将与原始 JPG 图像相同。
import com.aspose.words.*;
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertImage("Input.jpg");
doc.save("Output.pdf");
import com.aspose.words.*;
Document doc = new Document("Input.jpg");
doc.save("Output.pdf");
import com.aspose.words.*;
Document doc = new Document("Input.jpg");
for (int page = 0; page < doc.getPageCount(); page++)
{
Document extractedPage = doc.extractPages(page, 1);
extractedPage.save(String.format("Output_%d.pdf", page + 1));
}
import com.aspose.words.*;
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertImage("Input.jpg");
doc.save("Output.pdf");
import com.aspose.words.*;
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Shape shape = builder.insertImage("Input.jpg");
shape.getShapeRenderer().save("Output.pdf", new ImageSaveOptions(SaveFormat.pdf));
我们在Maven存储库中托管我们的 Java 'Aspose.Words for Java' 是一个常见的包含字节码的 JAR 请按照有关如何将其安装到 Java 开发人员环境的分步说明进行操作。
Java SE 7 和更新的 Java 版本。 Java SE 6 提供了一个单独的包,以防您不得不使用这个过时的 JRE 。
我们的 Java 包是跨平台的,可以在所有具有 JVM 实现的 Microsoft Windows 、Linux、macOS、Android 和 iOS。
有关可选包依赖项的信息,例如 JogAmp JOGL 、 Harfbuzz 字体引擎、 Java Advanced Imaging JAI ,请参阅产品文档。
您可以将JPG转换为许多其他文件格式: