1

When I save a webpage with Safari's > File > Export as PDF...
Safari renders a long PDF in several (long) pages.

Here a screenshot of Preview's Crop Inspector, 200 inch seems to be the height values for each page.
Sometimes have over 10 pages because the webpages get pretty long with +100 comments. enter image description here enter image description here

So now I want to crop, tile or posterize these long pages into normal height.
I want to read them in portrait orientation on on old iPad 2 which has a screen resolution of 768px x 1024px.
The PDF I saved with Safari has already the 768px width because I used the Responsive Design Mode

I tried following tools to crop / tile / posterize the long pages:

  • ADOBE ACROBRAT PRO DC
    Print > Page Sizing & Handling > Poster > Print
    ! The app crashes

  • BRISS
    Never been able to get the crop arguments to work from the command line
    Auto cropping to a certain height does not work, even not in GUI mode

  • PDFTILECUT
    Seems to work but can't set the margins to zero, get rid of the trim marks and set the -tile-size value correctly

  • PDFPOSTER
    Error in the Terminal
    pdfposter: error: The input-file is either currupt or no PDF at all: Invalid Elementary Object starting with b'b' @7: b'3\n%\xc4\xe5\xf2\xe5\xeb\xa7\xf3\xa0\xd0\xc4\xc6\n3 0 obj\n<< /Filter /FlateDecode /Length 19229 >>\nstream\nx\x01\xd5\xbdi\x97\x1c\xc7\x95'

I don't get it, the webpage is saved to PDF by Safari and corrupt?

  • UPDATE 1: I managed something in PDFPOSTER, after "repairing" the PDF
    I have set the height of the --poster-size BOX to something really long: 100000pt
    pdfposter -v -m 768x1024pt -p 768x100000pt in.pdf out.pdf

That works for both pages, one after the other, but I can’t find a solution to set the Y coordinates of each page to 0 The pages always seem to start from the bottom of the poster size, leaving space at the top..

  • UPDATE 2: attached a few pictures as why Safari > File > Print is NOT an option for me.
  1. It leaves me with borders unable to remove
  2. Dark Mode is not applied
  3. Responsive layouts are not applied

enter image description here enter image description here enter image description here

  • UPDATE 3: The last days I tried out libraries, toolkits, bindings, command line tools, modules, recipes ecc. like a mad man, but today I finally found my peace with PYPDF
    Now that I played around long enough with this Cropping and Transforming example I am confident I can do what I want.

Basically with PYPDF you define:
reader = PdfReader('mypdf.pdf')
writer = PdfWriter()
I than loop over the pages page_x = reader.pages[i] from the input file, set mediaboxes for each "new" page and add it to the writer writer.add_page(page_x)
Finally write out with writer.write()

Hyperlinks remain intact! 🤘

1
  • 1
    Save the PDF from the print menu instead. That will place it on pages.
    – benwiggy
    Jan 28, 2023 at 15:02

2 Answers 2

2
+50

When I save a webpage with Safari's → File → Export as PDF... Safari renders a long PDF in several (long) pages.

This is expected behavior. A webpage is not a printed page. As you've found, it can be 200 inches or more. As stated in the comments, the correct action here would have been to utilize Print to PDF so the pagination would be the standard US Letter size (8.5"x11"). The print engine would have automatically handled page margins, header, footer, gutter, etc. without you having to manually do it.

So, how do we fix this?

So now I want to crop, tile or posterize these long pages into normal height.

Option 1: Print to PDF (again)

Using Adobe Acrobat or Preview, print the image to PDF using the standard settings. This should paginate it correctly though it's impossible to guess where the page breaks would end up now.

Option 2, Part I: Split the image into multiple files

I want to read them in portrait orientation on on old iPad 2 which has a screen resolution of 768px x 1024px...The PDF I saved with Safari has already the 768px width because I used the Responsive Design Mode

For this task, we're going to use a (free) tool called GraphicsMagick. It's available via MacPorts, Homebrew, and direct download.

We are going to "split" the image using the convert command with the crop and adjoin operators:

First, convert the PDF to an image. This is necessary because PDFs do not "break" easily. For this I selected a PNG:

% gm convert input.pdf output.png

Next, crop the image by the desired (calculated) size:

gm convert -crop 768x990 input.pdf +adjoin output%04d.pdf 

The output file output%04d.pdf uses a C++ printf style %d output format. Simply put, it uses a signed four digit integer with leading zeros in the filename. Example output0001.pdf. This will create as many individual pages as necessary.

Please note: Since it's not clear what the page margins were, I am using the raw values of US Letter or 8.5 inches wide and 11 inches long. With the resolutions you used of 768px wide, this calculates to about 90-ish DPI; 72 DPI is the norm for a printed page whether on paper or viewing on an iPad. The length value of 990px is calculated by multiplying 90DPI by 11 inches.

You might have to adjust to fit your margins. If you do, remember to subtract the left and right margins from 8.5 then multiply by the DPI. So, if your page has ½ inch margins all around, the formula to calculate crop size will be: 8.5 - (2*0.5) * 72. It will be the same for the length except you'll substitute 11 for the 8.5.

Part II: Recombine the pages into a single PDF

Now that we have all the individual pages created, we can recombine them into a single PDF file. You can use either of two tools that you can use to accomplish this: PDFtk or PDFBox. Both are available on MacPorts, but Homebrew doesn't have PDFBox. You'll need to download it directly from GitHub

  • PDFtk:

    % pdftk *.pdf newDocument.pdf
    
  • PDFBox:

    % java -jar pdfbox-app-2.0.21.jar PDFMerger (output0001.pdf output0002.pdf...output000N.pdf) newDocument.pdf
    

(PDFTk seems easier to use, but I've found the output "better" with PDFBox. YMMV)

18
  • US Letter size or A4 depending on print settings
    – Gilby
    Jan 31, 2023 at 7:00
  • Option 1 with Preview doesn't split it. Is that because it was a pdf containing an image?
    – Gilby
    Jan 31, 2023 at 7:08
  • It’s possible it won’t print. I”ve never tried printing something that large. That said, I’ve printed large images where it automatically split the image so I’m not sure what’s going on there.
    – Allan
    Jan 31, 2023 at 13:58
  • Did you attempt option 2?
    – Allan
    Jan 31, 2023 at 13:58
  • I tested this on my Mac and found that you must convert the PDF to an image first to make this work. Once you have the image "split" to your specifications, you can convert it back to a PDF using the reverse of the command gm convert input.png output.pdf
    – Allan
    Jan 31, 2023 at 17:15
0

On iPad you can create a screenshot with CMD-Shift-3. What many people do not know is that you can actually create a screenshot not only of the visible screen but of the whole webpage. For this, use the same keyboard combination and then tap on the little preview window that appears at the bottom left. Then, at the top, select „Full Page“.

enter image description here

3
  • Cool, it does not work for me though... when I click on the thumbnail in the bottom left I just get a Finder Preview, without these options.
    – FFish
    Feb 1, 2023 at 6:43
  • @FFish On occasion, it also did not work for me. I have no idea why. Recently it always worked. You can try to create a screenshot be pressing the power button and the volume up button at the same time when you look at a webpage in Safari.
    – John
    Feb 1, 2023 at 21:58
  • Ah but you are saying on iOS? OK I see now "On iPad". My iPad is 15 years old LOL
    – FFish
    Feb 2, 2023 at 17:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .