Split A4 pages in a PDF file to A5 pages [duplicate]
Possible Duplicate:
Split A4 PDF page into two A5 and back again
I have A4 pages in a PDF file like the following:
How could I split each A4 pages to two A5 pages?
Try with:
- Briss (freeware) Easy to use, only drag and drop rectangles to create new pages.
- A-PDF Page Cut (shareware) Don't know... it adds watermark to new pages.
If this function is not already performed by some existing PDF tool, then here is a high-level brainstorm of how I would approach the problem with CAM::PDF. I'm not sure if it would work.
- duplicate the page
- rotate the content
- set the crop box for each of the pages to just the half of interest
Off the top of my head I don't know if the extra out-of-cropbox content would be invisible, or if it would affect the render...
UPDATE: I implemented a mostly-working, simplistic solution, as follows. It duplicates the page in question, rotates both copies, and sets the CropBox on each, choosing the left half for the first page and the right half of the second page. You may not need the rotation in your case, not sure.
#!/usr/bin/perl
use strict;
use warnings;
use CAM::PDF;
my $pdffile = 't/sample1.pdf';
my $pdfout = 'temp2.pdf';
my $pagenum = 1;
my $pdf = CAM::PDF->new($pdffile) or die $CAM::PDF::errstr;
my ($objnum, $gennum) = $pdf->getPageObjnum($pagenum);
my $pagedict = $pdf->getPage($pagenum);
$pagedict->{Rotate} = CAM::PDF::Node->new('number', 90);
my $oldbox = $pdf->getValue($pagedict->{CropBox} || $pagedict->{MediaBox});
my @box = map {$pdf->getValue($_)} @{$oldbox};
$pagedict->{CropBox} = CAM::PDF::Node->new('array', [
map {CAM::PDF::Node->new('number', $_)} $box[0], $box[1], $box[2], ($box[3]+$box[1])/2
]);
my $duplicate = CAM::PDF->new($pdffile) or die $CAM::PDF::errstr;
$duplicate->extractPages($pagenum);
$pdf->appendPDF($duplicate); # appends at end instead of inserting
$pagedict = $pdf->getPage($pdf->numPages());
$pagedict->{Rotate} = CAM::PDF::Node->new('number', 90);
$pagedict->{CropBox} = CAM::PDF::Node->new('array', [
map {CAM::PDF::Node->new('number', $_)} $box[0], ($box[3]+$box[1])/2, $box[2], $box[3]
]);
if ($objnum) {
$pdf->{changes}->{$objnum} = 1;
}
$pdf->cleanoutput($pdfout);
The hard way: use ConTeXt/LuaTeX to rearrange the pages.
The reasonable way: a combination of pdf shuffler, PDFjam and or PDF Split & Merge should do the job.
精彩评论