Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of notes slide #63

Closed
dung1764 opened this issue Nov 18, 2014 · 11 comments
Closed

Support of notes slide #63

dung1764 opened this issue Nov 18, 2014 · 11 comments

Comments

@dung1764
Copy link

Is it possible to add notes/comments for each slide ?

@Progi1984
Copy link
Member

@dung1764 At the moment, no. But any PR are welcome :)

OpenXML :

Fichier .rels

<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide" Target="../notesSlides/notesSlide1.xml"/>

notesSlides1.xml

<!-- top -->
<p:notes xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">

<p:sp>
    <p:nvSpPr>
        <p:cNvPr id="45" name="PlaceHolder 1"/>
            <p:nvPr>
                <p:ph type="body"/>
            </p:nvPr>

OpenDocument :

<office:presentation>
    <draw:page draw:name="page0" draw:style-name="dp1" draw:master-page-name="Standard" presentation:presentation-page-layout-name="AL1T0">
        <draw:frame draw:style-name="gr1" draw:layer="layout" svg:width="15.875cm" svg:height="7.997cm" svg:x="4.498cm" svg:y="4.763cm">
            <draw:text-box>
                <text:p text:style-name="P1">
                    <text:span text:style-name="T1">Thank you for using PHPPowerPoint!</text:span>
                </text:p>
            </draw:text-box>
        </draw:frame>
        <presentation:notes draw:style-name="dp2">
            <draw:page-thumbnail draw:style-name="gr2" draw:layer="layout" svg:width="14.848cm" svg:height="11.136cm" svg:x="3.075cm" svg:y="2.257cm" draw:page-number="1" presentation:class="page"/>
            <draw:frame presentation:style-name="pr1" draw:layer="layout" svg:width="16.799cm" svg:height="13.364cm" svg:x="2.1cm" svg:y="14.107cm" presentation:class="notes">
                <draw:text-box>
                    <text:p>Test</text:p>
                    <text:p/>
                    <text:p/>
                    <text:p>Test2</text:p>
                    <text:p/>
                    <text:p/>
                    <text:p>Test3</text:p>
                    <text:p/>
                    <text:p/>
                    <text:p>OpenDocument rocks</text:p>
                </draw:text-box>
            </draw:frame>
        </presentation:notes>
    </draw:page>
    <presentation:settings presentation:mouse-visible="false"/>
</office:presentation>

@Progi1984
Copy link
Member

@dung1764 Support for notes slide implemented in ODPresentation & PowerPoint2007 Writer. Could you test and give me a feedback ? A sample has been added.

@Progi1984
Copy link
Member

@dung1764 It's ok for you ?

@JewrassicPark
Copy link
Contributor

I can see the xml in the archive but the notes don't seem to show up in ppt (Testing with ppt 2013)

@JewrassicPark
Copy link
Contributor

