I would like to change page orientation for just specific few pages in my PDF document. The PDF document is created out of html template using html2pdf. It goes like this: if the content of the page (typically a table) is too wide to be properly shown in portrait orientation, show page in landscape.
Following the hint in [how to rotate pages into landscape and page content should be in portrait iTextpdf][1]
[1]: how to rotate pages into landscape and page content should be in portrait iTextpdf I have created my custom tag and TagWorker.
public class LandscapeTagWorker extends BodyTagWorker {
public LandscapeTagWorker(IElementNode element, ProcessorContext context) {
super(element, context);
}
/**
* @param element
* @param context
* @see com.itextpdf.html2pdf.attach.ITagWorker#processEnd(com.itextpdf.html2pdf.html.node.IElementNode, com.itextpdf.html2pdf.attach.ProcessorContext)
*/
@Override
public void processEnd(IElementNode element, ProcessorContext context) {
super.processEnd(element, context);
String value = element.getAttribute("value");
if ( "true".equalsIgnoreCase(value) ) {
PdfDocument doc = context.getPdfDocument();
doc.setDefaultPageSize(doc.getDefaultPageSize().rotate());
}
}
}
The problems are: first, this does nothing. Even if it would work, I do not want to change the orientation of the whole document, just orientation of the pages where the content of the <landscape value="true">
is found.
How can I extract the current page(s) out of ProcessorContext/PdfDocument and how to change page orientation of only those pages?