この短いチュートリアルでは、C++を使用してPDFを作成する方法を学習します。 ** C ++ create PDF file **の例を使用すると、いくつかのAPI呼び出しでPDFを簡単に生成できます。この例は、C++をサポートする任意のMSWindows開発環境で使用できます。
C++を使用してPDFを作成する手順
- NuGetパッケージマネージャーを使用してAspose.Pdf for C++ライブラリを含める
- Aspose::Pdf名前空間への参照を含める
- ドキュメントオブジェクトを初期化して、C++からPDFを作成します
- TextFragmentインスタンスを初期化して、テキストとそのプロパティを設定します
- C++でSaveメソッドを使用してディスク上にPDFを作成する
- C ++では、いくつかの簡単な手順を使用してPDFドキュメントを生成します。これを実現するには、 Document Class を使用して空白のPDFを作成し、その中にページを追加します。次に、 TextBuilderクラス*インスタンスを初期化することにより、PDFテキストとそのプロパティを設定します。生成されたPDFファイルはSaveメソッドを使用してディスクに保存されます。
C++を使用してPDFを生成するコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <system/string.h> | |
#include <system/shared_ptr.h> | |
#include <stdio.h> | |
#include <system/console.h> | |
#include <system/environment.h> | |
#include <system/object_ext.h> | |
#include <Aspose.PDF.Cpp/License.h> | |
#include <Aspose.PDF.Cpp/Document.h> | |
#include <Aspose.PDF.Cpp/Page.h> | |
#include <Aspose.PDF.Cpp/PageCollection.h> | |
#include <Aspose.PDF.Cpp/Color.h> | |
#include <Aspose.PDF.Cpp/Text/TextFragment.h> | |
#include <Aspose.PDF.Cpp/Text/Position.h> | |
#include <Aspose.PDF.Cpp/Text/TextBuilder.h> | |
#include <Aspose.PDF.Cpp/Text/TextFragmentCollection.h> | |
#include <Aspose.PDF.Cpp/Text/TextFragmentState.h> | |
#include <Aspose.PDF.Cpp/Text/FontRepository.h> | |
using namespace System; | |
using namespace Aspose::Pdf; | |
using namespace Aspose::Pdf::Text; | |
void CreatePdfInCpp() | |
{ | |
// Set the license for Aspose.PDF for C++ to create PDF | |
SharedPtr<License> CreatePDFLicense = System::MakeObject<License>(); | |
CreatePDFLicense->SetLicense(u"Aspose.PdfCPP.lic"); | |
// Initialize document object create PDF from C++ | |
SharedPtr<Document> PdfDocument = MakeObject<Document>(); | |
// Add empty page in PDF | |
SharedPtr<Page> pdfPage = PdfDocument->get_Pages()->Add(); | |
// Initialize Text fragment and set text | |
SharedPtr <TextFragment> textFragments = MakeObject<TextFragment>(u"Knowledgebase Text"); | |
// Apply text related properties | |
textFragments->set_Position(MakeObject < Position>(100, 600)); | |
textFragments->get_TextState()->set_FontSize(12); | |
textFragments->get_TextState()->set_Font(FontRepository::FindFont(u"TimesNewRoman")); | |
textFragments->get_TextState()-> | |
set_BackgroundColor((MakeObject<Aspose::Pdf::Color>())->FromRgb(System::Drawing::Color::get_Wheat())); | |
textFragments->get_TextState()-> | |
set_ForegroundColor((MakeObject<Aspose::Pdf::Color>())->FromRgb(System::Drawing::Color::get_Red())); | |
// Instantiate TextBuilder object | |
SharedPtr < TextBuilder> textBuilders = MakeObject< TextBuilder>(pdfPage); | |
// Append added fragment to the PDF page | |
textBuilders->AppendText(textFragments); | |
// Create PDF using C++ | |
PdfDocument->Save(u"Generated_out.pdf"); | |
} |
- C ++では、PDFジェネレーターは単純なAPI呼び出しを使用して開発できます。他のAPIやAdobePDFに依存せずにC++を使用してPDFを生成する方法*を目撃しました。いくつかの手順で、テキストを挿入し、それぞれのテキストプロパティを設定することで、PDFを最初から作成することができました。
最後のトピックでは、C++を使用してPDFフォームをフラット化する方法に焦点を当てました。このトピックでは、いくつかの簡単な手順を使用してC++でPDFを作成する方法について説明します。