OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How can I export just one page from PowerPoint file to PDF?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
xybook
Newbie
Newbie


Joined: 24 Feb 2004
Posts: 4

PostPosted: Tue Feb 24, 2004 7:33 am    Post subject: How can I export just one page from PowerPoint file to PDF? Reply with quote

My java code use impress_pdf_Export filter to export a PowerPoint file to PDF.
But I don't know which PropertyValue should be set so that it can just export one of pages to PDF?
Code:

   propertyvalue[2] = new PropertyValue();
   propertyvalue[2].Name = "Pages";
   propertyvalue[2].Value = "2-2";


I have been try "Pages", "Page", "PageNumber" but it doesn't work.

Any comments are welcome.
Thanks in advanced.

xybook Twisted Evil
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Tue Feb 24, 2004 7:57 am    Post subject: Reply with quote

There is a parameter for printing that lets you select a page range to print.

But we are not printing. We are doing storeToUrl(), which is really saving, i.e. an "export".

I do not know, and it has been discussed here several times past
http://www.oooforum.org/forum/viewtopic.php?t=2735
http://www.oooforum.org/forum/viewtopic.php?t=3458
http://www.oooforum.org/forum/viewtopic.php?t=5565
what are the possible parameters that can be passed to import / export filters. Nobody has ever found them documented anywhere.

I can offer you an ugly solution.

I have written a SlideSplitter macro. You can get it at
http://OOoMacros.org
The way it works, is that it opens your Impress file deletes all pages except for the first page, then saves it in several formats (PDF, Flash, Html), then closed without saving.
Then it repeats the process, but this time deleting all pages except for the second page. Then repeats for third page, etc.
You end up with your original Impress file untouched. But you have a separate PDF, Flash and Html for every page of your original presentation.

You could program something like this technique. If you need to access, copy / rename files, etc. then make use of the com.sun.star.ucb.SimpleFileAccess service to do the file manipulation.
http://www.oooforum.org/forum/viewtopic.php?p=17276#17276
http://www.oooforum.org/forum/viewtopic.php?t=4611
http://www.oooforum.org/forum/viewtopic.php?p=17049#17049
This might be important if you are not writing in OOo Basic. For instance a Java program manipulating documents on a remote OOo, using SimpleFileAccess can manipulate files that are on the OOo machine, not the machine running the Java program.

Of course, the slide splitter technique I just described does not necessarily require any file manipulation at all.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
xybook
Newbie
Newbie


Joined: 24 Feb 2004
Posts: 4

PostPosted: Wed Feb 25, 2004 11:31 am    Post subject: Reply with quote

Thanks Danny, you solution should work for our project.

I also browse the source code /oo_1.1_src/filter/source/pdf/pdfexport.cxx,
found some piece of code interest me.
Code:

for( sal_Int32 nData = 0, nDataCount = rFilterData.getLength(); nData < nDataCount; ++nData )
            {
    if( rFilterData[ nData ].Name == OUString( RTL_CONSTASCII_USTRINGPARAM( "CompressMode" ) ) )
    rFilterData[ nData ].Value >>= nCompressMode;
else if( rFilterData[ nData ].Name == OUString( RTL_CONSTASCII_USTRINGPARAM( "PageRange" ) ) )
    rFilterData[ nData ].Value >>= aPageRange;
else if( rFilterData[ nData ].Name == OUString( RTL_CONSTASCII_USTRINGPARAM( "Selection" ) ) )
    rFilterData[ nData ].Value >>= aSelection;
}         



I guess the prperties name should be
    CompressMode
    PageRange
    Selection
but they are still not work for my java code at all.

Any way, I will take your solution to solve it out.

xybook
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Wed Feb 25, 2004 1:17 pm    Post subject: Reply with quote

