Koristeći naš API za programiranje, C++ programeri mogu jednostavno napraviti dokument u PDF, DOC, DOCX, HTML, EPUB i mnogim drugim formatima sa samo nekoliko redaka koda.
Uz dani moćni API, C++ programeri mogu stvarati dokumente u gotovo svim formatima. Da biste to učinili, trebate slijediti nekoliko koraka koristeći našu C++ biblioteku:
Vrijedno je napomenuti da bi prazan dokument tehnički trebao sadržavati jedan paragraf, tako da kada programski kreirate dokument, dobit ćete upravo tu osnovnu strukturu dokumenta.
Imajte na umu da možete odmah dodati sadržaj u novostvoreni dokument. Tako ćete dobiti ne samo prazan dokument, već dokument koji sadrži potreban sadržaj. Za više informacija o tome kako urediti dokument, pogledajte stranicu Uređivanje.
Navedena C++ biblioteka omogućuje programsku izradu dokumenta u bilo kojem podržanom formatu – PDF, DOCX, DOC, RTF, ODT, EPUB, HTML i drugi.
Isprobajte našu moćnu funkcionalnost i pogledajte kako izraditi dokument u nekim formatima koristeći sljedeći primjer:
dotnet add package Aspose.Words.Cpp
Kopirati
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto font = builder->get_Font();
font->set_Name(u"Courier New");
font->set_Color(System::Drawing::Color::get_Blue());
font->set_Size(36);
font->set_HighlightColor(System::Drawing::Color::get_Yellow());
builder->Write(u"Morbi enim nunc faucibus a.");
doc->Save(u"Output.docx");
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto firstRun = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed. ");
auto secondRun = MakeObject<Run>(doc, u"Morbi enim nunc faucibus a.");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(firstRun);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(secondRun);
builder->MoveTo(secondRun);
builder->StartBookmark(u"Aspose bookmark");
// Ako je NextSibling null, tada je najvjerojatnije ovo zadnje Run u paragrafu.
if (secondRun->get_NextSibling() != NULL)
builder->MoveTo(secondRun->get_NextSibling());
else
builder->MoveTo(secondRun->get_ParentParagraph());
builder->EndBookmark(u"Aspose bookmark");
doc->Save(u"Output.docx");
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto firstRun = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed. ");
auto secondRun = MakeObject<Run>(doc, u"Morbi enim nunc faucibus a.");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(firstRun);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(secondRun);
builder->MoveTo(secondRun);
builder->StartBookmark(u"Aspose bookmark");
// Ako je NextSibling null, tada je najvjerojatnije ovo zadnje Run u paragrafu.
if (secondRun->get_NextSibling() != NULL)
builder->MoveTo(secondRun->get_NextSibling());
else
builder->MoveTo(secondRun->get_ParentParagraph());
builder->EndBookmark(u"Aspose bookmark");
auto saveOptions = MakeObject<PdfSaveOptions>();
saveOptions->get_OutlineOptions()->get_BookmarksOutlineLevels()->Add(u"Aspose bookmark", 1);
doc->Save(u"Output.docx", saveOptions);
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto run = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed.");
auto para = doc->get_FirstSection()->get_Body()->get_FirstParagraph();
para->AppendChild(run);
auto comment = MakeObject<Comment>(doc, u"John Doe", u"JD", System::DateTime::get_Today());
comment->SetText(u"Quisque fringilla leo.");
auto commentRangeStart = MakeObject<CommentRangeStart>(doc, comment->get_Id());
auto commentRangeEnd = MakeObject<CommentRangeEnd>(doc, comment->get_Id());
run->get_ParentNode()->InsertBefore(commentRangeStart, run);
run->get_ParentNode()->InsertAfter(commentRangeEnd, run);
commentRangeEnd->get_ParentNode()->InsertAfter(comment, commentRangeEnd);
comment->AddReply(u"Jane Doe", u"JD", System::DateTime::get_Now(),
u"Pellentesque vel sapien justo.");
doc->Save(u"Output.docx");
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto firstRun = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed. ");
auto secondRun = MakeObject<Run>(doc, u"Morbi enim nunc faucibus a.");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(firstRun);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(secondRun);
builder->MoveTo(secondRun);
builder->StartBookmark(u"Aspose bookmark");
// Ako je NextSibling null, tada je najvjerojatnije ovo zadnje Run u paragrafu.
if (secondRun->get_NextSibling() != NULL)
builder->MoveTo(secondRun->get_NextSibling());
else
builder->MoveTo(secondRun->get_ParentParagraph());
builder->EndBookmark(u"Aspose bookmark");
doc->Save(u"Output.docx");
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto firstRun = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed. ");
auto secondRun = MakeObject<Run>(doc, u"Morbi enim nunc faucibus a.");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(firstRun);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(secondRun);
builder->MoveTo(secondRun);
builder->StartBookmark(u"Aspose bookmark");
// Ako je NextSibling null, tada je najvjerojatnije ovo zadnje Run u paragrafu.
if (secondRun->get_NextSibling() != NULL)
builder->MoveTo(secondRun->get_NextSibling());
else
builder->MoveTo(secondRun->get_ParentParagraph());
builder->EndBookmark(u"Aspose bookmark");
auto saveOptions = MakeObject<PdfSaveOptions>();
saveOptions->get_OutlineOptions()->get_BookmarksOutlineLevels()->Add(u"Aspose bookmark", 1);
doc->Save(u"Output.docx", saveOptions);
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto firstRun = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed. ");
auto secondRun = MakeObject<Run>(doc, u"Morbi enim nunc faucibus a.");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(firstRun);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(secondRun);
builder->MoveTo(secondRun);
builder->StartBookmark(u"Aspose bookmark");
// Ako je NextSibling null, tada je najvjerojatnije ovo zadnje Run u paragrafu.
if (secondRun->get_NextSibling() != NULL)
builder->MoveTo(secondRun->get_NextSibling());
else
builder->MoveTo(secondRun->get_ParentParagraph());
builder->EndBookmark(u"Aspose bookmark");
doc->Save(u"Output.docx");
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto firstRun = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed. ");
auto secondRun = MakeObject<Run>(doc, u"Morbi enim nunc faucibus a.");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(firstRun);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(secondRun);
builder->MoveTo(secondRun);
builder->StartBookmark(u"Aspose bookmark");
// Ako je NextSibling null, tada je najvjerojatnije ovo zadnje Run u paragrafu.
if (secondRun->get_NextSibling() != NULL)
builder->MoveTo(secondRun->get_NextSibling());
else
builder->MoveTo(secondRun->get_ParentParagraph());
builder->EndBookmark(u"Aspose bookmark");
doc->Save(u"Output.docx");
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto firstRun = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed. ");
auto secondRun = MakeObject<Run>(doc, u"Morbi enim nunc faucibus a.");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(firstRun);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(secondRun);
builder->MoveTo(secondRun);
builder->StartBookmark(u"Aspose bookmark");
// Ako je NextSibling null, tada je najvjerojatnije ovo zadnje Run u paragrafu.
if (secondRun->get_NextSibling() != NULL)
builder->MoveTo(secondRun->get_NextSibling());
else
builder->MoveTo(secondRun->get_ParentParagraph());
builder->EndBookmark(u"Aspose bookmark");
auto saveOptions = MakeObject<PdfSaveOptions>();
saveOptions->get_OutlineOptions()->get_BookmarksOutlineLevels()->Add(u"Aspose bookmark", 1);
doc->Save(u"Output.docx", saveOptions);
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto shape = builder->InsertChart(ChartType::Pie, 432, 252);
auto chart = shape->get_Chart();
chart->get_Title()->set_Text(u"Demo Chart");
chart->get_Series()->Clear();
chart->get_Series()->Add(u"Series 1",
MakeArray<String>({ u"Category1", u"Category2", u"Category3" }),
MakeArray<double>({ 2.7, 3.2, 0.8 }));
doc->Save(u"Output.docx");
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto firstRun = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed. ");
auto secondRun = MakeObject<Run>(doc, u"Morbi enim nunc faucibus a.");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(firstRun);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(secondRun);
builder->MoveTo(secondRun);
builder->StartBookmark(u"Aspose bookmark");
// Ako je NextSibling null, tada je najvjerojatnije ovo zadnje Run u paragrafu.
if (secondRun->get_NextSibling() != NULL)
builder->MoveTo(secondRun->get_NextSibling());
else
builder->MoveTo(secondRun->get_ParentParagraph());
builder->EndBookmark(u"Aspose bookmark");
doc->Save(u"Output.docx");
using namespace Aspose::Words;
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
auto firstRun = MakeObject<Run>(doc, u"Proin eros metus, sagittis sed. ");
auto secondRun = MakeObject<Run>(doc, u"Morbi enim nunc faucibus a.");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(firstRun);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(secondRun);
builder->MoveTo(secondRun);
builder->StartBookmark(u"Aspose bookmark");
// Ako je NextSibling null, tada je najvjerojatnije ovo zadnje Run u paragrafu.
if (secondRun->get_NextSibling() != NULL)
builder->MoveTo(secondRun->get_NextSibling());
else
builder->MoveTo(secondRun->get_ParentParagraph());
builder->EndBookmark(u"Aspose bookmark");
auto saveOptions = MakeObject<PdfSaveOptions>();
saveOptions->get_OutlineOptions()->get_BookmarksOutlineLevels()->Add(u"Aspose bookmark", 1);
doc->Save(u"Output.docx", saveOptions);
Postoje tri opcije za instalaciju Aspose.Words for C++ u okruženje razvojnog programera. Odaberite onaj koji odgovara vašim potrebama i slijedite upute korak po korak:
Ovu biblioteku C++ možete koristiti za razvoj softvera na Microsoft Windows, Linux i macOS:
Ako razvijate softver za Linux ili macOS, provjerite informacije o dodatnim ovisnostima o knjižnici (fontconfig i mesa-glu paketi otvorenog koda) u dokumentaciji proizvoda.