How to Include PDF Files in LaTeX Documents | Baeldung on Computer Science (2024)

Last updated: March 18, 2024

How to Include PDF Files in LaTeX Documents | Baeldung on Computer Science (1)

Written by: baeldung

How to Include PDF Files in LaTeX Documents | Baeldung on Computer Science (2)

Reviewed by: Milos Simic

  • Latex

    1. Introduction

    In this tutorial, we’ll explain how to include .pdf files in LaTeX documents.

    We can include .pdf figures using the graphicx package and the \includegraphics command. However, sometimes, we need to include a range of pages from an existing PDF in a new LaTeX document.

    2. Package pdfpages

    The package pdfpages offers precisely such functionalities:

    \usepackage{pdfpages}

    It requires the following packages: atbegshi, pdflscape, graphicx, ifthen, and calc. These are available in all standard LaTeX distributions.

    We also require a recent version of pdftex.def.

    To use it, we declare pdfpages in the preamble, and thus any missing packages are automatically loaded so we don’t need to load them explicitly.

    The package pdfpages runs on pdflatex, xelatex, and lualatex engines.

    3. The \includepdf Command

    The package offers the command \includepdf for including pages from an existing PDF. Its syntax is:

    \includepdf[options]{filename}

    There, options is a comma-separated list of key=value pairs, each denoting a specific option of the command. The filename shouldn’t have blank spaces, otherwise, the inclusion will fail.

    We explain the main options to \includepdf in the following subsections.

    3.1. Option pages

    The option pages specifies which pages to include. We can specify them as a list, e.g., pages={3,4,5, 7, 11}.

    However, consecutive pages can be specified by their start and end: pages={3-5, 7, 11}.

    To insert an empty page, we add {}, e.g., pages={3-5, 7, {}, 11}. That will insert a blank page between the seventh and the eleventh pages of the specified PDF.

    Let’s say that we have a PDF named alice_in_wonderland.pdf and that we want to include its third and fourth pages:

    \documentclass{article}\usepackage{lipsum}\usepackage{pdfpages}\begin{document}{\raggedright\lipsum[1]\includepdf[pages={3-4}]{alice_in_wonderland.pdf}\lipsum[2]}\end{document}

    The lipsum package generates a pseudo-Latin text for test purposes. We can see the output includes two pages from alice_in_wonderland.pdf, which we’ve set in a different font to distinguish them from the main text:

    3.2. Options landscape and angle

    To rotate the sheet of paper by 90º, we set landscape=true. This only affects the sheet and not the inserted pages.

    To rotate the included pages, we use the option angle. For instance, rotating by 45º:

    \includepdf[angle=45,pages={3}]{alice_in_wonderland.pdf}

    gives us this result:

    The default values are landscape=false and angle=0.

    3.3. Options nup, delta, scale, and offset

    The option nup lets us place multiple pages on each sheet of paper. Its syntax is: nup=xnupxynup. Here, xnup and ynup designate the number of inserted pages in the horizontal and vertical directions on each sheet of paper. The default is nup=1×1, i.e, an included page per sheet.

    On the other hand, delta controls the horizontal and vertical spacing between the inserted pages (when including multiple pages per sheet). The argument is two-dimensional:

    delta = xdelta ydelta

    For example, delta=-1.75in -2.0in, reduces the space between the inserted pages by 1.75in and 2in in the horizontal and vertical directions.

    The option offset lets us translate the origin of the inserted pages. It’s a two-dimensional option, so we set the offset by specifying the horizontal and vertical offsets: offset=xoffset yoffset. We can make them positive or negative. The default offsets are zeroes.

    Finally, scale lets us resize the pages we include.

    Here’s an example of using all four options:

    \lipsum[1-2]\includepdf[scale=0.65, nup=3x2, pages={3-8}, offset=-0.25in -0.25in, delta=-1.75in -2.00in]{alice_in_wonderland.pdf}\lipsum[3]

    Here’s the result we get:

    The nup=3×2 specification means that we would like the alice_in_wonderland.pdf pages to be arranged in 3 columns of 2 rows. We scale the included pages by 65% and set the offsets from the edgesof the page to -0.25in. Further, we adjust the spaces between the included pages. Usually, we’ll need some experimentation to set the scale, offset, and delta correctly.

    3.4. Option reflect

    This option lets us reflect the included pages. To do that, we set reflect=true. The default is reflect=false.

    Here’s an example:

    \lipsum[1]\includepdf[scale=0.65,nup=2x2, reflect,pages={3-6}, offset=-0.25in -0.25in, delta=-2.0in -3.00in]{alice_in_wonderland.pdf}\lipsum[2]

    This is the result:

    As we see, the inserted pages were reflected around their middles.

    4. Coloring the Included Pages

    Sometimes, we want to color the included pages to make them appear different. We can do that by using \pagecolor{}.

    However, the \pagecolor{<color>} command must come before the \usepackage{pdfpages} declaration for this to work:

    \documentclass{article}\usepackage{lipsum}\usepackage{xcolor}\pagecolor{white}\usepackage{pdfpages}\begin{document}{\raggedright\lipsum[2]\newpage{\pagecolor{olive}\includepdf[pages={3}]{alice_in_wonderland.pdf}}\pagecolor{white}\lipsum[3]}\end{document}

    Here’s the output:

    We can change the color later (as we did in the example, from white to olive), but the first \pagecolor command must come before \usepackage{pdfpages}.

    5. Conclusion

    In this article, we talked about importing pages from an existing .pdf file into a LaTeX document. We used the pdfpages package for this purpose. It can include multiple pages and arrange them in various ways.

    How to Include PDF Files in LaTeX Documents | Baeldung on Computer Science (2024)
    Top Articles
    75th Republic Day of India 2024: History, Theme, Significance  - Leverage Edu
    How to use two-factor authentication (2FA) on X
    Hamlett Dobson Funeral Home Obituaries Kingsport Tn
    Busted Newspaper Pulaski County
    Trivago Manhattan
    Oklahoma Dam Generation Schedule
    Feet.girl01
    Fresenius Medical Care to launch 5008 dialysis machine: improved patients` quality of life and efficient use of resources
    Goodwill letter success! **UPDATE** new scores: EX 782; EQ 764; TU 769 no more baddies!
    Jikatabi Thothub
    Cpcon Protection Priority Focus
    Dvax Message Board
    Rice explains personal reason for subdued goal celebration against Ireland
    Clarita Amish Auction 2023
    Bank Of America Operating Hours Today
    Entegra Forum
    Ropro Cloud Play
    6023445010
    Justine Waddell talks about a season of screenings MELODIA!
    洗面台用 アクセサリー セットの商品検索結果 | メチャ買いたい.com
    Sloansmoans Bio
    Perse03_
    COUNTRY VOL 1 EICHBAUM COLLECTION (2024) WEB [FLAC] 16BITS 44 1KHZ
    Skip The Games Lawton Oklahoma
    Seattle Clipper Vacations Ferry Terminal Amtrak
    Watch The Lovely Bones Online Free 123Movies
    What tools do you recommend for emceeing?
    Gopher Hockey Forum
    Hca Florida Middleburg Emergency Reviews
    Abby's Caribbean Cafe
    Cia Decrypter
    Antique Wedding Favors
    Nickelodeon Home Media
    Lo que necesitas saber antes de desrizarte el cabello
    Camwhor*s Bypass 2022
    Help with Finding Parts for Your Vehicle
    EU emissions allowance prices in the context of the ECB’s climate change action plan
    "Lebst du noch?" Roma organisieren Hilfe für die Ukraine – DW – 05.03.2022
    Abingdon Avon Skyward
    Papa Louie When Pizzas Attack Unblocked
    Craigslist Pets Inland Empire
    Pawn Shops In Sylva Nc
    Personapay/Glens Falls Hospital
    The forgotten history of cats in the navy
    Indian River County FL.
    Is The Rubber Ducks Game Cancelled Today
    18006548818
    Skip The Games Mil
    Wat is een Microsoft Tenant
    Four Embarcadero Center - Lot #77
    Apartments for Rent in Buellton, CA - Home Rentals | realtor.com®
    Latest Posts
    Article information

    Author: The Hon. Margery Christiansen

    Last Updated:

    Views: 5844

    Rating: 5 / 5 (70 voted)

    Reviews: 93% of readers found this page helpful

    Author information

    Name: The Hon. Margery Christiansen

    Birthday: 2000-07-07

    Address: 5050 Breitenberg Knoll, New Robert, MI 45409

    Phone: +2556892639372

    Job: Investor Mining Engineer

    Hobby: Sketching, Cosplaying, Glassblowing, Genealogy, Crocheting, Archery, Skateboarding

    Introduction: My name is The Hon. Margery Christiansen, I am a bright, adorable, precious, inexpensive, gorgeous, comfortable, happy person who loves writing and wants to share my knowledge and understanding with you.