// Combine individual pages $command = "gs \\\n" . " -o " . $article_pdf_filename . " \\\n" . "-sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \\\n"; $n = count($reference->ia->pages); for ($i = 0; $i < $n; $i++) { $command .= $tmpdir . '/' . $reference->ia->pages[$i] . '.pdf '; if ($i < $n - 1) { $command .= '\\'; } $command .= "\n"; } echo $command . "\n"; system($command); // XMP? // Mendeley doesn't seem to recognise XMP if (0) { pdf_add_xmp($reference, $article_pdf_filename); } } // Have PDF, now do something with it... if (1) { $identifier = 'biostor-' . $biostor; // upload to IA $headers = array(); $headers[] = '"x-archive-auto-make-bucket:1"'; $headers[] = '"x-archive-ignore-preexisting-bucket:1"'; $headers[] = '"x-archive-interactive-priority:1"'; // collection $headers[] = '"x-archive-meta01-collection:biostor"'; // metadata $headers[] = '"x-archive-meta-sponsor:BioStor"'; $headers[] = '"x-archive-meta-mediatype:texts"';
/** * @brief Create PDF for a reference * * We create a simple cover page for the PDF. This page contains basic bibliographic metadata * for the PDF, in order for Mendeley to process the PDF correctly. In response to my discovery * that Mendeley doesn't accept all XMP (Ticket#2010040110000015) support@mendeley.com replied that * they have some heuristic tests to see if the metadata is valid, such as whether the information * about the title and authors occurs on the first of the PDF. * * * @param reference_id Reference id * @param pdf_filename Full path of PDF file to create * */ function pdf_create($reference_id, $pdf_filename) { global $config; // Get reference $reference = db_retrieve_reference($reference_id); // Get tags $tags = pdf_tags($reference->reference_id, 10); // Paper size // A4 = 210 x 297 $paper_width = 210; // mm $paper_height = 297; // mm $margin = 10; //---------------------------------------------------------------------------------------------- // PDF $pdf = new FPDF('P', 'mm', 'A4'); //$pdf = PDF_Rotate('P', 'mm', 'A4'); //---------------------------------------------------------------------------------------------- // Basic metadata (e.g., that displayed by Mac OS X Preview) $pdf->SetTitle($reference->title, true); // true means use UTF-8 $pdf->SetAuthor(reference_authors_to_text_string($reference), true); // true means use UTF-8 if (count($tags) > 0) { $pdf->SetKeywords(join(", ", $tags), true); } //---------------------------------------------------------------------------------------------- // Cover page (partly to ensure Mendeley accepts XMP metadata) $pdf->AddPage(); // Title $pdf->SetFont('Arial', '', 24); $pdf->SetXY($margin, $margin); $pdf->Write(10, utf8_decode($reference->title)); // Authors $y = $pdf->GetY(); $pdf->SetXY($margin, $y + 16); $pdf->SetFont('Arial', 'B', 16); $pdf->Write(6, utf8_decode(reference_authors_to_text_string($reference))); // Citation $y = $pdf->GetY(); $pdf->SetXY($margin, $y + 10); $pdf->SetFont('Arial', 'I', 12); $pdf->Write(6, utf8_decode($reference->secondary_title)); $pdf->SetFont('Arial', '', 12); $pdf->Write(6, ' ' . $reference->volume); if (isset($reference->issue)) { $pdf->Write(6, '(' . $reference->issue . ')'); } $pdf->Write(6, ':' . $reference->spage); if (isset($reference->epage)) { $pdf->Write(6, '-' . $reference->epage); } $pdf->Write(6, ' (' . $reference->year . ')'); // URL $url = $config['web_root'] . 'reference/' . $reference->reference_id; $pdf->Write(6, ' '); $pdf->SetTextColor(0, 0, 255); $pdf->SetFont('', 'U'); $pdf->Write(6, $url, $url); $pdf->SetFont('', ''); $pdf->SetTextColor(0, 0, 0); //---------------------------------------------------------------------------------------------- // If we add taxon names as keywords if (count($tags) > 0) { $keywords = "Keywords: " . join("; ", $tags); $y = $pdf->GetY(); $pdf->SetXY($margin, $y + 10); $pdf->Write(6, $keywords); } //---------------------------------------------------------------------------------------------- // Footer giving credit to BHL $y = $paper_height; $y -= $margin; $y -= 40; $pdf->Image($config['web_dir'] . '/images/cc/cc.png', 10, $y, 10); $pdf->Image($config['web_dir'] . '/images/cc/by.png', 20, $y, 10); $pdf->Image($config['web_dir'] . '/images/cc/nc.png', 30, $y, 10); $pdf->SetXY(10, $y + 10); $pdf->SetFont('Arial', '', 10); $pdf->SetTextColor(0, 0, 0); $pdf->Write(6, 'Page images from the Biodiversity Heritage Library, '); //Then put a blue underlined link $pdf->SetTextColor(0, 0, 255); $pdf->SetFont('', 'U'); $pdf->Write(6, 'http://www.biodiversitylibrary.org/', 'http://www.biodiversitylibrary.org/'); $pdf->SetFont('', ''); $pdf->SetTextColor(0, 0, 0); $pdf->Write(6, ', made available under a Creative Commons Attribution-Noncommercial License '); $pdf->SetTextColor(0, 0, 255); $pdf->SetFont('', 'U'); $pdf->Write(6, 'http://creativecommons.org/licenses/by-nc/2.5/', 'http://creativecommons.org/licenses/by-nc/2.5/'); //---------------------------------------------------------------------------------------------- // Add BHL page scans $pages = bhl_retrieve_reference_pages($reference_id); foreach ($pages as $page) { $image = bhl_fetch_page_image($page->PageID); $page_width = $paper_width; $page_height = $paper_height; $page_width -= 2 * $margin; $page_height -= 2 * $margin; // Fit to page $img_height = $image->height; $img_width = $image->width; $w_scale = $page_width / $img_width; $h_scale = $page_height / $img_height; $scale = min($w_scale, $h_scale); $img_height *= $scale; $img_width *= $scale; $pdf->AddPage(); $x_offset = ($paper_width - $img_width) / 2.0; $y_offset = ($paper_height - $img_height) / 2.0; $pdf->Image($image->file_name, $x_offset, $y_offset, $img_width); } $pdf->Output($pdf_filename, 'F'); pdf_add_xmp($reference, $pdf_filename, $tags); }