I changed the writeNote function of my Slide writer for Powerpoint2007 and this works for me:

    public function writeNote(Note $pNote = null)
    {
        // Check slide
        if (is_null($pNote)) {
            throw new \Exception("Invalid \PhpOffice\PhpPowerpoint\Slide\Note object passed.");
        }

        // Create XML writer
        $objWriter = $this->getXMLWriter();

        // XML header
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');

        // p:notes
        $objWriter->startElement('p:notes');
        $objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
        $objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main');
        $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');

        // p:cSld
        $objWriter->startElement('p:cSld');

        // p:spTree
        $objWriter->startElement('p:spTree');

        // p:nvGrpSpPr
        $objWriter->startElement('p:nvGrpSpPr');

        // p:cNvPr
        $objWriter->startElement('p:cNvPr');
        $objWriter->writeAttribute('id', '1');
        $objWriter->writeAttribute('name', '');
        $objWriter->endElement();

        // p:cNvGrpSpPr
        $objWriter->writeElement('p:cNvGrpSpPr', null);

        // p:nvPr
        $objWriter->writeElement('p:nvPr',null);



        // ## p:nvGrpSpPr
        $objWriter->endElement();

        // p:grpSpPr
        $objWriter->startElement('p:grpSpPr');

        // a:xfrm
        $objWriter->startElement('a:xfrm');

        // a:off
        $objWriter->startElement('a:off');
        $objWriter->writeAttribute('x', SharedDrawing::pixelsToEmu($pNote->getOffsetX()));
        $objWriter->writeAttribute('y', SharedDrawing::pixelsToEmu($pNote->getOffsetY()));
        $objWriter->endElement(); // a:off

        // a:ext
        $objWriter->startElement('a:ext');
        $objWriter->writeAttribute('cx', SharedDrawing::pixelsToEmu($pNote->getExtentX()));
        $objWriter->writeAttribute('cy', SharedDrawing::pixelsToEmu($pNote->getExtentY()));
        $objWriter->endElement(); // a:ext

        // a:chOff
        $objWriter->startElement('a:chOff');
        $objWriter->writeAttribute('x', SharedDrawing::pixelsToEmu($pNote->getOffsetX()));
        $objWriter->writeAttribute('y', SharedDrawing::pixelsToEmu($pNote->getOffsetY()));
        $objWriter->endElement(); // a:chOff

        // a:chExt
        $objWriter->startElement('a:chExt');
        $objWriter->writeAttribute('cx', SharedDrawing::pixelsToEmu($pNote->getExtentX()));
        $objWriter->writeAttribute('cy', SharedDrawing::pixelsToEmu($pNote->getExtentY()));
        $objWriter->endElement(); // a:chExt

        // ## a:xfrm
        $objWriter->endElement();

        // ## p:grpSpPr
        $objWriter->endElement();


        $objWriter->startElement('p:sp');
        $objWriter->startElement('p:nvSpPr');

        $objWriter->startElement('p:cNvPr');
        $objWriter->writeAttribute('id','1');
        $objWriter->writeAttribute('name','Notes Placeholder');
        $objWriter->endElement(); //p:cNvPr

        $objWriter->startElement('p:cNvSpPr');

        $objWriter->startElement('a:spLocks');
        $objWriter->writeAttribute('noGrp','1');
        $objWriter->endElement();//a:spLocks

        $objWriter->endElement(); //p:cNvSpPr

        $objWriter->startElement('p:nvPr');

        $objWriter->startElement('p:ph');
        $objWriter->writeAttribute('type','body');
        $objWriter->writeAttribute('idx','1');
        $objWriter->endElement(); //p:ph

        $objWriter->endElement();//p:nvPr

        $objWriter->endElement();//p:nvSpPr

        $objWriter->writeElement('p:spPr',null);


        $objWriter->startElement('p:txBody');
        $objWriter->writeElement('a:bodyPr',null);
        $objWriter->writeElement('a:lstStyle',null);

        // Loop shapes
        $shapes  = $pNote->getShapeCollection();
        foreach ($shapes as $shape) {
            // Check type
            if ($shape instanceof RichText) {
               $paragraphs = $shape->getParagraphs();
               $this->writeParagraphs($objWriter, $paragraphs);
            }
        }

        $objWriter->endElement();//p:txBody
        //p:sp
        $objWriter->endElement();

        //p:spTree
        $objWriter->endElement();
        //p:cSld
        $objWriter->endElement();

        // > p:notes
        $objWriter->endElement();

        // Return
        return $objWriter->getData();
    }

@Progi1984
Copy link
Member

@JewrassicPark @dung1764 If you could test with the last version of the develop branch, and give some feedback (success & fail), I could close or continue this issue. Thanks.

@JewrassicPark
Copy link
Contributor

Works for me, but to be fair it's the code I already checked so it's not a great test.

@Progi1984
Copy link
Member

I finally tested on my Windows Computer with PowerPoint & PowerPoint online and it works. So I close this issue.

@JewrassicPark
Copy link
Contributor

I've found a case in which it causes powerpoint to crash and it's not
trivial

If you create a first slide without notes then make subsequent slides with
notes, powerpoint can't read the file. I'm currently looking into the bug.

On Thu, Jan 8, 2015 at 7:00 AM, Progi1984 notifications@github.com wrote:

I finally tested on my Windows Computer with PowerPoint & PowerPoint
online and it works. So I close this issue.


Reply to this email directly or view it on GitHub
#63 (comment)
.

@JewrassicPark
Copy link
Contributor

the relationship is either with the _rels directory in notesslides or the
notemaster but I couldn't find the exact relationship

right now I've just patched my project by adding a placeholder note for
slides that don't have notes but this isnt a good solution and should be
opened as a bug

On Thu, Jan 8, 2015 at 1:03 PM, Derek Cohen derekcohen@gmail.com wrote:

I've found a case in which it causes powerpoint to crash and it's not
trivial

If you create a first slide without notes then make subsequent slides with
notes, powerpoint can't read the file. I'm currently looking into the bug.

On Thu, Jan 8, 2015 at 7:00 AM, Progi1984 notifications@github.com
wrote:

I finally tested on my Windows Computer with PowerPoint & PowerPoint
online and it works. So I close this issue.


Reply to this email directly or view it on GitHub
#63 (comment)
.

@Progi1984 Progi1984 reopened this Jan 9, 2015
@Progi1984
Copy link
Member

@JewrassicPark Could you open it as a new bug with a sample code ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants