![Convert Publisher to PNG in Java | PUB to PNG Converter](images/convert-publisher-to-png-in-java.jpg#center)
Microsoft Publisherを使用せずにPUBファイルをPNG画像にエクスポートする方法を探していますか?こちらの記事がぴったりです!このブログ記事では、Javaを使用してPUBをPNGに変換する方法を説明します。Microsoft Publisherは、PUBファイルを作成するデスクトップ出版アプリケーションです。PUBファイルには、ドキュメントのレイアウト、テキスト、画像、フォーマット要素が含まれています。Microsoft PublisherファイルをPNG画像に変換すると、広くサポートされている画像形式でコンテンツを共有できます。それでは、JavaでPublisherをPNGに変換する方法を学びましょう。
この記事では、以下のトピックをカバーします:
Java APIでPublisherをPNGに変換
PUBからPNGへの変換は、2段階のプロセスです。まず、Aspose.PUB for Javaライブラリを使用してPUBファイルを読み込み、PDFとしてレンダリングします。次に、Aspose.PDF for Javaを使用して、そのPDFをクリーンなPNG画像に変換します。
Aspose.PUB for JavaおよびAspose.PDF for Java APIのJARファイルをダウンロードするか、次の設定を使用してMavenリポジトリからAPIをダウンロードしてください:
<repositories>
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>http://repository.aspose.com/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pub</artifactId>
<version>22.8</version>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>24.5</version>
</dependency>
</dependencies>
JavaでPUBをPNGに変換
JavaでPublisher PUBファイルをPNG画像にプログラムで変換するには、次の手順に従ってください:
- PubFactory.createParser() メソッドを使用してパーサーを作成します。
- parse() メソッドを呼び出してPUBファイルを処理します。
- PDFファイルを保存するためにメモリストリームを作成します。
- convertToPdf() メソッドを使用してPUBファイルをPDFに変換し、MemoryStreamに保存します。
- PDFストリームを使用してDocumentクラスオブジェクトを作成します。
- PdfFileInfoを使用してPDFファイル情報を取得します。
- PDFページをループし、その高さと幅を取得し、解像度を設定します。
- ページの高さ、幅、解像度を使用してJpegDeviceを作成します。
- 最後にprocess() メソッドを呼び出して、ページをPNG画像として保存します。
次のコードサンプルは、JavaでPublisher PUBファイルをPNGに変換する方法を示しています。
// This code example demonstrates how to convert PUB to PNG in Java. | |
// File name | |
String fileName = "florist-flyerr.pub"; | |
// Initialize ByteArrayOutputStream to hold intermediary PDF file. | |
final ByteArrayOutputStream os = new ByteArrayOutputStream(); | |
// Initialize Pub Parser for the PUB file | |
IPubParser parser = PubFactory.createParser(fileName); | |
// Parse the Publisher file | |
Document doc = parser.parse(); | |
// Convert PUB to PDF file and save output into the stream | |
PubFactory.createPdfConverter().convertToPdf(doc, os); | |
// Load the intermediary PDF document | |
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(os.toByteArray()); | |
// Get PDF file info | |
PdfFileInfo info = new PdfFileInfo(pdfDocument); | |
// Loop through all the pages | |
for (Page page : pdfDocument.getPages()) | |
{ | |
// Get page dimensions from the PDF document | |
int width = (int) info.getPageWidth(page.getNumber()); | |
int height = (int) (info.getPageHeight(page.getNumber())); | |
// Set resolution for the output image | |
Resolution resolution = new Resolution(300); | |
// Create PNG device with specified Width and Height | |
PngDevice pngDevice = new PngDevice(width, height , resolution); | |
// Convert PUB to PNG image | |
pngDevice.process(page, "Page" + page.getNumber() + ".png"); | |
} |
![Convert PUB to PNG in Java](images/pub-to-png-using-java.jpg#center)
JavaでPUBをPNGに変換します。
ライブラリを無制限に試すには、無料の一時ライセンスを取得してください。
PUBからPNGコンバーター - 無料オンライン
代わりに、この無料オンラインPUBからPNGコンバーターを使用して、ソフトウェアをインストールせずにPublisherファイルをPNG画像に変換できます。
![](images/pub-to-png-converter-free-online.jpg)
PublisherからPNGへの変換 – 無料リソース
PublisherファイルをPNG形式に変換するだけでなく、これらのAPIの他の機能もこれらのリソースを使用して探ってください:
結論
この記事では、Javaを使用してPublisher PUBファイルをPNG形式に変換する方法を体験しました。Aspose.PUBおよびAspose.PDF for Javaライブラリを使用することで、そのプロセスを簡素化できます。ここで説明した手順に従えば、Publisherデザインを高品質なPNG画像に簡単に変換できます。
試してみる準備はできましたか?Aspose.PUB for Javaをダウンロードして、今すぐPUBファイルの変換を始めましょう!オンラインソリューションをお探しの場合は、無料のPUBからPNGコンバーターもご利用いただけます。ご不明な点があれば、無料サポートフォーラムでお気軽にお問い合わせください。