Skip to main content

Web browser object?

19 replies [Last post]
Anonymous

Hi Richard,

I downloaded the incubator/rbair/swing/pdf project.
So far I'm very impressed. The code is clear and already well documented.

I had a few exceptions with my pdf files. After a few correction, I can nearly display all the pdfs we created.

1) First a bit of robustness :
PDFViewer line 150
Image img = renderedPages[currentPage-1].getImage();
if (img != null) {
g2.drawImage(img, 0, 0, renderedPages[currentPage-1].getImageObserver());
} else {
// something wrong happened
}

2) IndirectReference
Some pdfs have indirect references everywhere.
I had to add a few getObject()
For example PDFParser line 1250 resources = (Map)getObject(obj); instead of resources = (Map)obj; and line 1262: Map fontsMap = (Map)getObject(getResources().get(RES_KEY_FONT));
Maybe it would be interesting to remove all indirectReference after the initial parsing.

3) Contents with an array instead of PDFContentStream
In PDFParser line 1066 I added
If (temp instanceof Object[])
temp = ((Object[])temp)[0];
In my pdf I have an array of 2 objects. With the code above I lose the second half of the document.
There should be a loop to concatenate all the operations in PDFContentStream.operations ?

4) in PDFRenderer.renderSubPath I have operator like "BT" and "w". It is some kind of recursion.
As a quick fix I added the following code

... else
if (op == PDFOperator.BT) {
List subList = collectUntilClosingOperator(PDFOperator.ET, ops, i);
i+=subList.size()+1;
renderText(g, subList);
} else if (op == PDFOperator.w) {
float weight = ((Number)operands[0]).floatValue();
int gray = (int)(400.0f * weight);
if (gray > 255)
gray = 255;
Color grayColor = new Color(gray,gray,gray);
g.setXORMode(Color.WHITE);
g.setColor(grayColor);
g.fill(path);
g.setPaintMode();
} else {
System.err.println("RenderSubPath failed because an unrecognized operator was encountered '" + op + "'");

}
List collectUntilClosingOperator(PDFOperator operator, List ops, int startingIndex) {
for (int i=startingIndex; i < ops.size();i++) {
PDFOperation operation = (PDFOperation)ops.get(i);
PDFOperator op = operation.getOperator();
if (op == operator)
return ops.subList(startingIndex + 1, i);
}
return null;
}

5) When zooming a few times I get OutOfMemoryErrors. Increasing the heap size resolves the problem.
Nevertheless It would be good to check for available memory and not use a huge in memory ImageIcon if there is not enough memory.
Maybe a release of the previous image before constructing the new one would improve the memory usage.

Jean-Paul
[att1.html]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rameshgupta
Offline
Joined: 2004-06-04

> My personal wish would be that swingx (and later
> possibly swing) will in the future contain enhanced
> lightweight viewers for:
> - images
> - html
> as well as a standard pdf viewer.
>

And a Swing/2D-based SVG/Tiny viewer ;-)

Ramesh

mnutty
Offline
Joined: 2006-02-17

Is there anywhere I can get the code?

Patrick Wright

Hi Mark

On 12/9/05, jdnc-interest@javadesktop.org wrote:
> Is there anywhere I can get the code?

Code for what? several different things were mentioned in this thread.

Patrick

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

jpfinne
Offline
Joined: 2003-07-30

Hi Dirk,
I'm glad someone will work on the pdf renderer.
I don't have much time and I was a bit afraid of working on this alone.

The patches above are only a quick hack. I had pdfs to render and I changed to code to make it work. Handling of subpath and PDFOperator.w have to be improved.

I have a version of PDFViewer.java with no off screen images. I don't have out of memory problems and it seems to be fast enough to navigate and scroll. I can send you the source code if you want (e.mail jeanpaul a.t finne dot be).

