• Resolved jakeashley

    (@jakeashley)


    My goal:
    When one of our users chooses to download a pdf, that chosen pdf then passes through my filter to append a footer containing contact information via FPDI/FPDF.

    What I need help with:
    Identifying the correct parameter used by Download Monitor to have this happen. I have done most of the work as you can see below, so hopefully you can help.

    add_filter( 'dlm_file_path', 'Auto_Custom_Flyer');
    
    	use setasign\Fpdi\Fpdi;
    
    function Auto_Custom_Flyer() {
    	
    	require('wp-content/themes/enfold-child/FPDF/fpdf.php');
    	require_once('wp-content/themes/enfold-child/FPDI/src/autoload.php');
    	
    	$current_user = wp_get_current_user();
    	$user_headshot = get_avatar_url(wp_get_current_user());
    	
    	$file_path = ANY_PDF_DOWNLOAD_BY_USER;
    	$pdf = new Fpdi();
    	$pdf->AddPage('P', 'Letter');
    	$pdf->setSourceFile( $file_path );
    	$tplIdx = $pdf->importPage(1);
    	$pdf->useTemplate($tplIdx, 0,0,215.9);
    	
    	$pdf->Line(9.525, 209, 206.375, 209);
    	$pdf->SetFont('Helvetica');
    	$pdf->SetTextColor(0, 0, 0);
    	$pdf->SetFontSize(10);
    	$pdf->SetXY(41, 215);
    	$pdf->MultiCell(150,5,"$current_user->display_name \nLoan Officer \nNMLS #123456 \n\n555-555-5555 \n$current_user->user_email");
    	$pdf->SetFont('Helvetica');
    	$pdf->SetTextColor(0, 0, 0);
    	$pdf->SetFontSize(7);
    	$pdf->SetXY(9.525, 250);
    	$pdf->MultiCell(0,3,"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
    	$pdf->Image($user_headshot,9.525,216,28,0,'JPEG');
    	
    	$pdf->Output();
    	
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hey @jakeashley,

    I’m sorry to say but this is beyond the scope of our support. Customization of any code (especially advanced things like PDF manipulation) is allowed but this is something we can’t help you with.

    Kind Regards,

    Barry Kooij

    Thread Starter jakeashley

    (@jakeashley)

    @barrykooij

    No problem. I figured it out.

    For others interested:

    use setasign\Fpdi\Fpdi;
    
    add_filter( 'dlm_file_path', 'auto_custom_flyer' );
    function auto_custom_flyer($this) {
    
    	require('FPDF/fpdf.php');
    	require_once('FPDI/src/autoload.php');
    	
    	$current_user = wp_get_current_user();
    	$user_headshot = get_avatar_url( wp_get_current_user() );
    	// Initiate FPDI library
    	$pdf = new Fpdi();
    	// Add a PDF page
    	$pdf->AddPage('P', 'Letter');
    	// Set the source file of that PDF page
    	$pdf->setSourceFile($this);
    	// Import file
    	$tplIdx = $pdf->importPage(1);
    	// Use the imported file and place it at position 0,0 with a width of 215.9 (US Letter 215.9mm x 279.4mm)
    	$pdf->useTemplate($tplIdx, 0, 0, 215.9);
    	
    	// Now add headshot and information/custom fields on top of the imported PDF file
    	$pdf->Line(9.525, 209, 206.375, 209);
    	$pdf->SetFont('Helvetica');
    	$pdf->SetTextColor(0, 0, 0);
    	$pdf->SetFontSize(9);
    	$pdf->SetXY(41.935, 213.763);
    	$pdf->MultiCell(61.253,4,"$current_user->display_name \nLoan Officer \nNMLS #123456 \n\n555-555-5555 \n$current_user->user_email");
    	$pdf->SetFont('Helvetica');
    	$pdf->SetTextColor(0, 0, 0);
    	$pdf->SetFontSize(7);
    	$pdf->SetXY(9.525, 250);
    	$pdf->MultiCell(0,3,"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
    	$pdf->Image($user_headshot,9.525,213.763,28,0,'JPEG');
    	
    	
    	
    	$pdf->Output();
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Need help identifying the correct parameter to pass through my filter’ is closed to new replies.