web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / power automate desktop...
Power Automate
Suggested Answer

power automate desktop 拆分PDF

(0) ShareShare
ReportReport
Posted on by
power automate desktop 拆分PDF遇到難題,我感覺沒人可以解答。當unicode有多頁時,從第二頁開始就不會出現unicode。如何實現按unicode拆分再合併pdf。原來腳本有bug
如下:
Display.SelectFileDialog.SelectFiles Title: $'''請選擇PDF''' InitialDirectory: $'''C:\\Users\\Desktop\\nika''' IsTopMost: False CheckIfFileExists: False SelectedFiles=> SelectedFiles ButtonPressed=> ButtonPressed
Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Users\\taku_zhuo\\Desktop\\資料.xlsx''' Visible: False ReadOnly: True UseMachineLocale: False Instance=> ExcelInstance
Excel.ReadFromExcel.ReadCells Instance: ExcelInstance StartColumn: 1 StartRow: 1 EndColumn: 4 EndRow: 1000 GetCellContentsMode: Excel.GetCellContentsMode.TypedValues FirstLineIsHeader: True RangeValue=> ExcelData
Excel.CloseExcel.Close Instance: ExcelInstance
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
Text.ConvertDateTimeToText.FromCustomDateTime DateTime: CurrentDateTime CustomFormat: $'''yyyyMM''' Result=> FormattedDateTime
LOOP pageIndex FROM 1 TO 46 STEP 1
    Pdf.ExtractTextFromPDF.ExtractTextFromPage PDFFile: SelectedFiles[0] PageNumber: pageIndex DetectLayout: True ExtractedText=> ExtractedPDFText
    ON ERROR
    END
    Text.ParseText.RegexParseForFirstOccurrence Text: ExtractedPDFText TextToFind: $'''D\\d{5}''' StartingPosition: 0 IgnoreCase: False OccurrencePosition=> Position Match=> match
    ON ERROR
    END
    Text.Trim Text: match TrimOption: Text.TrimOption.Both TrimmedText=> cleancode
    Variables.FilterDataTable DataTable: ExcelData FilterParameters: { ^['RULE', 'COLUMN', 'OPERATOR', 'VALUE'], [$'''''', $'''unicode''', $'''Equal''', cleancode] } MatchCase: True FilteredDataTable=> FilteredDataTable
    DISABLE Variables.FilterDataTable DataTable: ExcelData FilterParameters: { ^['RULE', 'COLUMN', 'OPERATOR', 'VALUE'], [$'''''', $'''unicode''', $'''Equal''', cleancode] } MatchCase: True FilteredDataTable=> FilteredDataTable
    SET TargetFileName1 TO FilteredDataTable[0]['buyer']
    SET TargetFileName2 TO FilteredDataTable[0]['saler']
    Pdf.ExtractPages PDFFile: SelectedFiles[0] PageSelection: pageIndex ExtractedPDFPath: $'''C:\\Users\\taku_zhuo\\Desktop\\invoice\\%TargetFileName2%_%cleancode%_%TargetFileName1%%FormattedDateTime%.pdf''' IfFileExists: Pdf.IfFileExists.Overwrite ExtractedPDFFile=> ExtractedPDF
    ON ERROR
        GOTO 结束
    END
    LABEL 结束
END
PS: 想要功能很複雜。我有1個多頁數的pdf,1個excel(欄位有unicode和saler)。我需要按照unicode拆分pdf,有些unicode只有1頁,有些unicode有好多頁。當出現好多頁時,pdf只有在第一頁出現unicode,後面沒有顯示unicode。拆分好pdf還有再按照excel對應欄位修改檔案名~~
I have the same question (0)
  • Suggested answer
    Riyaz_riz11 Profile Picture
    4,204 Super User 2026 Season 1 on at
    Hi,
     
    1. Use While Loop for Pages
    Replace fixed LOOP 1 TO 46 with: SET PageIndex=1, BLOCK, LOOP WHILE 1=1. Inside: Pdf.ExtractTextFromPage page=PageIndex, regex find unicode, process if found.
    2. Stop on Page Error
    After ExtractText: ON BLOCK ERROR (set to end of block). Increase PageIndex by 1 at end of loop. Exits when no more pages ---Extract fails.
     
     
    If I have answered your question, please mark it as the preferred solution ✅ . If you like my response, please give it a Thumbs Up 👍.
    Regards,
    Riyaz

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 377

#2
11manish Profile Picture

11manish 279

#3
David_MA Profile Picture

David_MA 234 Super User 2026 Season 1

Last 30 days Overall leaderboard