Very interesting. But I had no luck either...
Code:
Sub Main
   ' Create new writer document.
   oDoc = StarDesktop.loadComponentFromURL( "private:factory/swriter", "_blank", 0, Array() )
   
   ' Get the text of the document.
   oText = oDoc.getText()
   ' Get a cursor that can move over or to any part of the text.
   oCursor = oText.createTextCursor()
   
   ' Create ten pages of content.
   For nPage = 1 To 10
      ' Insert text into current paragraph.
      oText.insertString( oCursor, "This is page " & CSTR( nPage ) & ".", False )
      ' Give this paragraph a style.
      oCursor.ParaStyleName = "Heading 2"
      IF nPage > 1 Then
         ' If we are beyond the 1st page, then make the first new paragraph
         '  have a page break ahead of it.
         oCursor.BreakType = com.sun.star.style.BreakType.PAGE_BEFORE
      EndIf
      ' Start a new paragraph.
      oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
      
      ' Now insert 20 lines of text.
      For nLine = 1 To 20
         oText.insertString( oCursor, "This is line " & CSTR( nLine ) & ".", False )
         oText.insertControlCharacter( oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False )
      Next
   Next
   
   
   ' The PDF export filter possibly has three parameters...
   '   http://www.oooforum.org/forum/viewtopic.php?p=23173#23173
   
   oDoc.storeToUrl( _
      ConvertToURL( "C:\Documents and Settings\dbrewer\Desktop\test.pdf" ), _
      Array( _
         MakePropertyValue( "FilterName", "writer_pdf_Export" ), _
         MakePropertyValue( "PageRange", "1-4" ) ) )
End Sub

Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
   oPropertyValue = createUnoStruct( "com.sun.star.beans.PropertyValue" )
   If Not IsMissing( cName ) Then
      oPropertyValue.Name = cName
   EndIf
   If Not IsMissing( uValue ) Then
      oPropertyValue.Value = uValue
   EndIf
   MakePropertyValue() = oPropertyValue
End Function

_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
limberger
Guest





PostPosted: Wed Mar 10, 2004 7:16 am    Post subject: Properties...... Reply with quote

Where can i found all the properties Question
cause i want to export to a pdf file using de PRESS OPTIMIZED compression....
Back to top
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Wed Mar 10, 2004 3:31 pm    Post subject: Reply with quote

Probably as xybook did, read the source. Maybe I'll have to try this myself sometime. Could prove interesting.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
jhl
Newbie
Newbie


Joined: 20 Jan 2005
Posts: 1

PostPosted: Thu Jan 20, 2005 4:26 am    Post subject: A problem leads to a solution Reply with quote

