public function testCanFillFormFromFile() { $form = $this->getForm(); $fdf = $this->getFdf(); $file = $this->getOutFile(); $pdf = new Pdf($form); $this->assertInstanceOf('mikehaertl\\pdftk\\Pdf', $pdf->fillForm($fdf)); $this->assertInstanceOf('mikehaertl\\pdftk\\Pdf', $pdf->needAppearances()); $this->assertTrue($pdf->saveAs($file)); $this->assertFileExists($file); $tmpFile = (string) $pdf->getTmpFile(); $this->assertRegExp("#pdftk A='{$form}' fill_form '{$fdf}' output '{$tmpFile}' drop_xfa need_appearances#", (string) $pdf->getCommand()); }
public function generate() { $pdf = new Pdf($this->_pdf); // Сложим рубли с копейками $num_sum1 = $this->_num_sum1 + $this->_num_sum1_kopeck; $num_sum2 = $this->_num_sum2 + $this->_num_sum2_kopeck; // echo $this->_num_sum1_kopeck;exit; //Разобьём нужные нам числа $fromIndexSplit = Number::getSplitDigits($this->_from_index, 6); $toIndexSplit = Number::getSplitDigits($this->_to_index, 6); $fromInnSplit = Number::getSplitDigits($this->_from_inn, 12); $fromCorpPriceSplit = Number::getSplitDigits($this->_from_corp_price, 20); $fromCalcPriceSplit = Number::getSplitDigits($this->_from_calc_price, 20); $pdfParams = array('words_sum1' => Number::num2str($num_sum1), 'words_sum2' => Number::num2str($num_sum2), 'num_sum1' => $this->_num_sum1, 'num_sum2' => $this->_num_sum2, 'num_sum2_kopeck' => Number::fract($this->_num_sum2_kopeck), 'to_fio' => $this->_to_fio, 'to_addr' => $this->_to_addr, 'from_fio' => $this->_from_fio, 'from_addr' => $this->_from_addr); // Склеим ассоциативные массивы с друг другом $pdfParams = array_merge($pdfParams, $this->cookPrefixArray($fromIndexSplit, 'from_index_'), $this->cookPrefixArray($toIndexSplit, 'to_index_'), $this->cookPrefixArray($fromInnSplit, 'inn_'), $this->cookPrefixArray($fromCorpPriceSplit, 'corp_price_'), $this->cookPrefixArray($fromCalcPriceSplit, 'calc_price_')); // var_dump($pdfParams); $pdf->fillForm($pdfParams)->needAppearances(); if ($err = $pdf->getError()) { return $err; } $pdf->send(); }
public function submitForm(Request $request) { //Get input $input = Input::all(); //Date $input["Date"] = date("j/ n/ Y"); //Bools for Parties if ($input["party"] == "Republican") { $input["Rep"] = "Yes"; } else { $input["Dem"] = "Yes"; } //concat name $input["Voter_Name"] = $input["first_name"] . " " . $input["last_name"]; $contents = Storage::disk('local'); $storagePath = Storage::disk('local')->getDriver()->getAdapter()->getPathPrefix(); // $contents = Storage::get('reg.pdf'); //Save as FDF $fdf = new FdfFile($input); $fdf->saveAs('data.fdf'); $docId = md5(uniqid(rand(), true)); //Save as Pdf $pdf = new Pdf($storagePath . 'template.pdf'); $pdf->fillForm($fdf->getFileName())->saveAs($storagePath . "generated/" . $docId . '.pdf'); //Setting up Lob $apiKey = env('LOB_KEY'); $lob = new \Lob\Lob($apiKey); //Send the letter $letter = $lob->letters()->create(array('description' => 'Voter Registration', 'to[name]' => 'Town Clerk', 'to[address_line1]' => '230 Main St, Ste 108', 'to[address_city]' => 'Brattleboro', 'to[address_zip]' => '05301', 'to[address_state]' => 'VT', 'to[address_country]' => 'US', 'from[name]' => 'Benjamin Franklin', 'from[address_line1]' => '123 Fake Street', 'from[address_city]' => 'Philadelphia', 'from[address_zip]' => '94041', 'from[address_state]' => 'PA', 'from[address_country]' => 'US', 'file' => '@' . realpath($storagePath . "generated/" . $docId . '.pdf'), 'color' => false)); $letter['file'] = $storagePath . "generated/" . $docId . '.pdf'; return View::make('thanks', $letter)->with('data', $letter); }