コード例 #1
1
// - Optionally add table of contents, including setting the depth and appearance.
//---------------------------------------------------------------------------------------
$output_path = "../../TestFiles/Output/html2pdf_example";
$host = "http://www.gutenberg.org/";
$page0 = "wiki/Main_Page";
$page1 = "catalog/";
$page2 = "browse/recent/last1";
$page3 = "wiki/Gutenberg:The_Sheet_Music_Project";
// The first step in every application using PDFNet is to initialize the
// library and set the path to common PDF resources. The library is usually
// initialized only once, but calling Initialize() multiple times is also fine.
PDFNet::Initialize();
// For HTML2PDF we need to locate the html2pdf module. If placed with the
// PDFNet library, or in the current working directory, it will be loaded
// automatically. Otherwise, it must be set manually using HTML2PDF.SetModulePath.
HTML2PDF::SetModulePath("./../../../PDFNetC/Lib");
//--------------------------------------------------------------------------------
// Example 1) Simple conversion of a web page to a PDF doc.
$doc = new PDFDoc();
// now convert a web page, sending generated PDF pages to doc
$converter = new HTML2PDF();
$converter->InsertFromURL($host . $page0);
if ($converter->Convert($doc)) {
    $doc->Save($output_path . "_01.pdf", SDFDoc::e_linearized);
} else {
    echo printf("Conversion failed. HTTP Code: %d\n%s", $converter->GetHTTPErrorCode(), $converter->GetLog());
}
$doc->Close();
//--------------------------------------------------------------------------------
// Example 2) Modify the settings of the generated PDF pages and attach to an
// existing PDF document.