How to correctly set a fancy header and footer in a included pdf, which contains many pages? - header

Last time I tried to add fancy header and footer in my document, but I'm not happy of it's result. How to correctly set a fancy header and footer in a included pdf, which contains many pages?
My goal, which I want achieve, is: If the number of page is odd, I want to have a header and the number of page on the left side of page, otherwise I want to have it on the right.
Here is my base code:
\documentclass[oneside, a4paper, 12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{polski}
\usepackage{pdfpages}
\usepackage{changepage}
\usepackage{fancyhdr}
\usepackage[right=2.7cm,left=3.5cm, top=2.7cm, bottom=2.5cm,includehead]{geometry}
\strictpagecheck
\begin{document}
%\setcounter{page}{18}
\includepdf[pages=-,pagecommand={
\ifoddpage
\pagestyle{fancy} \fancyhf{}
\fancyhead[L]{Test of left header}
\fancyfoot[L]{\thepage}
\else
\fancyhead[R]{Test of right footer}
\fancyfoot[R]{\thepage}
\fi}]{scenariusz_wersja_do_edycji.pdf}
\end{document}
I would be glad if somebody knows the solution, because i need it necessarily for the BA thesis!

If you use a twosideed documentclass, then you can let fancyhdr automatically place your header/page number on even/odd pages:
\documentclass[twoside, a4paper, 12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{polski}
\usepackage{pdfpages}
\usepackage{changepage}
\usepackage{fancyhdr}
\usepackage[right=2.7cm,left=3.5cm, top=2.7cm, bottom=2.5cm,includehead]{geometry}
\strictpagecheck
\setlength{\headheight}{15pt}
\fancypagestyle{mystyle}{%
\fancyhf{}
\fancyhead[LO,RE]{Some header}
\fancyfoot[LO,RE]{\thepage}
}
\begin{document}
%\setcounter{page}{18}
\includepdf[pages=-,pagecommand={
\thispagestyle{mystyle}
}]{example-image-duck}
\end{document}

Related

Why is the title page running over the end of the document?

I am attempting to create a paper with the elsarticle.cls class, and have it be 2 columns. There are O(100) authors on the paper. For some reason, the author list spills over the bottom margin rather than continuing onto the next page, so the abstract never appears in the document. Below is a minimal working example of this type of problem.
\documentclass[english,10pt,final,twocolumn]{elsarticle}
\usepackage{lipsum}
%\usepackage{subcaption}
\usepackage{multido}
\begin{document}
\begin{frontmatter}{}
\title{
A minimal working example of an author list erroniously going beyond the bottom of a page in an 2-column Elsevier article.
}
\newcommand*{\UCR}{University of California Riverside, 900 University Avenue, Riverside, CA 92521, USA}
\newcommand*{\UCRindex}{39}
%Here I give myself 1000 times authorship on this paper just to fill up the page
\multido{}{1000}{ \author[toUCR]{S.J.~Paul}}
\address[toUCR]{\UCR}
\begin{abstract}
\lipsum[3]
\end{abstract}
%\date{\today}
\end{frontmatter}{}
\section{Introduction}
\lipsum[2]
\end{document}
This produces the file shown below. How do I fix this?
Rendered document
As a workaround, you could remove the twocolumn class option and manually switch to two column layout after the frontmatter:
\documentclass[english,10pt,final,
%twocolumn
]{elsarticle}
\usepackage{lipsum}
%\usepackage{subcaption}
\usepackage{multido}
\begin{document}
\begin{frontmatter}{}
\title{
A minimal working example of an author list erroniously going beyond the bottom of a page in an 2-column Elsevier article.
}
\newcommand*{\UCR}{University of California Riverside, 900 University Avenue, Riverside, CA 92521, USA}
\newcommand*{\UCRindex}{39}
%Here I give myself 1000 times authorship on this paper just to fill up the page
\multido{}{1000}{ \author[toUCR]{S.J.~Paul}}
\address[toUCR]{\UCR}
\begin{abstract}
\lipsum[3]
\end{abstract}
%\date{\today}
\end{frontmatter}
\twocolumn
\section{Introduction}
\lipsum[2]
\end{document}

Positioning of figures in sections and avoid blank pages with float package

I have the problem that latex creates empty pages while using the float package.
This is the Code:
\section{Sample}
Sample Text.
\section{Title}
\begin {figure}[H]
Insert figure via R-Code.
\captionlistentry{Title Boxplot}
Insert figure via R-Code.
\captionlistentry{Dressiergrad Boxplot}
\end{figure}
\begin{figure}[H]
Insert figure via R-Code.
\captionlistentry{Reckgrad Boxplot}
\end{figure}
So i got 2 Sections "Sample" and "Example ". In Sample there is some text and in Title there are 3 figures. 2 of the figures and the section heading are fitting onto 1 page.
So there should be smth. like that:
Page1: Sample title + text
Page2: Example title + 2 figures
Page3: 1 figure
But Latex makes this:
Page1: Sample title + text
Page2: Empty Page
Page3: Example title + 2 figures
Page4: 1 figure
I'm using documentclass{article}, thanks for helping!
Try removing the [H] option. If the image sizes are little bigger than what can be fit in the same page, LaTeX pushes it to the next page.
As a second option, you can reduce the size of the image a little bit!

XSL / XSL-FO: Different formatting of a block depending on its page position on PDF page

I'm new in this mailing list, so please apologize any of my wrongdoings.
FOP 1.1
Question: Is there any condition to find the position of a text-block in on PDF page.
This is the problem:
I need to change the formatting of a title-block depending on its position on the page.
If the title-block appears somewhere in the (vertical) middle of the page, I want to add a line on top of it.
if the title-block appears at the beginning/top of a page the line must not appear
Does XSL-FO have a way to do that?
From http://lists.w3.org/Archives/Public/www-xsl-fo/2015Sep/0002.html:
I used a white background on the
fo:region-before and a negative margin on the title to 'push' the
'border-before' of the title under the fo:region-before.
This requires that the FO processor supports negative values of
'margin-top', which is allowed but not required (http://www.w3.org/TR/xsl11/#margin-top). It also requires
that the FO processor will 'paint' the fo:region-before after painting
the fo:region-body.

Docx4J: Vertical text frame not exported to PDF

I'm using Docx4J to make an invoice model.
In the left-side of the page, it's usual to show a legal sentence as: Registered company in ... Book ... Page ...
I have inserted this in my template with a Word text frame.
Well, my issue is: when exporting to .docx, this legal text is shown perfect, but when exporting to .pdf, it's shown as an horizontal table under the other data.
The code to export to PDF is:
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setFoDumpFile(foDumpFile);
foSettings.setWmlPackage(template);
fos = new FileOutputStream(new File("/C:/mypath/prueba_OUT.pdf"));
Docx4J.toFO(foSettings, fos, Docx4J.FLAG_EXPORT_PREFER_XSL);
Any help would be very appreciated.
Thanks.
You'd need to extend the PDF via FO code; see further How to correctly position a header image with docx4j?
Float left may or may not be easy; similarly the rotated text.
In general, the way to work on this is to take the FO generated by docx4j, then hand edit it to something which FOP can convert to a PDF you are happy with. If you can do that, then its a matter of modifying docx4j to generate that FO.

How to correctly position a header image with docx4j?

I am trying to convert this Word document with a header showing an image on the right
http://www.filesnack.com/files/cduiejc7
to PDF using this sample code:
https://github.com/plutext/docx4j/blob/master/src/samples/docx4j/org/docx4j/samples/ConvertOutPDF.java
Here's the result:
http://www.filesnack.com/files/ctjs659h
While the Word document has the header image on the right, the converted PDF shows it on the left.
How can I make docx4j to reproduce the original document as PDF?
Your image is positioned relative to a paragraph:
<w:drawing>
<wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251658240" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1" wp14:anchorId="791936E3" wp14:editId="575B92C8">
<wp:simplePos x="0" y="0"/>
<wp:positionH relativeFrom="column">
<wp:posOffset>5317388</wp:posOffset>
</wp:positionH>
<wp:positionV relativeFrom="paragraph">
<wp:posOffset>-325755</wp:posOffset>
</wp:positionV>
docx4j potential to support stuff like that in PDF output is limited by what XSL FO supports. See docx4j's TextBoxTest class for what we can do with text boxes.
Currently, although we can position some textBoxes; we don't do the same for floating images: https://github.com/plutext/docx4j/issues/127
In the meantime, a possible workaround for some cases (eg float right) is to use a table.
Or possibly, you could try putting the image inside a text box!