Output graph to a two page PDF

↘锁芯ラ 提交于 2021-02-20 10:07:43

问题


I am doing a forest plot and want to save it to a PDF file.

My forest plot is oversize (8in*20in). It can fit in a one page PDF like this:

  dev.print(pdf, file="C:\\Work\\plot.pdf", width=8, height=20);

But then it is too long: When I print this PDF on a A4 paper, it has to be shrinked to fit the paper.

So I want to save it to a two-page PDF file (from R). Ps: it is not a question about how to set the printer.

How to do this?


回答1:


So, you are able to generate an 8in x 20in == 203.2mm x 508mm == 576pt x 1440pt sized PDF showing a plot.

It is not entirely clear to me from your question what exactly you want:

  1. Generate the PDF plot so that it is divided into two different pages from the beginning?
  2. Take the PDF as is and during the print job setup find these settings which would print it onto two different pages by posterizing the original page?
  3. Post-process the PDF that you created to posterize it and create a 2-page output PDF (which you can then print)?

Assuming '1.': generate PDF plot distributed over 2 pages

Sorry, I cannot help here...

Assuming '2.': print setup to print 1 PDF page on 2 sheets of paper

If you print a PDF from Adobe Acrobat or from Adobe Reader, then you'll find a setting in the print dialog named "Poster". Here you can select to print one PDF page across multiple pieces of paper. (It also lets you select if you want some overlap from piece to piece, and if you want to add cut marks and the like to the printouts).

Assuming '3.': post-process 1 PDF page to stretch over 2 A4 pages

  1. MuPDF is a lightweight PDF (and other document formats) viewer, made by the same company that also maintains Ghostscript. MuPDF ships with an additional command line utility, mutool.

    Its subcommand poster can divide PDF pages into smaller tiles and 'posterize' them. So this command will achieve what you want:

    mutool poster -x 1 -y 2 input.pdf output.pdf
    

    The output.pdf will be divided into 1 part (i.e. not divided) in x-, and into 2 equal parts in y-direction. (You could divide it into any other number of segments if you wanted). So output.pdf will have two pages, each sized 8in x 10in. A4 paper is sized 8.26in x 11.69in when measured in Inches.

    When printing these, you'll still need to enable the Print to fit Page Size checkbox in the print dialog if you want to make best use of the A4 page size.

  2. Ghostscript is a command line tool that can (amongst many other functions) be used to process PDF files (PDF in, modified PDF out). It can be (ab)used to cut PDF pages into halfs.

    Here are a few previous StackOverflow answers which describe how to do it. You'll need to adapt some parameters to your specific size(s), but the principles should be clear from those examples (even though some of these split pages into left and right halves, not top/bottom as you may require):

    • Linux-based tool to chop PDFs into multiple pages (SuperUser)
    • Freeware to split a pdf's pages down the middle? (SuperUser)
    • Convert PDF 2 sides per page to 1 side per page (SuperUser)
    • How can I split a PDF's pages down the middle? (SuperUser)
    • Cropping a PDF using Ghostscript 9.01 (StackOverflow)
    • PDF - Remove White Margins (StackOverflow)
    • Split one PDF page into two (StackOverflow)

    The method described there is more tedious and not as straight-forward as with the mutool poster method.




回答2:


Maybe not the answer you are looking for but you could print it in another vectorial format (e.g. svg) and then export it as pdf on two pages with a (vectorial) image editor.

Edit: If ploting in pdf works well despite the big size of the graph there are also tools to split pdf pages. You can find some directions here: https://superuser.com/questions/437148/how-to-split-a-pdf-onto-multiple-pages-on-command-line

Windows equivalent of pdfposter could be Rasterbator or PosteRazor, for example.



来源:https://stackoverflow.com/questions/29496779/output-graph-to-a-two-page-pdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!