I found a solution to speed up PDF export of an Impress document.
Note: this will remove all bitmaps and backgrounds on slides, including the
master pages of course.
The goal is to generate a very small PDF that only contains text material.
I then use this text-only PDF with pdf2html to extract the lines and their
bounding boxes on the page.
Laurent.
public void RemoveBitmaps(XShapes xShapes)
{
if (xShapes==null)
return;
int nshapes = xShapes.getCount();
for (int i=0;i<nshapes;i++)
{
try {
XShape xShape = (XShape)UnoRuntime.queryInterface(
XShape.class, xShapes.getByIndex( i ));
String shapetype = xShape.getShapeType();
if (shapetype!=null)
{
if (shapetype.indexOf("GroupShape")>=0)
{
XShapes shapes = (XShapes)UnoRuntime.queryInterface(
XShapes.class, xShape );
RemoveBitmaps(shapes);
}
else
{
XText xText = (XText) UnoRuntime.queryInterface(
XText.class, xShape );
String text = null;
if (xText!=null)
text = xText.getString();
boolean notext = false;
if (text==null)
notext = true;
else if (text.length()==0)
notext = true;
if (notext)
{
xShapes.remove(xShape);
nshapes--;
i--;
}
}
}
}
catch (Exception e) { System.out.println(e.toString()); }
}
}
public void RemoveBackground(XDrawPage xPage)
{
try {
if (xPage==null)
return;
XPropertySet xPagePropSet =
(XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xPage );
if (xPagePropSet==null)
return;
Object any = xPagePropSet.getPropertyValue("Background");
if (any==null)
return;
com.sun.star.uno.XInterface xInt =
(com.sun.star.uno.XInterface)UnoRuntime.queryInterface(
com.sun.star.uno.XInterface.class, any );
XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface(
XPropertySet.class, xInt );
if (xPropSet==null)
return;
xPropSet.setPropertyValue("FillStyle",
com.sun.star.drawing.FillStyle.SOLID);
xPropSet.setPropertyValue("FillColor",0xffffff);
xPagePropSet.setPropertyValue("Background",xPropSet);
}
catch (Exception e) { System.out.println("GetBackground error: " +
e.toString()); }
}
for each xPage in the Impress document, then do:
XMasterPageTarget xMasterPageTarget =
(XMasterPageTarget)UnoRuntime.queryInterface(XMasterPageTarget.class,
xPage);
XDrawPage xMasterPage = xMasterPageTarget.getMasterPage();
RemoveBackground(xMasterPage);
XShapes xShapes = (XShapes)UnoRuntime.queryInterface(XShapes.class,
xMasterPage);
RemoveBitmaps(xShapes);
RemoveBackground(xPage);
xShapes = (XShapes)UnoRuntime.queryInterface(XShapes.class, xPage);
RemoveBitmaps(xShapes);
On 4/3/07, Laurent Denoue <[EMAIL PROTECTED]> wrote:
Hello Joost,
Yes you're right: the size of the PS file is smaller when I select these
options.
My goal is two-fold:
#1 export each slide of an Impress into an image: this is done using
GraphicObjectFilter
#2 extract the bounding box of each word on each slide
I couldn't find a way to directly extract this information.
However, I can export the presentation to PDF and then use XPDF to extract
the words and their bounding boxes.
But: saving to PDF was very slow sometimes.
Solution: remove all shapes that are not text on each slide.
Exporting to PDF is then much faster, but for some reason I can't get rid
of all bitmaps.
For example, I have a problem going inside a group when the ShapeType is
"GroupShape".
Is there a sample code somewhere to navigate through shapes on a DrawPage
and going inside the groups?
Also, is the index of the first shape within a group 0?
Laurent.
On 4/3/07, Joost Andrae <[EMAIL PROTECTED]> wrote:
>
> Hi Laurent,
>
> if you print to a postscript printer and want to reduce transparency,
> gradients and other things to reduce the output size of the printout
> then please have a look at /tools/options/print.
>
> > I noticed that when I try to print to a PS file instead, Impress warns
> me
> > that the Impress document contains transparent objects.
>
> Kind regards, Joost
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>