使用 iText 将 \ DropDown 组件滚动到 PDF

发布于 2024-10-16 04:52:28 字数 338 浏览 4 评论 0原文

让我解释一下我真正想要的:

我已经成功使用 iText 库将 JPanel 及其所有组件导出到 PDF。

但是我遇到了一些问题。我想使用 iText 将 JScrollPane 导出为 PDF...这可能吗?好吧,从技术上来说......因为它对我有用......但是我的 JScrollPane 实际上是滚动的......那么我如何将 JScrollPane 导出到 PDF 并保留 JScrollPane 的属性。我知道 pdf 文档确实支持这一点,正如我所看到的那样。

请帮忙... 我不确定您实际上是否需要任何代码...

我这样做的方式是将 JPanel 转换为图形,然后将其导出为 pdf

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 library.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最冷一天 2024-10-23 04:52:28

pdf PDF 中唯一滚动的是列表字段。如果您可以将 JScrollPane 的内容硬塞到字符串列表选项中,那就太好了。如果不是的话……不太好。

嵌入 Flash

这意味着将 JScrollPanel 转换为 PDF,然后将该 PDF 转换为 Flash(带有滚动条),然后将该 Flash 嵌入到 PDF 中。呃,但是应该可以。

嘿!

按钮和 JavaScript

您可以将按钮的外观设置为模板(“图标”)。您可以在按钮的范围内调整图像的缩放和对齐方式(垂直和水平)。如果你可以在javascript中调整这种对齐方式,你就可以模拟滚动条。是的!

var fld = this.getField("myButtonField");
fld.buttonAlignX += foo; // a percentage
fld.buttonAlignY -= bar; // ditto

我建议使用 PushbuttonField 来构建所有这些内容,一个用于每个控件,一个用于 JScrollPanel。您将面板的滚动行为设置为“从不”,并将初始图标对齐设置为合理的(我想是“顶部”)。

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 );

如果您想真正变得更奇特,您甚至可以使用更多脚本以及buttonAlignX和buttonAlignY在向上和向下箭头之间制作比例滑块。我不认为你会支持拖拽。

丑陋的缩放

一种在视觉上不太吸引人的替代方案是保留所有数据,将滚动面板的内容以完整尺寸、未剪辑的方式绘制到模板中。然后,您可以按比例缩小该模板以适合原始对话框上的可用区域。人们可能必须放大才能看到任何东西,但随后他们就可以看到一切。没有时髦的脚本魔法,只是一个看起来时髦的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文