Scrolling \ DropDown Components to PDF using iText
let me explain what i actually want:
i have managed to successfully export my JPanel along with all its components to a PDF using iText's l开发者_高级运维ibrary.
However i have run into a bit of a problem. I would like to export a JScrollPane to PDF using iText... is this even possible? well it is, technically... cause it works for me.. however my JScrollPane actually scrolls... so how can i export the JScrollPane to a PDF keeping the JScrollPane's properties. i know that pdf documents do support this as i have seen it.
Please help... i'm not sure if you require any code actually...
the way i've been doing it is converting the JPanel to a graphic then exporting that to pdf
The only thing that scrolls within a pdf PDF is a list field. If you can shoehorn the contents of your JScrollPane into string list options, great. If not... not so great.
Embedded Flash
That means converting your JScrollPanel to PDF and converting that PDF to Flash (with a scroll bar) and embedding that flash in your PDF. Ugh, but it should work.
Hey!
Pushbuttons and JavaScript
You can set the appearance of a button to be a template (an "icon"). You can adjust the scaling and alignment (both vertical and horizontal) of the image within the bounds of the button. If you can adjust this alignment in javascript, you can simulate scroll bars. YEP!
var fld = this.getField("myButtonField");
fld.buttonAlignX += foo; // a percentage
fld.buttonAlignY -= bar; // ditto
I suggest using PushbuttonField
to build all this stuff, one for each control and one for the JScrollPanel. You set the panel's scroll behavior to "never" and the initial icon alignment to be something reasonable ("top" I'd imagine).
PushbuttonField panelButton = new PushbuttonField( writer, rect, "panelHackButton" );
panelButton.setTemplate( jpanelTemplate );
panelButton.setLayout( PushbuttonField.LAYOUT_ICON_ONLY );
panelButton.setScaleIcon( PushbuttonField.SCALE_ICON_NEVER );
panelButton.setIconVerticalAdjustment( 1f );
PdfFormField pdfFld = panelButton.getField();
writer.addAnnotation( pdfFld ); // added to the current page
PushbuttonField scrollUpButton = new PushbuttonField( writer, otherRect, "scrollUpButt" ); // he said "butt"
scrollUpButton.setLayout( PushbuttonField.LAYOUT_LABEL_ONLY );
scrollUpButton.setText( "Up" );
pdfFld = scrollupButton.getField();
pdfFld.setAdditionalActions( PdfFormField.AA_DOWN, PdfAction.javaScript( script, writer ) );
writer.addAnnotation( pdfFld );
If you wanted to get REALLY fancy, you could even do proportional sliders between the up and down arrows with more script and buttonAlignX and buttonAlignY. I don't think you could support dragging.
Ugly scaling
A less visually appealing alternative that would preserve all your data would be to draw the contents of your scroll panel at full size, unclipped, into a template. You'd then scale that template down proportionately to fit the available area on the original dialog. Folks might have to zoom in to see anything, but then they could see everything. No funky script magic, just a funky looking PDF-dialog-thingy.
精彩评论