There was a bug for the operator.re:
else if (op == PDFOperator.re) {
//draws a rectangle
float x = ((Number)operands[lastIndex-3]).floatValue();
float y = ((Number)operands[lastIndex-2]).floatValue();
float width = ((Number)operands[lastIndex-1]).floatValue();
float height = ((Number)operands[lastIndex]).floatValue();
path.moveTo(x, y);
path.lineTo(x, y + height); // jpf : was -
path.lineTo(x + width, y + height);// jpf : was -
path.lineTo(x + width, y);
path.closePath();

To increase the number of pdf that can be rendered, it is important to implement the operator Tj. Unfortunately I have a scaling problem and get "sun.dc.pr.PRException: endPath: bad path" exceptions.

renderSubPath should handle recursive call.

Jean-Paul

jnadler
Offline
Joined: 2009-04-19

Any news on the sun PDF renderer? I'm about to embark on a project that requires this; jPedal looks like the alternative. Thoughts?

Thanks--Jeff

jnadler
Offline
Joined: 2009-04-19

Also on the PDF viewer topic: Does either Richard's PDF viewer or the Sun viewer know how to handle AcroForm fields to allow user text/data entry?

Thanks,

Jeff

jpfinne
Offline
Joined: 2003-07-30

Hi Richard,
I wonder whether it is good news. We need a solution to view and print pdfs very soon. Your pdf renderer could work for us with just a few hours of work. Having the source is a big plus because we want to customize the output. For example we want to split the pdf into single pages and transfer across the wire only the pages the user asked. The process has to be transparent to the user. He/she sees the total page number count and can view the next pages as if the document was a single file.

We can't afford to wait more than a month for a solution from Sun.

Jean-Paul

rbair
Offline
Joined: 2003-07-08

Hi Jean-Paul,

I totally understand. There are a couple of ways we can work with this. First, since it is open source you can do whatever you want to to the source. If the LGPL license is an issue, the code was originally licensed under a modified Apache BSD style license, so I could point you to that code.

Second, if you sign & fax in the JCA (joint copyright agreement), I'd be happy to give you incubator CVS access and you can hack on the sources directly.

Unfortunately I don't personally have the time to work on this problem, since my time is being taken up in getting the DataSet and Binding APIs ready for the February 28 milestone release, as are most of the other committers (this is a huge milestone!).

The good news is that the Sun PDF code is strikingly similar to my own -- it only took me 30-40 minutes to port my PDF viewer to use the Sun code. So no matter which route you take you should be able to switch fairly easily.

Richard

jancarel
Offline
Joined: 2004-03-11

I noticed the code branch mentioned in this thread had disappeared from the incubator project.
Any update on this subject?
Any chance a pdf viewer will be part of jndc/swingx in the future?

rbair
Offline
Joined: 2003-07-08

Hey Jan,

I don't know what happened to the code in the incubator. I'm a very strong proponent of having PDF rendering in SwingX in the future, but it won't be for this coming release. We just don't have the time. However, the PDF code should still be available in the incubator.

Richard

jancarel
Offline
Joined: 2004-03-11

Richard, thanks for your reply.
My personal wish would be that swingx (and later possibly swing) will in the future contain enhanced lightweight viewers for:
- images
- html
as well as a standard pdf viewer.

In the meantime I will get by using a patched version of your viewer code sent to me by Jean Paul Finne which works ok for 1-page pdf's.

rbair
Offline
Joined: 2003-07-08

Hey Jan,

What would you like to see in regard to an image viewer? The JXImagePanel is the likely candidate, at least for some features. I guess a more robust viewer could be built around it. What are some of your ideas in this regard?

Richard

jancarel
Offline
Joined: 2004-03-11

> What would you like to see in regard to an image
> viewer?

Hello Richard,
I guess it's better if I defer my comments and suggestions after I have had a chance to study the current state of swingx in beta1 when it is released.

dirkhillbrecht
Offline
Joined: 2005-02-01

Hi,

I am also very eager of looking at and using a Java PDF renderer. As long as the Sun solution is not available, Richard's renderer is the way to go, I think. Therefore, it seems sensible to me to invest some work into that thing to enhance it where needed. My suggestions are

- Clean up dependencies even more

- Incorporate the changed suggested above by J.P. Finne

- Make better useable main files and perhaps a bundle to gain more attention (people like things which are ready to test - and perhaps to use...)

Just having signed and faxed the JCA, I am willing to invest some time for this. Any suggestions where and how to start?

Best regards,
Dirk

rbair
Offline
Joined: 2003-07-08

Cool! Glad to have your help. Bino is giving you commit access to the jdnc-incubator so you can hack on the PDF renderer. Do the work in the org.jdesktop.jdnc.incubator.rbair packages.

Thanks!
Richard

rbair
Offline
Joined: 2003-07-08

Hey Jean-Paul,

Thanks for all of the good suggestions. I'm glad you could get your PDF's to display as well :)

