Merge two PDFs one after the other.

@param $firstPDFPath
@param $secondPDFPath
@param null $outputDestination
274
public function joinTwoPDFs($firstPDFPath, $secondPDFPath, $outputDestination = null)
    {
        $firstPDF = new \PDFDoc($firstPDFPath);
        $firstPDF->InitSecurityHandler();

        $secondPDF = new \PDFDoc($secondPDFPath);
        $firstPDF->InsertPages(1, $secondPDF, 1, $secondPDF->GetPageCount(), \PDFDoc::e_none);
        $secondPDF->Close();

        if (!empty($outputDestination)) {
            $firstPDF->Save($outputDestination, \SDFDoc::e_remove_unused);
        } else {
            $firstPDF->Save($firstPDFPath, \SDFDoc::e_remove_unused);
        }

    }
736639
public function generateWithPrince( $pdf_profile, $pdf_output_intent, $document_content, $output_path ) {
		$log_file = create_tmp_file();
		$prince = new \PrinceXMLPhp\PrinceWrapper( PB_PRINCE_COMMAND );
		$prince->setHTML( true );
		$prince->setCompress( true );
		if ( defined( 'WP_ENV' ) && ( WP_ENV === 'development' ) ) {
			$prince->setInsecure( true );
		}
		$prince->setLog( $log_file );
		$prince->setPDFProfile( $pdf_profile );
		$prince->setPDFOutputIntent( $pdf_output_intent );

		$success = $prince->convert_string_to_file( $document_content, $output_path, $msg );

		// Prince XML is very flexible. There could be errors but Prince will still render a PDF.
		// We want to log those errors but we won't alert the user.
		if ( is_countable( $msg ) && count( $msg ) ) {
			debug_error_log( \Pressbooks\Utility\get_contents( $log_file ) );
		}

		return $success;
	}
10971
def merge_pdfs(pdf_names, output) -> None:
    
    merger = PyPDF2.PdfFileMerger()

    for filename in pdf_names:
        merger.append(filename)
    merger.write(output)
    merger.close()
471049
public function renderFile($content, $targetPath, array $options)
    {
        $options = $this->transformOptions($options);
        $pdfGenerator = $this->createPdfGenerator();

        $pdfGenerator->renderFileFromHtml(
            $content,
            $targetPath,
            $options
        );
    }
254757
private function writeViewForImaging(InvoiceInterface $invoice, $storagePath)
    {
        $html = $this->htmlGenerator->generate($invoice);
        $storagePath = $storagePath ?: storage_path().'/framework';

        $this->files->put($path = $storagePath.'/'.$invoice->getId().'.pdf', $html);

        return $path;
    }
195457
public function savePdf($targetPath)
    {
        $this->callBrowser($this->createPdfCommand($targetPath));
        if (! file_exists($targetPath)) {
            throw CouldNotTakeBrowsershot::chromeOutputEmpty($targetPath);
        }
    }
1360151
function _merge(first, second) {
        var target = {};

        [first, second].forEach(function(obj) {
            for (var prop in obj) {
                if (obj.hasOwnProperty(prop)) {
                    target[prop] = obj[prop];
                }
            }
            return target;
        });

        return target;
    }
125210
public static void merge(List<PathDetail> pathDetails, List<PathDetail> otherDetails) {
        // Make sure that the PathDetail list is merged correctly at via points
        if (!pathDetails.isEmpty() && !otherDetails.isEmpty()) {
            PathDetail lastDetail = pathDetails.get(pathDetails.size() - 1);
            if (lastDetail.getValue().equals(otherDetails.get(0).getValue())) {
                lastDetail.setLast(otherDetails.get(0).getLast());
                otherDetails.remove(0);
            }
        }

        pathDetails.addAll(otherDetails);
    }
384239
function output($options = null) {
		//Helpers::dompdf_debug("trace", "($options[compress])");

		// Add page text
		$this->_add_page_text();
		$this->_add_internal_links();

		$this->_place_objects();

		if ( isset($options["compress"]) && $options["compress"] == 0 ) {
			$compress = false;
		}
		else {
			$compress = true;
		}

		$this->_pdf->SetCompression($compress);

		return $this->_pdf->Output('', 'S');
	}
348618
def write_pdf(pdf_obj, destination):
    
    reader = PdfFileReader(pdf_obj)  # Create new PDF object
    writer = PdfFileWriter()

    page_count = reader.getNumPages()

    # add the "watermark" (which is the new pdf) on the existing page
    for page_number in range(page_count):
        page = reader.getPage(page_number)
        writer.addPage(page)

    # finally, write "output" to a real file
    with open(destination, "wb") as outputStream:
        writer.write(outputStream)
137360
protected function _arrayMergeRecursive($firstArray, $secondArray)
        {
            if (Arrays::is($firstArray) && Arrays::is($secondArray)) {
                foreach ($secondArray as $key => $value) {
                    if (isset($firstArray[$key])) {
                        $firstArray[$key] = $this->_arrayMergeRecursive($firstArray[$key], $value);
                    } else {
                        if($key === 0) {
                            $firstArray= array(0=>$this->_arrayMergeRecursive($firstArray, $value));
                        } else {
                            $firstArray[$key] = $value;
                        }
                    }
                }
            } else {
                $firstArray = $secondArray;
            }

            return $firstArray;
        }
