TCPdf add custom author or page to footer in multiple pages ( author/page can be different on each page )












0















I have found a lot of information about page numbers in the footer for TCpdf, but I haven't found the solution to my specific problem.



My problem:
A user can add a content type with : image, page number, title and orientation.
The page number is needed, because the content is created when an image is received. So this is not in chronological order. An image can be added for page 20, while later on, an image that should be on page 2 is send.
So as solution I added the possibility to add page number as field in the content type.



when the content type is created, the full pdf is again generated. But how can I set the page to the inserted page?



The solution I had was to disable the footer, and add my own line when adding the page. But when trying to create the table of contents, it takes the last page number and keeps repeating the last number.
pagetitle1.....................40
pagetitle2.....................40
...



my code for when each page is created ( where I thought I could add a setPage($number)), but this gave the error: Wrong page number on setPage() function



  foreach ($nodes as $node) {
$title = $node->title;
$image = $node->field_tune['und'][0];
$image_orientation = $node->field_orientatie['und'][0]['value'];
$author = $node->field_composer['und'][0]['value'];
$page = $node->field_page['und'][0]['value'];
$orientation = ($image_orientation === 'Landscape' ) ? 'L' : 'P';

// add a page
$pdf->AddPage($orientation, 'A4', FALSE, TRUE);

//Here I added the code to set page number
//$pdf->setPage($page); --> this gave the error.
//But after further checking, this wasn't something to set
//pagenumber, but to go back to the defined page.

$pdf->Bookmark($title, 0, 0, '', 'B', array(0,64,128));


$html = theme('html_content_type_theme', [
'image' => theme('image_style', [
'style_name' => 'styled_image',
'path' => $image_uri,
]),
'orientation' => $orientation,
'title' => $title,
'author' => $author,
]);

// output the HTML content
$pdf->writeHTML($html, TRUE, TRUE, TRUE, FALSE, '');
$pdf->SetY(-15);
$pdf->SetFont('helvetica', '', 10);
//Here I create my custom footer to see the correct page
$pdf->Cell(0, 10, 'Ypres surrey Pipes & drums', 0, FALSE, 'C', 0, '', 0, FALSE, 'T', 'C');
$pdf->Cell(0, 10, $page, 0, FALSE, 'T', 0, '', 0, FALSE, 'T', 'C');


}



Another question: every content can be created by a custom author. How can I add the author name to the footer? ( Solution now: Is to add the author also as custom line in the html, not in the footer )