I'm going to hold on to these suggestions for a couple of days. Sun has (unknown to most of us) a really high quality PDF renderer that sun labs produced a while ago. The authors want it open sourced, but we have to go through the legal hurdles first. We've also discussed not open sourcing the project right now due to resource limitations, but instead getting a binary license and bundling the pdf renderer with JDNC as a jar. I personally haven't come across a PDF that this renderer won't render. They also make extensive use of Weak and Soft references for memory issues.

I'll let you know what happens -- I feel that a good pdf renderer is essential for desktop apps.

Richard

saurabhdwivedi
Offline
Joined: 2012-02-16

hi rbair,
i am trying to use the pdf renderer for our application to render pdf and alter the pdf for some text. the code i took from svn has a demo which is running "PDFViewer", with limited operations. I want to ask if there's any legal constraints if i use the code and customize it for my pdf related tasks?
second : if theres any way to run main class of standard liberary other that the demo provided to run and check all the functionality already provided with the PDF Renderer project.

Andy Depue

Wow, I can't speak for anyone else, but I can get *real* excited about an open
source Java PDF renderer. We are in dire need of such a thing for our
webstart rich client.

- Andy

On Thursday 10 February 2005 05:19 pm, jdnc-interest@javadesktop.org wrote:
> Hey Jean-Paul,
>
> Thanks for all of the good suggestions. I'm glad you could get your PDF's
> to display as well :)
>
> I'm going to hold on to these suggestions for a couple of days. Sun has
> (unknown to most of us) a really high quality PDF renderer that sun labs
> produced a while ago. The authors want it open sourced, but we have to go
> through the legal hurdles first. We've also discussed not open sourcing the
> project right now due to resource limitations, but instead getting a binary
> license and bundling the pdf renderer with JDNC as a jar. I personally
> haven't come across a PDF that this renderer won't render. They also make
> extensive use of Weak and Soft references for memory issues.
>
> I'll let you know what happens -- I feel that a good pdf renderer is
> essential for desktop apps.
>
> Richard
> ---
> [Message sent by forum member 'rbair' (Richard Bair)]
>
> http://www.javadesktop.org/forums/thread.jspa?messageID=56326
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

dirkhillbrecht
Offline
Joined: 2005-02-01

Andy,

> We are in dire need of such a thing for our
> webstart rich client.

we've solved the PDF showing and printing issues for rich clients with Acrobat Reader and Ghostscript for the moment:

Linux:

show: acroread

print: printpdf.sh:
---
#!/bin/sh
f=$1
[ ! -r $1 ] && exit 1
g=$f.ps
[ -e $g ] && exit 2
touch $g || exit 3
rm $g || exit 4
pdf2ps $f $g || exit $?
lp -h
-d
$g
rm $g
exit 0
---

Windows:
show: rundll32 url.dll,FileProtocolHandler {0}
print: c:\gs\gsX.YZ\bin\gswin32c setup.ps -dPrinted -dBATCH -dNOPAUSE -dSAFER -dQUIET -sOutputFile#"%printe
r%
" -dNOCANCEL

with setup.ps:
---
mark
/NoCancel true
/BitsPerPixel 4
/QueryUser 3
/UserSettings
<<
/DocumentName (PDF from Java)
/MaxResolution 600
>>
(mswinpr2) finddevice
putdeviceprops
setdevice
---

Working with some temporary files (e.g. for setup.ps) and starting acroread or gs as seperate processes, this works quite well and makes our customers happy while not driving us nuts due to support issues.

Best regards,
Dirk