I have spent some time sifting through this forum (particularly DannyB's numerous posts) trying to figure out why DocConverter doesn't work for me... I lost count of the number of times DannyB replied to this kind of message in other posts, and I'm damned if I'm going to add one more - the man is incredibly patient (I'm assuming Danny is a male name).

So, why on Windows XP professional, and OpenOffice.org 1.1.4, doesn't the thing work?
Firstly, I'm looking at writer to PDF conversion, note that writer to Word, or Text, or almost anything else does work, just not PDF. Guess what file format I need.

Clearly some good meaning programmer has changed the behaviour of the PDF export filter. My theroy is that it now requires additional parameters, but doesn't supply it's own default values, thus breaking the DocConverter code.

The note by xybook helps alot (though the code snippet is writing the properties, not reading them). I found by trial and many errors, that you do indeed need the CompressMode parameter - which matches the Compression list in the PDF Options dialog. What he missed is that these properties must be an array of the FIlterData parameter, a small step so for xybook your Java code should read:

Code:

pdfProperties[0].Name = "CompressMode";
pdfProperties[0].Value = 2; // 0 = Screen, 1 = Print, 2 = Press
filterProperties[0].Name = "FilterName";
filterProperties[0].Value =  "writer_pdf_Export";
filterProperties[1].Name = "FilterData";
filterProperties[1].Value = pdfProperties;


For DannyB, I made two modifications to your DocConverter (which now works for me, but I only tested writer to PDF, not calc, or impress to PDF), thus:

In MiscLib I added the following function:

Code:

'
' PDF export patch
'
' JHL 20/01/2005
'
' filter    the export filter name
' returns an array of properties for the export process

Function MakeExportProperties(filter as string)

    Dim filterProperty as new com.sun.star.beans.PropertyValue
    Dim overwriteProperty as new com.sun.star.beans.PropertyValue
    Dim filterDataProperty as new com.sun.star.beans.PropertyValue
    Dim compressModeProperty as new com.sun.star.beans.PropertyValue
    Dim result as Object
   
    filterProperty.Name = "FilterName"
    filterProperty.Value = filter
    overwriteProperty.Name = "Overwrite"
    overwriteProperty.Value = True
    if Right(filter, 11) = "_pdf_Export" then
        compressModeProperty.Name = "CompressMode"
        compressModeProperty.Value = 2
        filterDataProperty.Name = "FilterData"
        filterDataProperty.Value = Array(compressModeProperty)
        result = Array(filterProperty, overwriteProperty, filterDataProperty)
    else
        result = Array(filterProperty, overwriteProperty)
    endif
   
    MakeExportProperties() = result
end function


and in DocConverter I substituted all occurances of

Code:

oExportOptions = Array(MakePropertyValue( "FilterName",  cExportFilter )


with

Code:

oExportOptions = MakeExportProperties(cExportFilter)


I'd love to know if this modified code still works on earlier versions of OOo, or on different platforms...
Back to top
View user's profile Send private message Visit poster's website
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Thu Jan 20, 2005 11:51 am    Post subject: Re: A problem leads to a solution Reply with quote

jhl wrote:
I'm assuming Danny is a male name.

Yes.

I'd love to rework, DocConverter. So many projects, so little time.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
wsmith
Newbie
Newbie


Joined: 18 Feb 2005
Posts: 1

PostPosted: Fri Feb 18, 2005 9:15 am    Post subject: Generic Perl-Based HTML to PDF converter. Reply with quote

This can be used as a generic HTML to PDF converter. This provides a XML-RPC service to convert documents. Requires Xvfb, RPC::XML, Proc::Daemon. and TIme::HiRes.

This is relatively slow -- approx 1.5 sec/pdf. If anyone has any ideas on how to make it faster, please let me know.

Method html2pdf takes one argument: a base64-encoded package. The package can either be a single .html file or a .zip file containing either index.htm or index.html.

Code:

#!/usr/bin/perl


use warnings;
use strict;

use RPC::XML::Server;
use File::Temp qw(tempdir tempfile);
use File::Path;
use Time::HiRes qw(usleep);

# paths to various programs
my $xauth_bin = '/usr/bin/X11/xauth';
my $unzip_bin = '/usr/bin/unzip';
my $file_bin = '/usr/bin/file';
my $soffice_bin = '/path/to/soffice';
my $xvfb_bin = '/usr/bin/X11/Xvfb';
my $mcookie_bin = '/usr/bin/mcookie';

# internal variables
my $restart_interval = 3;
my $work_dir = tempdir();
my $usage_count_file = $work_dir . '/usage-count';
my $xauth_file = $work_dir . '/Xauthority';
my $macro = 'macro:///Standard.toPDF.toPDF';
my $display = ':42';

my $soffice_pid = 0;
my $xvfb_pid = 0;

$ENV{XAUTHORITY} = $xauth_file;
$ENV{DISPLAY} = $display;

$SIG{INT} = $SIG{TERM} = sub {
    system("rm -rf $work_dir");
    system("kill -9 $soffice_pid") if $soffice_pid;
    system("killall -9 'soffice.bin'");
    system("kill -9 $xvfb_pid") if $xvfb_pid;
};

# make work dir as needed
mkdir $work_dir;

# prelaunch xvfb
print "Starting Xvfb...";
unlink($xauth_file);
my $mcookie = `$mcookie_bin`;
system("touch $xauth_file");
system("$xauth_bin add $display . $mcookie >/dev/null 2>&1");
$xvfb_pid = `$xvfb_bin $display -screen 0 640x480x8 >/dev/null 2>&1 & echo \$!`;
chomp $xvfb_pid;
sleep 3;
print " done.\n";

# prelaunch openoffice
print "Starting OpenOffice...";
$soffice_pid = `$soffice_bin >/dev/null 2>&1 & echo \$!`;
sleep 5;
print " done.\n";

print "Daemonizing...\n";
use Proc::Daemon;
Proc::Daemon::Init();

# start server
my $srv = new RPC::XML::Server(port => 9000);
$srv->add_method({
    name => 'html2pdf',
    version => 1.0,
    hidden => 0,
    code => \&html2pdf,
    signature => [ 'base64 base64' ],
    help => ''
});

$srv->server_loop;

sub html2pdf {
    my ($srv, $package) = @_;

    my @files_to_cleanup = ();

    # save package
    my ($tfh, $tfn) = tempfile();
    print $tfh $package;
    push @files_to_cleanup, $tfn;
    close $tfh;

    # what type of file is this?
    my $index_file = '';
    my $tempdir = '';
    my $mime_type = `$file_bin --mime --brief '$tfn' 2>/dev/null`;
    chomp $mime_type;
    if($mime_type eq 'application/x-zip') {
        # a zip file. create tempdir and extract
        $tempdir = tempdir();
        push @files_to_cleanup, $tempdir;

        system("$unzip_bin -o -qq -d '$tempdir' '$tfn'");
        if(-f $tempdir . '/' . 'index.html') {
            $index_file = $tempdir . '/' . 'index.html';
        }
        elsif(-f $tempdir . '/' . 'index.htm') {
            $index_file = $tempdir .'/' . 'index.htm';
        }
        else {
            html2pdf_cleanup(@files_to_cleanup);
            return RPC::XML::fault->new(200, 'Could not find index.html or index.htm in archive.');
        }
    }
    elsif($mime_type eq 'text/html') {
        # just an html file.
        $index_file = $tfn;
    }
    else {
        return new RPC::XML::fault(200, 'Unrecognized file type: ' . $mime_type);
    }

    # try to convert file
    my (undef, $ofn) = tempfile(OPEN => 0);
    push @files_to_cleanup, $ofn;
    eval {
        # try to convert file
        system("$soffice_bin 'macro:///Standard.toPDF.toPDF(\"$index_file\", \"$ofn\")'");
    };
    if($@) {
        html2pdf_cleanup(@files_to_cleanup);
        return new RPC::XML::fault(200, 'Operation timed out.');
    }

    if(! -f $ofn) {
        html2pdf_cleanup(@files_to_cleanup);
        return new RPC::XML::fault(200, 'Operation failed.');
    }

    my $pdf_file = '';
    my $ofh = undef;

    open $ofh, $ofn;
    my $retval = new RPC::XML::base64($ofh);

    html2pdf_cleanup(@files_to_cleanup);

    return $retval;
}

sub html2pdf_cleanup {
    for my $fn (@_) {
        if( -d $fn ) {
            rmtree($fn, 0, 1);
        }
        elsif( -f $fn ) {
            unlink $fn;
        }
    }
}



This depends on the following macro being available:
macro:///Standard.toPDF.toPDF

Code:

sub toPDF( sInFile as string, sOutFile as string )
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
dim desktop    as object
rem ----------------------------------------------------------------------
rem get access to the document
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
desktop = createUnoService("com.sun.star.frame.Desktop")

dim args1(2) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ReadOnly"
args1(0).Value = True
args1(1).Name = "FilterName"
args1(1).Value = "HTML (StarWriter)"
args1(2).Name = "Hidden"
args1(2).Value = True

dim doct as object
doct = desktop.loadComponentFromURL(ConvertToURL(sInFile), "_blank", 0, args1())
document = doct.CurrentController.Frame

rem ----------------------------------------------------------------------
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "FilterName"
args2(0).Value = "writer_pdf_Export"

doct.storeToURL(ConvertToURL(sOutFile), args2())

doct.dispose()

end sub
Back to top
View user's profile Send private message
Jonas Ulrich
Newbie
Newbie


Joined: 30 Aug 2005
Posts: 3

PostPosted: Tue Aug 30, 2005 11:45 pm    Post subject: More Problems Reply with quote

Hi,
i'm having further problems with the writer_pdf_Exporter Module.
I can't get it to export the proper fonts im using.
In the document that should be exported a Type 1 Font (.pfm on Windows 2000) is used before exporting, that is replaced by an Arial/Helvetica font upon exporting.
Someone already suggested that this maybe due to compression options that replace fonts with Standard Fonts, but i have no clue where to stop that.
Does anyone have any ideas?

greetz Jonas
Back to top
View user's profile Send private message
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Wed Aug 31, 2005 12:34 am    Post subject: Reply with quote

have a try with http://www.oooforum.org/forum/viewtopic.phtml?p=61607#61607 , and play around with the CompressMode

Good luck ms777
Back to top
View user's profile Send private message
Danad
OOo Advocate
OOo Advocate


Joined: 22 Feb 2004
Posts: 293
Location: Brasil

PostPosted: Wed Aug 31, 2005 7:16 am    Post subject: Reply with quote

Quote:

Very interesting. But I had no luck either...

From notes by xybook and jhl I did have to modify a little your code and now it works on XP + OOo (1.1.3 && 1.9.109):
Code:

   ' The PDF export filter possibly has three parameters...
   '   http://www.oooforum.org/forum/viewtopic.php?p=23173#23173
   '
   Dim pdfProperties(1) As New com.sun.star.beans.PropertyValue
   pdfProperties(0).Name = "CompressMode"
   pdfProperties(0).Value = 2  ' 0 = Screen, 1 = Print, 2 = Press
   pdfProperties(1).Name = "PageRange"
   pdfProperties(1).Value = "1-4"
   anyArg = CreateUnoValue("any", pdfProperties())
   '
   oDoc.storeToUrl( _
      ConvertToURL( "C:\Documents and Settings\danad\My Documents\test.pdf" ), _
      Array( _
         MakePropertyValue( "FilterName", "writer_pdf_Export" ), _
         MakePropertyValue( "FilterData", anyArg ) ) )

HTH
Back to top
View user's profile Send private message
Jonas Ulrich
Newbie
Newbie


Joined: 30 Aug 2005
Posts: 3

PostPosted: Thu Sep 01, 2005 12:06 am    Post subject: Reply with quote

This won't help me.
Maybe the compression mode has nothing to do with the problem of the wrong fonts in the exported pdf.

*sighs*
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Sat Sep 10, 2005 8:31 am    Post subject: Reply with quote

Does this help any....

Impress: Export slides into separate documents
http://www.oooforum.org/forum/viewtopic.phtml?t=7796

The idea is to open an Impress document. (You could actually import a PPT document instead.) Then you delete every page except for the page you want to keep. Then export that one page. Then close the document without saving -- thus your original document still has all of its slides. Then repeat the procedure, but this time, keeping a different page. Each individual slide is exported into a separate document.

Slide Splitter
http://www.oooforum.org/forum/viewtopic.php?t=7796
http://www.oooforum.org/forum/viewtopic.php?p=32470#32470
http://www.oooforum.org/forum/viewtopic.php?p=23018#23018
http://www.oooforum.org/forum/viewtopic.php?t=2664
http://www.oooforum.org/forum/viewtopic.php?p=9819#9819

The Impress slide splitter is available at OOoMacros.org.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Guschtel
Newbie
Newbie


Joined: 08 Apr 2009
Posts: 2

PostPosted: Wed Apr 08, 2009 4:21 am    Post subject: Filter Pages in PDF Export Reply with quote

the PageRange Filter for the PDF actually works if one sets it correctly inside a FilterData Property.
So what i did in Java was:
Code:

public static HashMap getPageRangeProperty(int from, int to) {
       // i.e. 2-4;6;8-1
       HashMap filterData = new HashMap();
       filterData.put("PageRange", from + "-" + to);
       HashMap properties = new HashMap();
       properties.put("FilterData", filterData);
        return properties;
}


then convert this HashMap to PropertyValue's:
Code:

private static PropertyValue[] toPropertyValues(Map/*<String,Object>*/ properties) {
      PropertyValue[] propertyValues = new PropertyValue[properties.size()];
      int i = 0;
      for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) {
         Map.Entry entry = (Map.Entry) iter.next();
            Object value = entry.getValue();
            if (value instanceof Map) {
                // recursively convert nested Map to PropertyValue[]
                Map subProperties = (Map) value;
                value = toPropertyValues(subProperties);
            }
         propertyValues[i++] = makeProperty((String) entry.getKey(), value);
      }
      return propertyValues;
   }


this properties then can be used in
Code:

storable.storeToURL(foo, props);
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group