Pdf 以编程方式从文本数据生成注释记号幻灯片

Pdf 以编程方式从文本数据生成注释记号幻灯片,pdf,text,applescript,keynote,Pdf,Text,Applescript,Keynote,我编写了一个用于处理教堂礼拜歌的数据库web应用程序,我正在尝试添加一个模块来输出选定的歌曲,以便投影歌词。我最初认为我的所有用户都在使用Powerpoint,它可以导入一个简单的文本文件,每行前面都有0-5个选项卡(0-tab行成为新幻灯片的标题,一个或多个选项卡表示一个“要点”,其级别对应于多少个选项卡)。因此,我的模块目前输出这样一个文本文件,演示者将打开一个Powerpoint模板,按照他们想要的方式进行歌曲演示,插入文本文件作为新幻灯片的“大纲”,然后瞧。下面是一个在Powerpoin

我编写了一个用于处理教堂礼拜歌的数据库web应用程序,我正在尝试添加一个模块来输出选定的歌曲,以便投影歌词。我最初认为我的所有用户都在使用Powerpoint,它可以导入一个简单的文本文件,每行前面都有0-5个选项卡(0-tab行成为新幻灯片的标题,一个或多个选项卡表示一个“要点”,其级别对应于多少个选项卡)。因此,我的模块目前输出这样一个文本文件,演示者将打开一个Powerpoint模板,按照他们想要的方式进行歌曲演示,插入文本文件作为新幻灯片的“大纲”,然后瞧。下面是一个在Powerpoint中工作的文本文件结构的小示例(一张日文幻灯片,利用下一级大纲以较小字体罗马化):

但我教会的牧师(他的电脑用于投影)和除我之外的两位选择歌曲的礼拜领袖都使用Mac电脑。他们总是谈论Powerpoint的幻灯片,所以我想这就是他们使用的。但就在我完成输出选项卡式文本的代码时,我发现当他们说“Powerpoint”时,他们真正的意思是注释记号,它不能使用纯文本文件。旧版本的Keynote在内部以XML()格式存储幻灯片数据,但新版本的Keynote使用越来越不透明的格式()。苹果显然不想要任何东西,除了创建或编辑注释记号演示文稿

因此,我正在寻找关于如何处理这一问题的建议。我想要一个不涉及我创建Powerpoint文件以便他们转换为Keynote的过程。我不仅不应该每周都在循环中,而且在转换过程中还存在一些行距问题

我知道如何使用LaTeX从数据中生成PDF(我目前只对打印的chordsheets执行此操作,但我确信我可以找到如何进行幻灯片样式的布局),但Keynote显然一次只导入一页PDF-典型的周日礼拜集大约是30-50张幻灯片,因此这将非常烦人。此外,我希望敬拜领袖/牧师能够在必要时调整基调中的内容-如果它来自PDF,这是不可能的。因此,我的第一个选择是以某种方式将注释记号“模板”与某种文本(XML、JSON、选项卡式文本或其他任何文本)结合起来

似乎暗示可能可以使用Applescript(听起来像是iWorks相当于Office的VBA),但由于我没有Mac电脑,这将需要长时间借用别人的电脑来学习语言和开发/测试脚本(除非它足够简单,以至于你们中的一位愿意为我准备一些东西). 想法


编辑:在CJK的回答和评论之后,我意识到一个最终结果的例子可能有助于形象化我试图做的事情。这里有两张来自Powerpoint的幻灯片,选择了日文幻灯片示例,因为如果我能让它起作用,英文幻灯片就很容易了。一周前,当我尝试将此Powerpoint导入Keynote时,最顽固的样式是日语的行距(第一级“bullet”)和罗马化(第二级)

(如果你想知道,是的,那是底部的标题框——我知道这很不传统,但由于天花板很低,我们幻灯片的上半部分是优质房地产。)

在下一个示例(非季节性版本)中,我添加了Powerpoint的文本文件导入不支持的内容,因为CJK的方法启发我了解如何在脚本中使用富文本:在标题框中使用两种不同的文本格式。(以前我打算把版权信息放在每首歌的最后一张幻灯片上,放在使用3级或4级“子弹”风格的歌词下面。但我更喜欢标题。)

编辑2:试图从CJK的脚本中跳出跳板,下面是一个使用现有主幻灯片(如“标题和项目符号”和段落样式)的代码尝试(完全未经测试-仅来自在线示例)。我将在两天内测试它,但我将它放在这里,以便CJK可以看到我迄今为止所做的工作:

-- *** I'd like to use relative path so it would be portable, but (path to home folder as text) gave errors ***
property SambiDBTextFile : "/Users/Rachel/Desktop/Songs.txt"

property masterSlideName : "Lyrics" -- custom master slide based on "Title & Bullets"

