2つの簡単なステップでpdfファイルをJavaでWMZ画像に変換できます。まず、 Aspose.PDF for Java を使用すると、PDFをJPEGにエクスポートできます。その後、 Aspose.Imaging for Java Image Processing APIを使用して、JPEGをWMZにレンダリングできます。どちらのAPIも、 Aspose.Total for Java パッケージに含まれています。
Java経由でPDFをWMZにエクスポート
変換要件
Maven ベースのプロジェクトから直接Aspose.Total for Javaを簡単に使用できますそして、pom.xmlにライブラリを含めます。
または、 ダウンロード からZIPファイルを取得することもできます。
// supports PDF, CGM, EPUB, TeX, PCL, PS, XPS, MD, MHTML, XSLFO, HTML file formats | |
// load PDF with an instance of Document | |
Document document = new Document("input.pdf"); | |
// create an object of JpegDevice | |
JpegDevice renderer = new JpegDevice(); | |
// convert first of a particular PDF page to JPEG format | |
renderer.process(document.getPages().get_Item(1), "output.jpeg"); | |
// load JPEG file | |
Image image = Image.Load("output.jpeg"); | |
// supports Dicom, Jpeg2000, Apng, Psd, Dxf, Wmf, Emz, Wmz, Tga, Svgz file formats | |
// save JPEG to PSD file format | |
image.save("output.psd", new PsdOptions()); |
Javaを介して単一ファイルでPDFをWMZに変換する
APIを使用すると、PDFファイルをWMZの単一ファイルにエクスポートすることもできます。すべてのページを変換するには、最初にPDFドキュメントを1つのTIFFファイルにレンダリングし、その後、TIFFファイルをWMZにエクスポートできます。 Document クラスを使用して入力ファイルを開き、Resolution、TiffSettings、およびTIFFデバイスオブジェクトを作成できます。 process を使用して単一のTIFF画像を取得できますjava.io.OutputStream TiffDevice クラスのメソッド。最後に、 Image クラスを使用してTIFFファイルをロードし、 save メソッド。
// supports PDF, CGM, EPUB, TeX, PCL, PS, XPS, MD, MHTML, XSLFO, HTML file formats | |
// load PDF with an instance of Document | |
Document pdfDocument = new Document("input.pdf"); | |
// Create Resolution object | |
Resolution resolution = new Resolution(300); | |
// Create TiffSettings object | |
TiffSettings tiffSettings = new TiffSettings(); | |
tiffSettings.setCompression(CompressionType.None); | |
tiffSettings.setDepth(ColorDepth.Default); | |
tiffSettings.setShape(ShapeType.Landscape); | |
// Create TIFF device | |
TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings); | |
// Convert a particular page and save the image to stream | |
tiffDevice.process(pdfDocument, 1, 1, "output.tif"); | |
// load TIFF file | |
Image image = Image.Load("output.tif"); | |
// supports Dicom, Jpeg2000, Apng, Psd, Dxf, Wmf, Emz, Wmz, Tga, Svgz file formats | |
// save TIFF to PSD file format | |
image.save("output.psd", new PsdOptions()); |
Javaを介して透かし付きのPDFをWMZに変換する
APIを使用して、WMZドキュメントに透かしを入れたPDFファイルをWMZにエクスポートすることもできます。透かしを追加するには、最初にPDFをJPEGに変換し、透かしを追加します。透かしを追加するには、 Image クラスを使用して画像ファイルを読み込み、 Graphics クラスをImageオブジェクトで初期化し、新しい[Matrix]( https://reference.aspose.com/imaging/java/ com.aspose.imaging/Matrix)オブジェクトを作成し、変換と変換を目的の角度に設定し、 Graphics.drawString メソッド。画像に透かしを追加した後、JPEGをWMZ形式で保存できます。
// supports PDF, CGM, EPUB, TeX, PCL, PS, XPS, MD, MHTML, XSLFO, HTML file formats | |
// load PDF with an instance of Document | |
Document document = new Document("input.pdf"); | |
// create an object of JpegDevice | |
JpegDevice renderer = new JpegDevice(); | |
// convert first of a particular PDF page to JPEG format | |
renderer.process(document.getPages().get_Item(1), "output.jpeg"); | |
// load JPEG | |
Image image = Image.load("output.jpeg"); | |
// create and initialize an instance of Graphics class | |
Graphics graphics= new Graphics(image); | |
// create an instance of Font | |
Font font = new Font("Times New Roman", 16, FontStyle.Bold); | |
// create an instance of SolidBrush and set its properties | |
SolidBrush brush = new SolidBrush(); | |
brush.setColor(Color.getBlack()); | |
brush.setOpacity(100); | |
Size sz = graphics.getImage().getSize(); | |
// create an object of Matrix class for transformation | |
Matrix matrix = new Matrix(); | |
// first a translation then a rotation | |
matrix.translate(sz.getWidth() / 2, sz.getHeight() / 2); | |
matrix.rotate(-45.0f); | |
// set the Transformation through Matrix | |
graphics.setTransform(matrix); | |
// draw a string using the SolidBrush and Font objects at specific point | |
graphics.drawString("Watermark by Aspose.Imaging for Java", font, brush, 0, 0); | |
// supports Dicom, Jpeg2000, Apng, Psd, Dxf, Wmf, Emz, Wmz, Tga, Svgz file formats | |
// save JPEG to PSD file format | |
image.save("output.psd", new PsdOptions()); |
Javaを介してPDFをWMZファイルに変換および回転
APIを使用すると、必要に応じて出力WMZ画像を回転させることもできます。 Image.rotateFlipメソッドを使用すると、画像を90/180/270度回転し、画像を水平または垂直に反転できます。ライブラリは、すべての醜い詳細をカプセル化しながら、複雑な操作を実行するための簡単なメソッドを提供します。画像に適用する回転と反転のタイプを指定できます。画像を回転および反転するには、 Image クラスを使用して変換されたJPEG画像をロードし、Imageを呼び出すことができます。適切な RotateFlipType を指定しながらrotateFlipメソッド。
// supports PDF, CGM, EPUB, TeX, PCL, PS, XPS, MD, MHTML, XSLFO, HTML file formats | |
// load PDF with an instance of Document | |
Document document = new Document("input.pdf"); | |
// create an object of JpegDevice | |
JpegDevice renderer = new JpegDevice(); | |
// convert first of a particular PDF page to JPEG format | |
renderer.process(document.getPages().get_Item(1), "output.jpeg"); | |
// load JPEG file | |
Image image = Image.Load("output.jpeg"); | |
// roate image | |
image.RotateFlip(RotateFlipType.Rotate270FlipNone); | |
// supports Dicom, Jpeg2000, Apng, Psd, Dxf, Wmf, Emz, Wmz, Tga, Svgz file formats | |
// save JPEG to PSD file format | |
image.save("output.psd", new PsdOptions()); |