PS、EPS、XPSの変換
多才なAPIソリューションで、C++アプリケーションの可能性を最大限に引き出しましょう!C++向けの多才なAPIソリューションを使用して、PS、EPS、XPSファイルを高品質なPDFや美しい画像にシームレスに変換できます。
多才なネイティブAPIソリューションで、C++アプリケーションの可能性を最大限に引き出しましょう!PS、EPS、XPSファイルを高品質のPDFや美しい画像に素早く簡単に変換できます。正確なドキュメント変換が必要な場合でも、完璧なビジュアルコンテンツが必要な場合でも、当社のAPIはプロセスを簡素化し、プロジェクトを容易に強化するためのツールを提供します。ドキュメント管理を改善し、ビジュアルに新しい命を吹き込みましょう。C++ APIによるPostScript (PS)、Encapsulated PostScript (EPS)、およびXPSドキュメントからPDFおよび画像への変換の魔法を体験してください。ドキュメントを変換する準備はできましたか?無料トライアルを試すか、今すぐ購入して、コンテンツをアップグレードしましょう!
プログラマーは、PostScriptやXPSドキュメントのバッチ処理に簡単に使用できるだけでなく、キャンバス、パス、グリフ要素を操作したり、ベクターグラフィックスの形状やテキスト文字列を処理したりすることもできます。
ここでのC++用APIソリューションを使用すると、PS、EPS、XPSなどのPDL形式のファイルをプログラムで変換できますが、これらのネイティブAPI上で開発されたクロスプラットフォームのソリューションを確認して試してみるのも役立つでしょう。ここでは、EPSから画像、EPSからPDF、PostScriptからPDF、PostScriptから画像、XPSから画像、XPSからPDFなどの変換シナリオを紹介します。
C++経由でPostScript (PS, EPS) を画像に変換。
C++ライブラリを使用すると、Windows、Linux、およびmacOSプラットフォームでPostScript (PS) およびEncapsulated PostScript (EPS) ファイルを画像に変換できます。手順は以下の通りです。
- 入力ファイルストリームまたはファイル名をパラメータとして持つ PsDocument クラスの コンストラクタ を使用して、ドキュメントをロードします。
- ImageSaveOptions クラスのオブジェクトを作成し、必要な設定で初期化します。 set_ImageFormat を呼び出して、画像形式を ImageFormat の値として設定します。
- SaveAsImage を使用して、入力ファイルの各ページを画像のバイト配列に保存します。
EPSから画像への変換用C++コード
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir_WorkingWithDocumentConversion();
// Initialize PsDocument with the name of PostScript file.
System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(dataDir + u"inputForImage.ps");
// If you want to convert Postscript file despite of minor errors set this flag
bool suppressErrors = true;
//Initialize options object with necessary parameters.
System::SharedPtr<ImageSaveOptions> options = System::MakeObject<ImageSaveOptions>();
//Set output image format.
options->set_ImageFormat(Aspose::Page::Drawing::Imaging::ImageFormat::Png);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options->set_AdditionalFontsFolders(System::MakeArray<System::String>({u"{FONT_FOLDER}"}));
// Save PS document as array of image bytes, one bytes array for one page.
System::ArrayPtr<System::ArrayPtr<uint8_t>> imagesBytes = document->SaveAsImage(options);
//Save images bytes arrays as image files.
int32_t i = 0;
for (System::ArrayPtr<uint8_t> imageBytes : imagesBytes)
{
System::String imagePath = System::IO::Path::GetFullPath(dataDir + u"out_image" + System::Convert::ToString(i) + u"." + System::ObjectExt::ToString(options->get_ImageFormat()).ToLower());
{
System::SharedPtr<System::IO::FileStream> fs = System::MakeObject<System::IO::FileStream>(imagePath, System::IO::FileMode::Create, System::IO::FileAccess::Write);
// Clearing resources under 'using' statement
System::Details::DisposeGuard<1> __dispose_guard_0({ fs});
// ------------------------------------------
try
{
fs->Write(imageBytes, 0, imageBytes->get_Length());
}
catch(...)
{
__dispose_guard_0.SetCurrentException(std::current_exception());
}
}
i++;
}
//Review errors
if (suppressErrors)
{
for (auto&& ex : System::IterateOver(options->get_Exceptions()))
{
System::Console::WriteLine(ex->get_Message());
}
}
C++経由でのPostScriptからPDFへの変換。
PostScriptからPDFへの変換プロセスは、PostScriptから画像への変換と同じくらい簡単です。
- 入力ファイルストリームまたはファイル名をパラメータとして持つ PsDocument クラスの コンストラクタ を使用して、ドキュメントをロードします。
- PdfSaveOptions クラスのオブジェクトを作成し、AdditionalFontsFolderやSuppressErrorの値などの追加設定を定義します。
- SaveAsPdf メソッドを呼び出して、PDFファイルへの変換を実行します。
PostScriptからPDFへの変換用C++コード
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir_WorkingWithDocumentConversion();
// Initialize PsDocument with the name of PostScript file.
System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(dataDir + u"input.ps");
// If you want to convert Postscript file despite of minor errors set this flag
bool suppressErrors = true;
//Initialize options object with necessary parameters.
System::SharedPtr<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>(suppressErrors);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options->set_AdditionalFontsFolders(System::MakeArray<System::String>({u"{FONT_FOLDER}"}));
// Default page size is 595x842 and it is not mandatory to set it in PdfSaveOptions
// But if you need to specify sizeuse following line
//PdfSaveOptions options = new PdfSaveOptions(suppressErrorsnew, Aspose.Page.Drawing.Size(595x842));
// or
//saveOptions.Size = new Aspose.Page.Drawing.Size(595x842);
// Save document as PDF
document->SaveAsPdf(dataDir + u"outputPDF_out.pdf", options);
//Review errors
if (suppressErrors)
{
for (auto&& ex : System::IterateOver(options->get_Exceptions()))
{
System::Console::WriteLine(ex->get_Message());
}
}C++経由でXPSを画像に変換。
C++ XPS Processing APIは、WindowsおよびLinuxベースのシステムで、BMP、JPG、TIFF、PNGなどを含むXPSから画像への変換、およびXPSからPDFへの変換を処理します。XPSから画像への変換手順は以下の通りです。
- 入力ファイル名と XpsLoadOptions をコンストラクタパラメータとして、 XpsDocument クラスのインスタンスを作成します。
- Aspose::Page::XPS::Presentation::Image のいずれかのクラスのインスタンスとして保存オプションを作成します。
- XPSドキュメントの SaveAsImage メソッドを呼び出して、各ドキュメントページを画像のバイト配列に保存します。
XPSから画像への変換用C++コード
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir_WorkingWithDocumentConversion();
//Outut file
System::String outputFileName = dataDir + u"XPStoImage_out.bmp";
// Load XPS document form the XPS file
System::SharedPtr<XpsDocument> document = System::MakeObject<XpsDocument>(dataDir + u"input.xps", System::MakeObject<XpsLoadOptions>());
// Initialize options object with necessary parameters.
System::SharedPtr<BmpSaveOptions> options = System::MakeObject<BmpSaveOptions>();
options->set_SmoothingMode(System::Drawing::Drawing2D::SmoothingMode::HighQuality);
options->set_Resolution(300);
options->set_PageNumbers(System::MakeArray<int32_t>({1, 2, 6}));
// Save XPS document to the images byte arrays. The first dimension is for inner documents
// and the second one is for pages within inner documents.
System::ArrayPtr<System::ArrayPtr<System::ArrayPtr<uint8_t>>> imagesBytes = document->SaveAsImage(options);
// Iterate through document partitions (fixed documents, in XPS terms)
for (int32_t i = 0; i < imagesBytes->get_Length(); i++)
{
// Iterate through partition pages
for (int32_t j = 0; j < imagesBytes[i]->get_Length(); j++)
{
// Initialize image output stream
{
System::SharedPtr<System::IO::Stream> imageStream = System::IO::File::Open(System::IO::Path::GetDirectoryName(outputFileName) + System::IO::Path::DirectorySeparatorChar + System::IO::Path::GetFileNameWithoutExtension(outputFileName) + u"_" + (i + 1) + u"_" + (j + 1) + System::IO::Path::GetExtension(outputFileName), System::IO::FileMode::Create, System::IO::FileAccess::Write);
// Clearing resources under 'using' statement
System::Details::DisposeGuard<1> __dispose_guard_0({ imageStream});
// ------------------------------------------
try
{
imageStream->Write(imagesBytes[i][j], 0, imagesBytes[i][j]->get_Length());
}
catch(...)
{
__dispose_guard_0.SetCurrentException(std::current_exception());
}
}
}
}
C++経由でXPSをPDFに変換。
C++ XPS Processing APIは、WindowsおよびLinuxベースのシステムで、BMP、JPG、TIFF, PNGなどを含むXPSから画像への変換、およびXPSからPDFへの変換を処理します。XPSからPDFへの変換手順は以下の通りです。
- PDF出力用の出力ストリームを定義します。
- 入力ファイル名と XpsLoadOptions をコンストラクタパラメータとして、 XpsDocument クラスのインスタンスを作成します。
- PdfSaveOptions を使用して、TextCompression、ImageCompression、JpegQualityLevelなどのPDF固有の保存オプションを指定します。
- 最後に、いずれかの SaveAsPdf メソッドを使用して、XPSドキュメントをPDFに変換します。
XPSからPDFへの変換用C++コード
// The path to the documents directory.
System::String dataDir = RunExamples::GetDataDir_WorkingWithDocumentConversion();
// Initialize PDF output stream
{
System::SharedPtr<System::IO::Stream> pdfStream = System::IO::File::Open(dataDir + u"XPStoPDF_out.pdf", System::IO::FileMode::OpenOrCreate, System::IO::FileAccess::Write);
// Clearing resources under 'using' statement
System::Details::DisposeGuard<1> __dispose_guard_0({ pdfStream});
// ------------------------------------------
try
{
// Load XPS document form the XPS file
System::SharedPtr<XpsDocument> document = System::MakeObject<XpsDocument>(dataDir + u"input.xps", System::MakeObject<XpsLoadOptions>());
// Initialize options object with necessary parameters.
System::SharedPtr<Aspose::Page::XPS::Presentation::Pdf::PdfSaveOptions> options = System::MakeObject<Aspose::Page::XPS::Presentation::Pdf::PdfSaveOptions>();
options->set_JpegQualityLevel(100);
options->set_ImageCompression(Aspose::Page::XPS::Presentation::Pdf::PdfImageCompression::Jpeg);
options->set_TextCompression(Aspose::Page::XPS::Presentation::Pdf::PdfTextCompression::Flate);
options->set_PageNumbers(System::MakeArray<int32_t>({1, 2, 6}));
document->SaveAsPdf(pdfStream, options);
}
catch(...)
{
__dispose_guard_0.SetCurrentException(std::current_exception());
}
}FAQ
1. この API ソリューションで Postscript を変換できますか?
Aspose.Page には、PS、XPS、および EPS ファイルをオンラインまたはプログラムで他の形式に変換できる機能があります。ファイルをオンラインで即座に変換する必要がある場合は、 ページ記述言語形式のファイル コンバーター クロスプラットフォーム アプリケーションを使用できます。
2. コンバーターでサポートされているページ記述言語は何ですか?
この変換機能は、拡張子が .ps、.eps、および .xps のファイルをサポートします。 PDF や SVG などの有名な PDL は、Aspose.products では個別のソリューションとして表されます。
3. 機能は無料ですか?
クロスプラットフォーム コンバーター は無料です。API ソリューションの場合、無料の試用版を取得してから、必要に応じて製品を購入できます。