Best way to generate A3 from A4 #2121
Replies: 4 comments 10 replies
-
There isn't a good built-in way for this at the moment. Your best bet is probably staying completely in A4 in Typst, and then converting the output to A3 with another tool. |
Beta Was this translation helpful? Give feedback.
-
This is probably not something You can great N-up layouts like this for printing with a wide variety of tools that don't involve a full TeXLaTeX installation (or any at all). Try |
Beta Was this translation helpful? Give feedback.
-
So, I'd like to reopen this to report my findings, maybe someone finds them usefull:
let page1 = &doc.pages[0];
let page2 = &doc.pages[1];
let frame1 = &page1.frame;
let frame2 = &page2.frame;
let xdim = frame1.size().x;
let newsize = typst::layout::Size { x: 2.0 * xdim, y: frame1.size().y };
let mut frame = typst::layout::Frame::new(newsize, frame1.kind());
frame.set_baseline(frame1.baseline());
for item1 in frame1.items() {
let it = item1.clone();
frame.push(it.0, it.1);
}
for item2 in frame2.items() {
let item = item2.1.clone();
let point = item2.0;
let newpoint = typst::layout::Point { x: point.x xdim, y: point.y };
frame.push(newpoint, item);
}
let page = typst::layout::Page {
frame,
numbering: None,
number: 0
};
let v = vec![page];
doc.introspector.rebuild(&v);
doc.pages = v; This merges two A4 pages into one A3 page, but the rest is just a bit of bookkeeping I'll have to write (I need to go 4 A4 -> 2 A3 and similar), and then after all merge it into one large A3 document. Note that some choices here are specific to my usecase (e.e. reusing the old As far as I can tell though, this does the job very properly, but if anyone spots something I might have missed, I'd be grateful for any hint :) Otherwise, I hope this helps someone somewhere somehow! (e) I'll investigate if https://docs.rs/typst/latest/typst/layout/struct.Frame.html#method.push_frame is more efficient (since I can only clone the individual items, this method might just transfer ownership), but that's just a performance optimization after al... |
Beta Was this translation helpful? Give feedback.
-
So here's my final version (error handling removed since it's pretty specific). It's A LOT faster than going through png :) pub fn merge_frames(frame1: Option<Frame>, frame2: Frame) -> Frame {
let xdim = frame2.size().x;
let ydim = frame2.size().y;
let newsize = Size::new(2.0 * xdim, ydim);
let mut newframe = Frame::new(newsize, frame2.kind());
newframe.set_baseline(frame2.baseline());
if let Some(frame1) = frame1 {
newframe.push_frame(Point::zero(), frame1);
}
newframe.push_frame(Point::new(xdim, Abs::zero()), frame2);
newframe
}
// Combines 2 pages of the document into one page of double size. Returns an
// error if the document does not have 3 or 4 pages.
pub fn create_a3(mut doc: Document) -> Document {
let mut pages = doc.pages;
let len = pages.len();
let page1 = match len {
n @ 0..=2 => panic!("Can't merge"),
3 => None,
4 => pages.pop(),
n @ 5.. => panic!("Can't merge"),
};
let [page2, page3, page4] = pages.try_into().unwrap();
let frame1 = merge_frames(page1.map(|p| p.frame), page2.frame);
let frame2 = merge_frames(Some(page3.frame), page4.frame);
let page1 = Page {
frame: frame1,
numbering: None,
number: 0,
};
let page2 = Page {
frame: frame2,
numbering: None,
number: 0,
};
let v = vec![page1, page2];
doc.introspector.rebuild(&v);
doc.pages = v;
Ok(doc)
} |
Beta Was this translation helpful? Give feedback.
-
I'm creating documents of the format A4 for visual consumption, but I need them on A3 for printing. Note that this doesn't mean upscaling them, but putting 4 A4 documents in the right order on both sides of a A3 document (2 each side). I'm generating the documents programatically from templates, and I really need to make sure that the A3 is exactly occupied by the A4 documents. Moreover, I'd prefer if it was easy to keep those documents in sync...
Up to now, I've been using latex for this, and producing the A4 was really just including the A4 pdf's in the right order (using the package
pdfpages
). I want to switch to typst, which can't include pdf's right now. So, what's my best option here? I do of course know thecolumns
function, but I do foresee problems with the page headers/footers and page numbers at least...Thanks for any pointers! Let me know if anything was unclear here :)
Beta Was this translation helpful? Give feedback.
All reactions