share|improve this question





























    0















    I have found a lot of information about page numbers in the footer for TCpdf, but I haven't found the solution to my specific problem.



    My problem:
    A user can add a content type with : image, page number, title and orientation.
    The page number is needed, because the content is created when an image is received. So this is not in chronological order. An image can be added for page 20, while later on, an image that should be on page 2 is send.
    So as solution I added the possibility to add page number as field in the content type.



    when the content type is created, the full pdf is again generated. But how can I set the page to the inserted page?



    The solution I had was to disable the footer, and add my own line when adding the page. But when trying to create the table of contents, it takes the last page number and keeps repeating the last number.
    pagetitle1.....................40
    pagetitle2.....................40
    ...



    my code for when each page is created ( where I thought I could add a setPage($number)), but this gave the error: Wrong page number on setPage() function



      foreach ($nodes as $node) {
    $title = $node->title;
    $image = $node->field_tune['und'][0];
    $image_orientation = $node->field_orientatie['und'][0]['value'];
    $author = $node->field_composer['und'][0]['value'];
    $page = $node->field_page['und'][0]['value'];
    $orientation = ($image_orientation === 'Landscape' ) ? 'L' : 'P';

    // add a page
    $pdf->AddPage($orientation, 'A4', FALSE, TRUE);

    //Here I added the code to set page number
    //$pdf->setPage($page); --> this gave the error.
    //But after further checking, this wasn't something to set
    //pagenumber, but to go back to the defined page.

    $pdf->Bookmark($title, 0, 0, '', 'B', array(0,64,128));


    $html = theme('html_content_type_theme', [
    'image' => theme('image_style', [
    'style_name' => 'styled_image',
    'path' => $image_uri,
    ]),
    'orientation' => $orientation,
    'title' => $title,
    'author' => $author,
    ]);

    // output the HTML content
    $pdf->writeHTML($html, TRUE, TRUE, TRUE, FALSE, '');
    $pdf->SetY(-15);
    $pdf->SetFont('helvetica', '', 10);
    //Here I create my custom footer to see the correct page
    $pdf->Cell(0, 10, 'Ypres surrey Pipes & drums', 0, FALSE, 'C', 0, '', 0, FALSE, 'T', 'C');
    $pdf->Cell(0, 10, $page, 0, FALSE, 'T', 0, '', 0, FALSE, 'T', 'C');


    }



    Another question: every content can be created by a custom author. How can I add the author name to the footer? ( Solution now: Is to add the author also as custom line in the html, not in the footer )










    share|improve this question



























      0












      0








      0








      I have found a lot of information about page numbers in the footer for TCpdf, but I haven't found the solution to my specific problem.



      My problem:
      A user can add a content type with : image, page number, title and orientation.
      The page number is needed, because the content is created when an image is received. So this is not in chronological order. An image can be added for page 20, while later on, an image that should be on page 2 is send.
      So as solution I added the possibility to add page number as field in the content type.



      when the content type is created, the full pdf is again generated. But how can I set the page to the inserted page?



      The solution I had was to disable the footer, and add my own line when adding the page. But when trying to create the table of contents, it takes the last page number and keeps repeating the last number.
      pagetitle1.....................40
      pagetitle2.....................40
      ...



      my code for when each page is created ( where I thought I could add a setPage($number)), but this gave the error: Wrong page number on setPage() function



        foreach ($nodes as $node) {
      $title = $node->title;
      $image = $node->field_tune['und'][0];
      $image_orientation = $node->field_orientatie['und'][0]['value'];
      $author = $node->field_composer['und'][0]['value'];
      $page = $node->field_page['und'][0]['value'];
      $orientation = ($image_orientation === 'Landscape' ) ? 'L' : 'P';

      // add a page
      $pdf->AddPage($orientation, 'A4', FALSE, TRUE);

      //Here I added the code to set page number
      //$pdf->setPage($page); --> this gave the error.
      //But after further checking, this wasn't something to set
      //pagenumber, but to go back to the defined page.

      $pdf->Bookmark($title, 0, 0, '', 'B', array(0,64,128));


      $html = theme('html_content_type_theme', [
      'image' => theme('image_style', [
      'style_name' => 'styled_image',
      'path' => $image_uri,
      ]),
      'orientation' => $orientation,
      'title' => $title,
      'author' => $author,
      ]);

      // output the HTML content
      $pdf->writeHTML($html, TRUE, TRUE, TRUE, FALSE, '');
      $pdf->SetY(-15);
      $pdf->SetFont('helvetica', '', 10);
      //Here I create my custom footer to see the correct page
      $pdf->Cell(0, 10, 'Ypres surrey Pipes & drums', 0, FALSE, 'C', 0, '', 0, FALSE, 'T', 'C');
      $pdf->Cell(0, 10, $page, 0, FALSE, 'T', 0, '', 0, FALSE, 'T', 'C');


      }



      Another question: every content can be created by a custom author. How can I add the author name to the footer? ( Solution now: Is to add the author also as custom line in the html, not in the footer )










      share|improve this question
















      I have found a lot of information about page numbers in the footer for TCpdf, but I haven't found the solution to my specific problem.



      My problem:
      A user can add a content type with : image, page number, title and orientation.
      The page number is needed, because the content is created when an image is received. So this is not in chronological order. An image can be added for page 20, while later on, an image that should be on page 2 is send.
      So as solution I added the possibility to add page number as field in the content type.



      when the content type is created, the full pdf is again generated. But how can I set the page to the inserted page?



      The solution I had was to disable the footer, and add my own line when adding the page. But when trying to create the table of contents, it takes the last page number and keeps repeating the last number.
      pagetitle1.....................40
      pagetitle2.....................40
      ...



      my code for when each page is created ( where I thought I could add a setPage($number)), but this gave the error: Wrong page number on setPage() function



        foreach ($nodes as $node) {
      $title = $node->title;
      $image = $node->field_tune['und'][0];
      $image_orientation = $node->field_orientatie['und'][0]['value'];
      $author = $node->field_composer['und'][0]['value'];
      $page = $node->field_page['und'][0]['value'];
      $orientation = ($image_orientation === 'Landscape' ) ? 'L' : 'P';

      // add a page
      $pdf->AddPage($orientation, 'A4', FALSE, TRUE);

      //Here I added the code to set page number
      //$pdf->setPage($page); --> this gave the error.
      //But after further checking, this wasn't something to set
      //pagenumber, but to go back to the defined page.

      $pdf->Bookmark($title, 0, 0, '', 'B', array(0,64,128));


      $html = theme('html_content_type_theme', [
      'image' => theme('image_style', [
      'style_name' => 'styled_image',
      'path' => $image_uri,
      ]),
      'orientation' => $orientation,
      'title' => $title,
      'author' => $author,
      ]);

      // output the HTML content
      $pdf->writeHTML($html, TRUE, TRUE, TRUE, FALSE, '');
      $pdf->SetY(-15);
      $pdf->SetFont('helvetica', '', 10);
      //Here I create my custom footer to see the correct page
      $pdf->Cell(0, 10, 'Ypres surrey Pipes & drums', 0, FALSE, 'C', 0, '', 0, FALSE, 'T', 'C');
      $pdf->Cell(0, 10, $page, 0, FALSE, 'T', 0, '', 0, FALSE, 'T', 'C');


      }



      Another question: every content can be created by a custom author. How can I add the author name to the footer? ( Solution now: Is to add the author also as custom line in the html, not in the footer )







      pdf drupal-7 tcpdf page-numbering






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 11:05







      drupalteamrework

















      asked Nov 21 '18 at 6:22









      drupalteamreworkdrupalteamrework

      12




      12
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I found the solution to pass a custom number to my footer. This also will be the solution for my header problem where I want to add the author.



          class MYPDF extends TCPDF {

          public $pageNumber = '1';

          /**
          * @return string
          */
          public function getPageNumber(): string {
          return $this->pageNumber;
          }

          /**
          * @param string $pageNumber
          *
          * @return MYPDF
          */
          public function setPageNumber(string $pageNumber): MYPDF {
          $this->pageNumber = $pageNumber;
          return $this;
          }

          public function Footer() {
          $this->SetY(-15);
          $this->SetFont('helvetica', 'I', 8);
          $this->Cell(0, 10, $this->pageNumber, 0, false, 'R', 0, '', 0, false, 'T', 'M');
          }
          }


          In my foreach( $nodes ... ) I added the $pdf->setPageNumber($page)
          This needs to be after the addPage. Because else, the footer will receive the number of the previous node.



          $pdf->AddPage($orientation, 'A4', FALSE, TRUE);
          $pdf->setPageNumber($page);


          this can dan be done for all the custom changes you want to have on header or footer






          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406300%2ftcpdf-add-custom-author-or-page-to-footer-in-multiple-pages-author-page-can-be%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I found the solution to pass a custom number to my footer. This also will be the solution for my header problem where I want to add the author.



            class MYPDF extends TCPDF {

            public $pageNumber = '1';

            /**
            * @return string
            */
            public function getPageNumber(): string {
            return $this->pageNumber;
            }

            /**
            * @param string $pageNumber
            *
            * @return MYPDF
            */
            public function setPageNumber(string $pageNumber): MYPDF {
            $this->pageNumber = $pageNumber;
            return $this;
            }

            public function Footer() {
            $this->SetY(-15);
            $this->SetFont('helvetica', 'I', 8);
            $this->Cell(0, 10, $this->pageNumber, 0, false, 'R', 0, '', 0, false, 'T', 'M');
            }
            }


            In my foreach( $nodes ... ) I added the $pdf->setPageNumber($page)
            This needs to be after the addPage. Because else, the footer will receive the number of the previous node.



            $pdf->AddPage($orientation, 'A4', FALSE, TRUE);
            $pdf->setPageNumber($page);


            this can dan be done for all the custom changes you want to have on header or footer






            share|improve this answer






























              0














              I found the solution to pass a custom number to my footer. This also will be the solution for my header problem where I want to add the author.



              class MYPDF extends TCPDF {

              public $pageNumber = '1';

              /**
              * @return string
              */
              public function getPageNumber(): string {
              return $this->pageNumber;
              }

              /**
              * @param string $pageNumber
              *
              * @return MYPDF
              */
              public function setPageNumber(string $pageNumber): MYPDF {
              $this->pageNumber = $pageNumber;
              return $this;
              }

              public function Footer() {
              $this->SetY(-15);
              $this->SetFont('helvetica', 'I', 8);
              $this->Cell(0, 10, $this->pageNumber, 0, false, 'R', 0, '', 0, false, 'T', 'M');
              }
              }


              In my foreach( $nodes ... ) I added the $pdf->setPageNumber($page)
              This needs to be after the addPage. Because else, the footer will receive the number of the previous node.



              $pdf->AddPage($orientation, 'A4', FALSE, TRUE);
              $pdf->setPageNumber($page);


              this can dan be done for all the custom changes you want to have on header or footer






              share|improve this answer




























                0












                0








                0







                I found the solution to pass a custom number to my footer. This also will be the solution for my header problem where I want to add the author.



                class MYPDF extends TCPDF {

                public $pageNumber = '1';

                /**
                * @return string
                */
                public function getPageNumber(): string {
                return $this->pageNumber;
                }

                /**
                * @param string $pageNumber
                *
                * @return MYPDF
                */
                public function setPageNumber(string $pageNumber): MYPDF {
                $this->pageNumber = $pageNumber;
                return $this;
                }

                public function Footer() {
                $this->SetY(-15);
                $this->SetFont('helvetica', 'I', 8);
                $this->Cell(0, 10, $this->pageNumber, 0, false, 'R', 0, '', 0, false, 'T', 'M');
                }
                }


                In my foreach( $nodes ... ) I added the $pdf->setPageNumber($page)
                This needs to be after the addPage. Because else, the footer will receive the number of the previous node.



                $pdf->AddPage($orientation, 'A4', FALSE, TRUE);
                $pdf->setPageNumber($page);


                this can dan be done for all the custom changes you want to have on header or footer






                share|improve this answer















                I found the solution to pass a custom number to my footer. This also will be the solution for my header problem where I want to add the author.



                class MYPDF extends TCPDF {

                public $pageNumber = '1';

                /**
                * @return string
                */
                public function getPageNumber(): string {
                return $this->pageNumber;
                }

                /**
                * @param string $pageNumber
                *
                * @return MYPDF
                */
                public function setPageNumber(string $pageNumber): MYPDF {
                $this->pageNumber = $pageNumber;
                return $this;
                }

                public function Footer() {
                $this->SetY(-15);
                $this->SetFont('helvetica', 'I', 8);
                $this->Cell(0, 10, $this->pageNumber, 0, false, 'R', 0, '', 0, false, 'T', 'M');
                }
                }


                In my foreach( $nodes ... ) I added the $pdf->setPageNumber($page)
                This needs to be after the addPage. Because else, the footer will receive the number of the previous node.



                $pdf->AddPage($orientation, 'A4', FALSE, TRUE);
                $pdf->setPageNumber($page);


                this can dan be done for all the custom changes you want to have on header or footer







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 22 '18 at 7:28

























                answered Nov 22 '18 at 6:01









                drupalteamreworkdrupalteamrework

                12




                12






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406300%2ftcpdf-add-custom-author-or-page-to-footer-in-multiple-pages-author-page-can-be%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    MongoDB - Not Authorized To Execute Command

                    How to fix TextFormField cause rebuild widget in Flutter

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith