Article View: adobe.scripting.indesign
Article #16120Re: Placing Entire PDF in InDesign
From: Gary_Cosimini
Date: Thu, 16 Oct 2003 16:11
Date: Thu, 16 Oct 2003 16:11
102 lines
4228 bytes
4228 bytes
Here's an AppleScript from Adobe Studio, I think, which does just that:
set thePDF to choose file
set fileRef to (open for access thePDF)
set chunkSize to 16384 -- factor of 4096 for efficiency
set endbit to "" -- last bit of each chunk, carried over
set fileSize to (get eof fileRef)
if chunkSize > fileSize then -- would cause error
set chunkSize to fileSize
end if
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"/Type"}
repeat
try
set aChunk to read fileRef for chunkSize
on error -- end of file; parse endbit
set AppleScript's text item delimiters to {"/Type"}
set theBits to text items of endbit
set bitCount to count of items of theBits
repeat with i from 1 to bitCount
set oneBit to item i of theBits
if paragraph 1 of oneBit contains "/Pages" then
set AppleScript's text item delimiters to {"endobj"}
set partBit to text item 1 of oneBit
if partBit does not contain "/Parent" then
set AppleScript's text item delimiters to {"/Count"}
if (count of text items of partBit) > 1 then
set myPageNumber to word 1 of text item 2 of partBit
exit repeat
end if
end if
end if
end repeat
exit repeat
end try
set aChunk to endbit & aChunk
set AppleScript's text item delimiters to {"/Type"}
set theBits to text items of aChunk
set bitCount to count of items of theBits
if bitCount > 1 then
set endbit to item -1 of theBits -- might be incomplete; carry over
repeat with i from 1 to (bitCount - 1)
set oneBit to item i of theBits
if paragraph 1 of oneBit contains "/Pages" then
set AppleScript's text item delimiters to {"endobj"}
set partBit to text item 1 of oneBit
if partBit does not contain "/Parent" then
set AppleScript's text item delimiters to {"/Count"}
if (count of text items of partBit) > 1 then
set pageCount to word 1 of text item 2 of partBit
exit repeat
end if
end if
end if
end repeat
else
try
set endbit to text -6 thru -1 of aChunk -- in case delimiter is split across chunks
on error -- fewer than 6 chars in chunk; must be last read
set endbit to ""
end try
end if
end repeat
close access fileRef
set AppleScript's text item delimiters to oldDelims
set pageCount to (pageCount as number)
tell application "InDesign 2.0.2"
set myDocument to make document
tell myDocument
tell document preferences
set pages per document to pageCount
end tell
end tell
tell PDF place preferences
set PDF crop to crop media --crops the pdf to the full page
set page number to 1
end tell
-- place first page
set myPDF to place thePDF on page 1 of document 1 place point {0, 0}
set mybounds to the geometric bounds of myPDF
set my_y to item 3 of mybounds
set my_x to item 4 of mybounds
--set the page to the width and height of the pdf
tell myDocument
tell document preferences
set page height to my_y
set page width to my_x
end tell
-- these two lines put pic and frame in right place if necessary
set geometric bounds of parent of myPDF to mybounds -- adjust frame
set geometric bounds of myPDF to mybounds
end tell
-- now it's set up, do the rest
repeat with i from 2 to pageCount
tell PDF place preferences
set page number to i
end tell
place thePDF on page i of document 1 place point {0, 0}
end repeat
end tell
Technical Details
Message-ID:
<2ccdd93d.0@webx.la2eafNXanI>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-05!sn-xit-09!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!news-out.visi.com!petbe.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!webxReferences:
<2ccdd93d.-1@webx.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,8bc27d43e52b2d4e X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2003-10-16 09:37:52 PST From: Gary_Cosimini@adobeforums.com Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-05!sn-xit-09!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!news-out.visi.com!petbe.visi.com!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!webx Newsgroups: adobe.scripting.indesign Subject: Re: Placing Entire PDF in InDesign Message-ID: <2ccdd93d.0@webx.la2eafNXanI> Date: Thu, 16 Oct 2003 09:11:17 -0700 References: <2ccdd93d.-1@webx.la2eafNXanI> Lines: 103 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit