点击下载最新版Aspose.PDF for C++
// Numeration of Pages starts from 1
auto page = pages->idx_get(1);
auto paragraps = page->get_Paragraphs();
// Create text fragment
auto text = MakeObject(u"PDF API for C++");
auto ts = text->get_TextState();
// Set text state
ts->set_FontSize(16);
ts->set_FontStyle(FontStyles::Italic);
// Add to paragraph
paragraps->Add(text);
// Add text to paragraph
paragraps->Add(MakeObject(u"This example shows how to create a PDF with text using Aspose.PDF for C++."));
// Save PDF file
doc->Save(u"Example1.pdf");
输入HTML文件
auto tb = MakeObject(pages->idx_get(1));
// Create TextFragment
auto text = MakeObject(u"Hello world!");
text->set_Position(MakeObject(100, 800));
// Append TextFragment
tb->AppendText(text);
// Create another TextFragment
text = MakeObject(u"This example is created by Aspose.Pdf for C++.");
text->set_Position(MakeObject(150, 750));
tb->AppendText(text);
// Create another TextFragment
text = MakeObject(u"It demonstrates how to use TextBuilder to append text into PDF file.");
text->set_Position(MakeObject(200, 700));
tb->AppendText(text);
// Create TextParagraph
auto par = MakeObject();
par->set_Position(MakeObject(250,650));
par->AppendLine(u"New paragraph");
par->AppendLine(u"Line 2");
par->AppendLine(u"Line 3");
tb->AppendParagraph(par);
// Save PDF document
doc->Save(u"Created PDF.pdf");
输入HTML文件
auto stream = MakeObject();
SharedPtrbitmap = MakeObject(200, 200);
SharedPtrgraphics = Graphics::FromImage(bitmap);
graphics->Clear(System::Drawing::Color::get_Yellow());
graphics->FillRectangle(Brushes::get_Blue(), System::Drawing::Rectangle(0, 0, 200, 100));
bitmap->Save(stream, Imaging::ImageFormat::get_Bmp());
// Create rectangle
double x = 100.0, y = 600.0, width = 200.0, height = 200.0;
auto rect = MakeObject(x, y, x + width, y + height);
// Add image to PDF
stream->Seek(0, System::IO::SeekOrigin::Begin);
page->AddImage(stream, rect);
// Save PDF document
doc->Save(u"Created PDF.pdf");
输入HTML文件
// Create a text file
System::IO::File::WriteAllText(u"Attachment.txt", u"Some info");
SharedPtrfileSpecification = MakeObject(u"Attachment.txt", u"Sample text file");
// Add attachment to document's attachment collection
auto doc = MakeObject();
doc->get_EmbeddedFiles()->Add(fileSpecification);
// Add a page to PDF
doc->get_Pages()->Add();
// Save PDF document
doc->Save(u"Created PDF.pdf");
输入HTML文件