TCPDF - Having footer/header on certain pages only - tcpdf

I want to place the footer section on every page of my document except the first one.
I created my custom footer by extending the TCPDF class and overriding its footer method.
Then based on the documentation and using below example I understand I should use SetPrintHeader and SetPrintFooter methods:
http://www.tcpdf.org/examples/example_002.phps
// Page one
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->AddPage();
// Page two and on ..
$pdf->SetPrintHeader(true);
$pdf->SetPrintFooter(true);
$pdf->AddPage();
However, the above does not prevent the footer/header from being printed at all!
What am i doing wrong here ?
Thanks a million in advance !!

I think that
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
prints or hides the header and footer globally so if you do
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->AddPage();
// Page two and on ..
$pdf->SetPrintHeader(true);
$pdf->SetPrintFooter(true);
You are just telling TCPDF to print the header and footer (The last two statements).
What you should do is, in the header and footer function, print things conditionally based on the page you are in. Something like (not tested, i haven't my PHP IDE right now)
function Header(){
$pageN = PageNo();
if($pageN % 2 === 0){
//if page is 2/4/6... don't print anything
return;
}else{
//do your stuff
}

Header can be controlled by modifying the function startPage in tcpdf.php
In this example, I need headers from page 2 only.
// print page header
if ($this->numpages > 1) {
$this->setHeader();
}

Related

Overleaf - Set header for only first page (and not all pages)

I only want to set a header for only my first page. This is within overleaf.
My Attempt:
\fancyhead[L]{}
\fancyhead[R]{ \includegraphics[width=4cm]{logo.png}}
\renewcommand{\headrulewidth}{0pt}
This issue is that this sets the header for all pages.
How do I set the header to only be applicable for the first page and not all the pages?
Define a custom style. Here with the name firstpage:
\fancypagestyle{firstpage}
{
\fancyhead[L]{}
\fancyhead[R]{ \includegraphics[width=4cm]{logo.png}}
}
Then use it on desired page:
\thispagestyle{firstpage}

Footer on all page except last one

Hi how can I prepare rtf file that will display footer on each page except the last one. I've find only this option
\footer Footer on all pages
\footerf Footer for the first page only
\footerl Footer on left pages only
\footerr Footer on right pages only
Thanks for any answers.
Footers are reset by section breaks, so you can define your footer using \footer on the first page and then use \sect\sectd on the last page to clear it, and it will appear on all pages except the last.

pdf.js: Changing current page number programmatically

With pdf.js is there a way to programmatically change the current page of a PDF being viewed? For example, a call to change the current page to page 5.
(I know that I can initially set the page by specifying the page number in the URL, but I want to change it programmatically after it has been opened.)
PDFViewerApplication.pdfViewer.currentPageNumber is a getter and setter. Examples:
// Go to page 5
PDFViewerApplication.pdfViewer.currentPageNumber = 5;
// Move two pages forward
PDFViewerApplication.pdfViewer.currentPageNumber += 2;

How to make persistent header that retains form content with jqm listviews

I want to create a header containing an input field that persists across sublists, retaining the content the user has typed in so far.
If I just use standard listviews, the header scrolls away on sublists.
I've tried a number of things, including detaching the header and re-attaching it to the event supplied by pagebeforeshow, and that sort of works except that I can't get the content below the header to reformat:
$('div.ui-page').live('pagebeforeshow', function(event, ui) {
// Remove any header that's already there, as there will be for a sublist view
$(event.currentTarget).find(".ui-header").not("#myheader").remove();
// Add my header
var header = $('#myheader');
header.detach();
header.prependTo(event.currentTarget);
}
Any ideas? Thanks!
Hmm.. removing data-position="fixed" from the header seemed to do the trick. Now things space correctly..

The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml"

I know there are a few questions that have been answered but I didn't find something specific to my case.
I'm using the mobile capabilities of MVC4. So I created a _layout.mobile.cshtml and the corresponding views.
The error above happens when I go in with a mobile device. As you can see, it is trying to display the regular _layout.cshtml instead of the _layout.mobile.cshtml. So I'm assuming it is also trying to display the view (say Index.mobile.cshtm) which doesn't have the section in question. Basically it is mixing the regular layout with the mobile views.
This doesn't happen all the time. If I recycle the pool it works again for a while and then all of the sudden it goes back to having the error and it will continue until I recycle the pool again.
Has anyone seen this problem before that can shed some light?
Thanks
John
In the _ViewStart.cshtml available under the Views folder, change the Layout value to your custom layout. I think this may help.. (Make sure that you are returning View instead of partial view)
for example
#{
Layout = "~/Views/Shared/_layout.mobile.cshtml";
}
In case if you want to change the layout for a specific page you can explicitly define it at the top of the page as a page directive.
in the index.cshtml there is a section being called defined in the original layout file "_LayoutHome.cshtml" that is not defined in the new bootstrap layout.
specifically: #RenderSection("featured", required: false)
So the solution is to either add this section to the new layout (look for it in the original layout and paste it) or simply delete it from the index.cshtml.
I had also face the same problem I removed
#section featured {
From View
Another way to do this is to use a conditional block in your _ViewStart.cshtml page. For example, you may have two layouts depending on the device regular user. Using pseudo-code for the reading of the device/browser type bit, it would look something like this:
#{
if(userIsMobile)
{
Layout = "~/Views/Shared/_MobileLayout.cshtml";
}
else
{
Layout = "~/Views/Shared/_Layout.cshtml";
}
}
I have used this to display or hide sections or menu items as needed for different classes of user; it should work as well for device-specific layouts.
Joey Morgan

Resources