Forum


Replies: 1   Views: 2594
Transformdocument problem with valign => center in pdf
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by gh_ost  · 28-11-2017 - 06:38

Hellow! 

I am trying convert docx to pdf and in pdf third column text must be vertical align center. 

https://drive.google.com/open?id=1_SB5gjXFuFw3hWLoJHt_PFX5_0GE2Dfi

this document must give this result 

https://drive.google.com/open?id=1KiIcY9d9o4H7g3M1XgP1KrrF6jLe8y1E

I use this code

$data = Input::all();
        $obj_id = $data['obj_id'];
        $lang = $data['lang'];
        $expert_id = $data['expert_id'];
        $forNNS = $data['for_nns'];

        // þÿрõôõÃȄõü Ñ÷ыú
        $sysLang = App::getLocale();
        App::setLocale($lang);
        $lang_criteria = 'name_criteria_'.App::getLocale();
        // ýðхþôøü ÿõрõüõýýыõ ôÃȄ óõýõрðцøø
        $obj = ObjMain::findOrFail($obj_id);// ÷ðÑòúð
        $evals = EvaluationMain::where('obj_id',$obj->id)->where('expert_id', $expert_id)->where('status_id', '>', EvaluationStatus::ConfirmedByExpert);
        if ($evals->count() < 1)
            return Redirect::back()->with('error', trans('objects.summary_conclusion_warning'));

        $evals = EvaluationMain::where('obj_id',$obj->id)->where('expert_id', $expert_id)->with('evalDetails')->get();
        $expert = SPerson::where('main_user_id', $expert_id)->first();

        $rowWithBall = array();
        $rowWithoutBall = array();
        foreach ($evals as $e) {
            foreach ($e->evalDetails as $cr){ //echo '<pre>'; var_dump($e->evalDetails); die();
                if ($cr->score > 0) {
                    $rowWithBall[$cr->criteria_id]['comments'][]= $cr->comment;
                    $rowWithBall[$cr->criteria_id]['score'][]= $cr->score;
                    $rowWithBall[$cr->criteria_id][$lang_criteria]= $cr->evalRows->$lang_criteria;
                }
                else{
                    $rowWithoutBall[$cr->criteria_id]['comments'][] = $cr->comment;
                    $rowWithoutBall[$cr->criteria_id][$lang_criteria]= $cr->evalRows->$lang_criteria;
                }
            }
        }
        $summBall = 0;
        foreach ($rowWithBall as $k=>$r) {
            $score = round(array_sum($r['score']) / count($r['score']), 2);
            $rowWithBall[$k]['score'] = $score;
            $summBall += $score;
        }
        $countCrit = count($rowWithBall);// úþûøчõÑтòþ úрøтõрøõò
        $letterSum = $this->getLetterSum($summBall,$countCrit);//Ã¿Ã¾Ñ€Ã¾Ã³Ã¾Ã²Ã°Ñ Ã¾Ñ†ÃµÃ½ÃºÃ°

        // þÿрõôõÃȄü ÷ðóþûþòúø
        $header = ($forNNS == 0) ? trans('evaluation.evaluation_form_header') : trans('evaluation.summary_evaluation_form_header');// ÷ðóþûþòþú ôþúуüõýтð õÑûø 0 ÓÃâí 1 ÃÃá
        $signature = trans('expert.expert').' '.$expert->getFullName().' _____________________';//($forNNS == 0) ? trans('evaluation.evaluation_form_signature_individual') : trans('evaluation.evaluation_form_signature_organizer'); //ÿþôÿøÑÑŒ
        $header1 = trans('evaluation.evaluation_criteria_name');//Ãðøüõýþòðýøõ úрøтõрøõò þцõýúø
        $header2 = trans('evaluation.evaluation_form_score_header');//Ñðûû (þт 1 ôþ 9)
        $header3 = trans('evaluation.evaluation_form_comment_header');//Úþüüõýтðрøø
        $sumBallName = trans('evaluation.evaluation_form_total_score');//Ã˜Ñ‚Ã¾Ã³Ã¾Ã²Ã°Ñ Ã¾Ñ†ÃµÃ½ÃºÃ°
        $lettterBallName = trans('evaluation.evaluation_form_threshold_score');//ÃŸÃ¾Ñ€Ã¾Ã³Ã¾Ã²Ã°Ñ Ã¾Ñ†ÃµÃ½ÃºÃ°Ã°

        $pageParametrs = [
            'marginLeft' => 15*56.7, //Ûõòþõ ÿþûõ рðòýþ 15 üü
            'marginRight' => 15*56.7,
            'marginTop' => 15*56.7,
            'marginBottom' => 15*56.7,
            'borderTopColor' => 'C0C0C0'
        ];
        $tableParametrs = [
            'tableWidth' => [
                'type' => 'pct',
                'value' => 100,
            ],
            'tableLayout' => 'fixed',
            'columnWidths' => [25,470,140,650],
            'border' => 'single',
            'tableAlign' => 'center',
            'borderWidth' => 5,
            'textProperties' => array('fontSize' => 10),
        ];

        $word = new CreateDocx();
        $word->modifyPageLayout('A4-landscape', $pageParametrs);
        $word->setDefaultFont('Times New Roman');

        $pStyleBold = ['fontSize'=>10, 'textAlign' => 'center', 'bold' => true];
        $StyleSignature = ['fontSize'=>10, 'textAlign' => 'left', 'bold' => true, 'spacingTop' => 1500];

        $word->addText($header, $pStyleBold);
        $word->addText(trans('evaluation.within'), $pStyleBold);
        if(App::getLocale() == 'ru'){
            $objName = $obj->topicrus;
        } else if(App::getLocale() == 'kz'){
            $objName = $obj->topickaz;
        } else if(App::getLocale() == 'en'){
            $objName = $obj->topiceng;
        }
        $word->addText(trans('objects.irn').' '.$obj->number.' - «'.$objName.'»', $pStyleBold);

        $header1Fragment = new WordFragment($word);
        $header1Fragment->addText($header1, ['textAlign' => 'center', 'bold' => true, 'fontSize' => 10]);
        $header2Fragment = new WordFragment($word);
        $header2Fragment->addText($header2, ['textAlign' => 'center', 'bold' => true, 'fontSize' => 10]);
        $header3Fragment = new WordFragment($word);
        $header3Fragment->addText($header3, ['textAlign' => 'center', 'bold' => true, 'fontSize' => 10]);

        $evalData = [
            [
                ['colspan' => 2,'value' => $header1Fragment],
                $header2Fragment,
                $header3Fragment
            ],
        ];
        $i = 1;
        foreach ($rowWithBall as $k =>  $r){
            foreach ($r['comments'] as $c) {
                $comments = strip_tags(html_entity_decode($c));
                $comments = str_replace('&quot;', '"', $comments); // уñøрðõü &quot;
                $comments = str_replace('&nbsp;', ' ', $comments); // уñøрðõü &nbsp;
            }

            $scoreText = new WordFragment($word);
            $scoreText->addText($r['score'], ['textAlign' => 'center', 'fontSize' => 10]);
            $score = [
                'width' => 1400,
                'value' => $scoreText,
                'vAlign' => 'center',
            ];
            $iter = [
                'width' => 10,
                'value' => $i,
            ];
            $criteria = [
                'width' => 4500,
                'value' => $r[$lang_criteria]
            ];
            $comment = [
                'value' => $comments,
                'width' => 6000
            ];
            $evalData[] = [$iter,$criteria , $score , $comment];
            $i++;
        }
        //Ã¸Ñ‚Ã¾Ã³Ã¾Ã²Ã°Ñ Ã¾Ñ†ÃµÃ½ÃºÃ°
        $summText = new WordFragment($word);
        $summText->addText($summBall, ['textAlign' => 'center', 'fontSize' => 10]);
        $summBallVal = [
            'colspan' => 2,
            'value' => $summText,
            'vAlign' => 'center',
        ];
        if ($forNNS) { // õÑûø ÷ðúûючõýøõ ôÃȄ ÃÃá, тþ ôþñðòÃȄõü ßþрþóþòую þцõýúу
            $evalData[] = [$sumBallName, $summBall, $lettterBallName, $letterSum]; // ýðøüõýþòðýøõ ÿþÃȄ //ñðûû //ýðøüõýþòðýøõ ÿþÃȄ "ÃŸÃ¾Ñ€Ã¾Ã³Ã¾Ã²Ã°Ñ Ã¾Ñ†ÃµÃ½ÃºÃ°" //ÃŸÃ¾Ñ€Ã¾Ã³Ã¾Ã²Ã°Ñ Ã¾Ñ†ÃµÃ½ÃºÃ°
        } else{
            $evalData[] = [['colspan' => 2, 'value' => $sumBallName], $summBallVal]; // ýðøüõýþòðýøõ ÿþÃȄ //ñðûû //ÿуÑтышúð
        }
        // ÿþÃȄ úрøтõрøõò ñõ÷ ñðûûð
        foreach ($rowWithoutBall as $r){
            foreach ($r['comments'] as $c) {
                $comments = strip_tags(html_entity_decode($c));
                $comments = str_replace('&quot;', '"', $comments); // уñøрðõü &quot;
                $comments = str_replace('&nbsp;', ' ', $comments); // уñøрðõü &nbsp;
                $comments = trim(preg_replace('/\t+/', '', $comments));
            }
            $comment = new WordFragment($word);
            $comment->addText($comments, ['fontSize' => 10, 'fitText' => true, 'textDirection' => 'tbRl', 'tab' => false]);
            $evalData[] = [['colspan' => 2, 'value' => $r[$lang_criteria]], ['colspan' => 2, 'value' => $comment]]; // áøûьýыõ Ñтþрþýы // ñðûû // úþüüõýт
        }

        $word->addTable($evalData, $tableParametrs);
        $word->addText($signature, $StyleSignature);

        //áúðчøòðýøÑ
        $documentName = 'evaluation_form_'.$obj->number.'_'.$expert_id;
        $documentName = str_replace('/','_', $documentName);
        $word->createDocx($documentName);
        $word->enableCompatibilityMode();
        $word->transformDocument($documentName.'.docx', $documentName.'.pdf', ['odfconverter' => false, 'method' => 'direct']);

        unlink($documentName.'.docx');
        App::setLocale($sysLang);
        return Response::download( $documentName.'.pdf')->deleteFileAfterSend(true);

regards

Posted by admin  · 28-11-2017 - 07:56

Hello,

Your documents are protected and we can't download them, please send them to contact[at]phpdocx.com and as your user doesn't have any license tied, please also send the username or email of the user that has purchased the license.

Regards.