-- ** If I can use paragraph styles, I won't need these ***
property TextSizes : {32, 28, 20}
property TextColours : {"white", {63222,57568,41634}, {63222,57568,41634}}
property TextFonts : {"Hiragino Kaku Gothic Pro", "Arial Italic", "Hiragino Kaku Gothic Pro"}

-- ** This is what I really want to use, but I don't know if I can ***
property TextStyles : {"Main Lyrics", "Romaji Lyrics", "Song Credits"}

set AppleScript's text item delimiters to tab
set notes to paragraphs of (read SambiDBTextFile)

tell application "Keynote" to tell current document

    -- *** Check for master slide existence, and substitute if absent ***
    set masterSlideList to the name of every master slide
    if masterSlideName is not in masterSlideList then
        -- *** Create master slide? Nah, probably not possible ***
        display alert ("Master Slide") message "Master slide '" & masterSlideName & "' not found; using 'Title & Bullets' instead."
        set masterSlideName to "Title & Bullets"
    end if

    -- Create slides with content from Keynote text file
    repeat with i from 1 to number of notes
        if item i of notes is "" then exit repeat -- EOF

        -- Get the text (without tabstops) and the level of indentation
        set [TextContent, TabValue] to [last text item, number of rest of reverse of text items] of item i of notes

        if TabValue is 0 then -- Indicates title of new slide
            set current slide to make new slide with properties {base slide:master slide masterSlideName}
            set object text of the default title item to TextContent
        else -- TabValue is not 0, indicating lyrics
            if TabValue > 3 then set TabValue to 3

            -- *** I have no idea if this will work, but the point is to append
            set object text of default body item to object text of default body item & TextContent & return

            -- *** Style the line just added ***
            -- *** Plan A: use paragraph styles (not sure if I can do this) ***
            set paragraph style of paragraph ((count of paragraphs of default body item) - 1) of default body item to item TabValue of TextStyles

            -- *** Plan B: hardcoded styling (uncomment if above line doesn't work) ***
            --tell paragraph ((count of paragraphs of default body item) - 1) of default body item
                --set its color to item TabValue of TextColours
                --set its font to item TabValue of TextFonts
                --set its size to item TabValue of TextSizes
            --end tell
        end if
    end repeat
end tell

在今天对Keynote和AppleScript进行了一些讨论之后,我认为下面的脚本将按照您想要的内容生成一些内容。它包括根据正在分析的文本文件中每行的制表级别(1-5)设置不同文本设置的选项

    property KeynoteTextFile : "/Users/CK/Desktop/Keynote.txt"

    property PresentationTitle : "My Presentation"
    property _W : 1024 -- The width of each slide
    property _H : 768 -- The Height of each slide

    -- Text properties for the cover title and each slide title
    property CoverTextStyle : {font:"Arial Bold", color:"white", size:96}
    property TitleTextStyle : {font:"Arial Bold", color:"white", size:48}

    -- Spacing above and below the title of each slide
    property TitleMargins : {top:30, bottom:100}
    -- Spacing between lines in the body of each slide
    property VerticalSpacing : 75

    -- Text properties for the body of each slide for
    -- each level of tabulation
    property Tabulations : {0.1, 0.2, 0.3, 0.4, 0.5}
    property TextSizes : {32, 28, 24, 20, 16}
    property TextColours : {"white", "blue", "green", "magenta", "orange"}
    property TextFonts : {"Arial", "Arial Italic", "Times New Roman Bold", ¬
        "Times New Roman Bold Italic", "Times New Roman Italic"}


    set AppleScript's text item delimiters to tab
    set notes to paragraphs of (read KeynoteTextFile)

    -- Create new presentation with cover slide
    tell application "Keynote" to tell (make new document with properties ¬
        {document theme:theme "Black", width:_W, height:_H})

        set MyPresentation to it

        set base slide of current slide to master slide "Blank"

        tell the first slide to ¬
            set CoverTitle to make new text item ¬
                with properties {object text:PresentationTitle}

        set properties of object text of the CoverTitle to CoverTextStyle
    end tell

    -- Create slides with content from Keynote text file
    repeat with i from 1 to number of notes
        if item i of notes is "" then exit repeat -- EOF

        -- Get the text (without tabstops)
        -- and the level of indentation
        set [TextContent, TabValue] to ¬
            [last text item, number of rest of reverse of text items] ¬
                of item i of notes

        if TabValue is 0 then -- Indicates title of new slide
            tell application "Keynote"

                tell (make new slide at end of slides of MyPresentation) to ¬
                    set Title to make new text item ¬
                        with properties {object text:TextContent}

                set properties of object text of the Title to TitleTextStyle
                copy position of Title to [_x, _y]
                set position of Title to [_x, |top| of TitleMargins]

            end tell
        else -- TabValue is not 0, indicating slide content
            if TabValue > 5 then set TabValue to 5

            tell application "Keynote" to tell current slide of MyPresentation
                set n to number of text items

                set T to make new text item with properties ¬
                    {object text:TextContent}

                tell object text of T
                    set its color to item TabValue of TextColours
                    set its font to item TabValue of TextFonts
                    set its size to item TabValue of TextSizes
                end tell

                set position of T to ¬
                    [(item TabValue of Tabulations) * _W, ¬
                        VerticalSpacing * n + (|bottom| of TitleMargins)]

            end tell
        end if
    end repeat

    -- Go to first slide of presentation and bring Keynote
    -- into the foreground
    tell application "Keynote"
        set current slide of MyPresentation to first slide of MyPresentation
        activate
    end tell
以下是my Keynote.txt文件中的一些行:

这张幻灯片是由谁制作的:

请记住,实际幻灯片上的缩进级别不是由文本文件中的制表符决定的,而是由脚本顶部定义的属性值决定的。因此,解析文本文件中出现选项卡的唯一作用是确定在幻灯片上呈现文本时应用于文本的特征集(字体、颜色、大小和缩进,与文本文件缩进无关)


最后,我要指出,文本文件中的行可以以0-5个制表符开头。6个或更多选项卡被视为只有5个选项卡。但是,重要的是,行的其余部分不应包含文本中的任何制表符。就脚本所示,这将产生一些奇怪的结果。可以调整脚本以适应文本中需要包含制表符的行,但目前我看不到这种需要。

谢谢!我会在几天后访问Mac时尝试,但与此同时,我有一个问题:假设Keynote有多个级别的项目符号,如Powerpoint,您知道在添加行时如何在AppleScript中指定级别吗?具有两个选项卡的行旨在位于项目符号的第二级(以便模板可以定义与级别1不同的样式),而不是具有文字选项卡的第一级。如果你不知道
    property KeynoteTextFile : "/Users/CK/Desktop/Keynote.txt"

    property PresentationTitle : "My Presentation"
    property _W : 1024 -- The width of each slide
    property _H : 768 -- The Height of each slide

    -- Text properties for the cover title and each slide title
    property CoverTextStyle : {font:"Arial Bold", color:"white", size:96}
    property TitleTextStyle : {font:"Arial Bold", color:"white", size:48}

    -- Spacing above and below the title of each slide
    property TitleMargins : {top:30, bottom:100}
    -- Spacing between lines in the body of each slide
    property VerticalSpacing : 75

    -- Text properties for the body of each slide for
    -- each level of tabulation
    property Tabulations : {0.1, 0.2, 0.3, 0.4, 0.5}
    property TextSizes : {32, 28, 24, 20, 16}
    property TextColours : {"white", "blue", "green", "magenta", "orange"}
    property TextFonts : {"Arial", "Arial Italic", "Times New Roman Bold", ¬
        "Times New Roman Bold Italic", "Times New Roman Italic"}


    set AppleScript's text item delimiters to tab
    set notes to paragraphs of (read KeynoteTextFile)

    -- Create new presentation with cover slide
    tell application "Keynote" to tell (make new document with properties ¬
        {document theme:theme "Black", width:_W, height:_H})

        set MyPresentation to it

        set base slide of current slide to master slide "Blank"

        tell the first slide to ¬
            set CoverTitle to make new text item ¬
                with properties {object text:PresentationTitle}

        set properties of object text of the CoverTitle to CoverTextStyle
    end tell

    -- Create slides with content from Keynote text file
    repeat with i from 1 to number of notes
        if item i of notes is "" then exit repeat -- EOF

        -- Get the text (without tabstops)
        -- and the level of indentation
        set [TextContent, TabValue] to ¬
            [last text item, number of rest of reverse of text items] ¬
                of item i of notes

        if TabValue is 0 then -- Indicates title of new slide
            tell application "Keynote"

                tell (make new slide at end of slides of MyPresentation) to ¬
                    set Title to make new text item ¬
                        with properties {object text:TextContent}

                set properties of object text of the Title to TitleTextStyle
                copy position of Title to [_x, _y]
                set position of Title to [_x, |top| of TitleMargins]

            end tell
        else -- TabValue is not 0, indicating slide content
            if TabValue > 5 then set TabValue to 5

            tell application "Keynote" to tell current slide of MyPresentation
                set n to number of text items

                set T to make new text item with properties ¬
                    {object text:TextContent}

                tell object text of T
                    set its color to item TabValue of TextColours
                    set its font to item TabValue of TextFonts
                    set its size to item TabValue of TextSizes
                end tell

                set position of T to ¬
                    [(item TabValue of Tabulations) * _W, ¬
                        VerticalSpacing * n + (|bottom| of TitleMargins)]

            end tell
        end if
    end repeat

    -- Go to first slide of presentation and bring Keynote
    -- into the foreground
    tell application "Keynote"
        set current slide of MyPresentation to first slide of MyPresentation
        activate
    end tell
This is a Title
    This is indented by 1 tab
    So is this
        This is indented by 2 tabs
            This is 3 tabs
    Back to 1 tab