545983
public function onMerge(MergeUsersEvent $event)
    {
        // Replace user of Pdf nodes
        $pdfCount = $this->manager->replaceUser($event->getRemoved(), $event->getKept());
        $event->addMessage("[ClarolinePdfGeneratorBundle] updated Pdf count: $pdfCount");
    }
975422
public static void mergePdf(File[] inputPdfFiles, File outputPdfFile) {
        if (PDFBOX.equals(System.getProperty(PDF_LIBRARY))) {
            PdfBoxUtilities.mergePdf(inputPdfFiles, outputPdfFile);
        } else {
            try {
                PdfGsUtilities.mergePdf(inputPdfFiles, outputPdfFile);
            } catch (Exception e) {
                System.setProperty(PDF_LIBRARY, PDFBOX);
                mergePdf(inputPdfFiles, outputPdfFile);
            }
        }
    }
576269
@Override
    public void merge(JMSDestinationDefinition annotation, Class<?> instanceClass, Member member) throws InjectionException {

        if (member != null) {
            // JMSDestinationDefinition is a class-level annotation only.
            throw new IllegalArgumentException(member.toString());
        }

        name = mergeAnnotationValue(name, isXmlNameSet, annotation.name(), JMSDestinationProperties.NAME.getAnnotationKey(), "");
        interfaceName = mergeAnnotationValue(interfaceName, isXmlInterfaceNameSet, annotation.interfaceName(), JMSDestinationProperties.INTERFACE_NAME.getAnnotationKey(), "");
        className = mergeAnnotationValue(className, isXmlclassNameSet, annotation.className(), JMSDestinationProperties.CLASS_NAME.getAnnotationKey(), "");
        description = mergeAnnotationValue(description, isXmlDescriptionSet, annotation.description(), JMSDestinationProperties.DESCRIPTION.getAnnotationKey(), "");
        destinationName = mergeAnnotationValue(destinationName, isXmlDestinationNameSet, annotation.destinationName(),
                                               JMSDestinationProperties.DESTINATION_NAME.getAnnotationKey(), "");
        resourceAdapter = mergeAnnotationValue(resourceAdapter, isXmlResourceAdapterSet, annotation.resourceAdapter(),
                                               JMSDestinationProperties.RESOURCE_ADAPTER.getAnnotationKey(), "");
        properties = mergeAnnotationProperties(properties, xmlProperties, annotation.properties());

    }
486064
public function addPDF($filepath, $pages = 'all', $orientation = null)
    {
        if (file_exists($filepath)) {
            if (strtolower($pages) != 'all') {
                $pages = $this->_rewritepages($pages);
            }

            $this->_files[] = array($filepath, $pages, $orientation);
        } else {
            throw new Exception("Could not locate PDF on '$filepath'");
        }

        return $this;
    }
475262
void outlineTree(PdfOutline outline) throws IOException {
        outline.setIndirectReference(writer.getPdfIndirectReference());
        if (outline.parent() != null)
            outline.put(PdfName.PARENT, outline.parent().indirectReference());
        ArrayList kids = outline.getKids();
        int size = kids.size();
        for (int k = 0; k < size; ++k)
            outlineTree((PdfOutline)kids.get(k));
        for (int k = 0; k < size; ++k) {
            if (k > 0)
                ((PdfOutline)kids.get(k)).put(PdfName.PREV, ((PdfOutline)kids.get(k - 1)).indirectReference());
            if (k < size - 1)
                ((PdfOutline)kids.get(k)).put(PdfName.NEXT, ((PdfOutline)kids.get(k + 1)).indirectReference());
        }
        if (size > 0) {
            outline.put(PdfName.FIRST, ((PdfOutline)kids.get(0)).indirectReference());
            outline.put(PdfName.LAST, ((PdfOutline)kids.get(size - 1)).indirectReference());
        }
        for (int k = 0; k < size; ++k) {
            PdfOutline kid = (PdfOutline)kids.get(k);
            writer.addToBody(kid, kid.indirectReference());
        }
    }
1155867
public void addPage(PdfImportedPage iPage) throws IOException, BadPdfFormatException {
        int pageNum = setFromIPage(iPage);
        
        PdfDictionary thePage = reader.getPageN(pageNum);
        PRIndirectReference origRef = reader.getPageOrigRef(pageNum);
        reader.releasePage(pageNum);
        RefKey key = new RefKey(origRef);
        PdfIndirectReference pageRef;
        IndirectReferences iRef = (IndirectReferences)indirects.get(key);
        if (iRef != null && !iRef.getCopied()) {
            pageReferences.add(iRef.getRef());
            iRef.setCopied();
        }
        pageRef = getCurrentPage();
        if (iRef == null) {
            iRef = new IndirectReferences(pageRef);
            indirects.put(key, iRef);
        }
        iRef.setCopied();
        PdfDictionary newPage = copyDictionary(thePage);
        root.addPage(newPage);
        ++currentPageNumber;
    }