Find text and replace with a pdf stored in the same folder

Hello,
I have a catalog that is updated every so often.  I have written a script to find/replace the text from a .txt file.  but i have a pdf that i want to insert that is part of it as well.  Inside the .txt file i have the name of the document.  and the pdf is stored inside the same folder as the original .indd and the .txt file.
can someone point me at some examples on how this could be done. 
Thanks

I use this script: it puts a txt in a text frame, check the overflow and find/replace some words with a pdf. Hope this is helpful.
Paolo
/************************FLOW************************************************
* This function looks for Overflows in the story and either resizes the           *
* frame to the size of the margins (if necesary) or adds a new page and     *
* a new frame, which is then linked to the previous frame.esizes the           *
function flow(){
    for(var i = 0; i < app.activeDocument.pages.count(); i++)
        for(var b = 0; b < app.activeDocument.pages[i].textFrames.count(); b++)
            if(app.activeDocument.pages[i].textFrames[b].overflows == true )
                var currentPage = myDocument.pages[i];
                var myPageNo = currentPage.name;
                var currentFrame=currentPage.textFrames[b];
                var e =currentFrame.geometricBounds[0];
                var f =currentFrame.geometricBounds[1];
                var g =currentFrame.geometricBounds[2];
                var h =currentFrame.geometricBounds[3];
                if(myPageNo %2==0){
                    var myMargins =currentPage.marginPreferences;
                    var a = currentPage.bounds[0]+myMargins.top;
                    var b = currentPage.bounds[1]+myMargins.right;
                    var c = currentPage.bounds[2]-myMargins.bottom;
                    var d = currentPage.bounds[3]-myMargins.left;
                else{
                    var myMargins =currentPage.marginPreferences;
                    var a = currentPage.bounds[0]+myMargins.top;
                    var b = currentPage.bounds[1]+myMargins.left;
                    var c = currentPage.bounds[2]-myMargins.bottom;
                    var d = currentPage.bounds[3]-myMargins.right;
                if (g < c)
                    currentFrame.geometricBounds = [a,b,c,d];
                else if (g==c){
                var newPage = myDocument.pages.add(LocationOptions.AFTER, currentPage);
                currentPage = newPage;
                myPageNo = currentPage.name;
                if(myPageNo %2==0){
                    var myMargins =currentPage.marginPreferences;
                    var a = currentPage.bounds[0]+myMargins.top;
                    var b = currentPage.bounds[1]+myMargins.right;
                    var c = currentPage.bounds[2]-myMargins.bottom;
                    var d = currentPage.bounds[3]-myMargins.left;
                    var newFrame = currentPage.textFrames.add({geometricBounds:[a,b,c,d]});
                    newFrame.textFramePreferences.textColumnCount = 7;
                    newFrame.previousTextFrame = currentFrame;
                else{
                    var myMargins =currentPage.marginPreferences;
                    var a = currentPage.bounds[0]+myMargins.top;
                    var b = currentPage.bounds[1]+myMargins.left;
                    var c = currentPage.bounds[2]-myMargins.bottom;
                    var d = currentPage.bounds[3]-myMargins.right;
                    var newFrame = currentPage.textFrames.add({geometricBounds:[a,b,c,d]});
                    newFrame.textFramePreferences.textColumnCount = 7;
                    newFrame.previousTextFrame = currentFrame;
//************************************END FLOW FUNCTION*********************************************
/*******************TextPlacer***************************
    this script will add a text file in an existing text frame
    Questo file deve essere copiato nella cartella Script di InDesign
function myGetBounds(myDocument, myPage){
var myPageWidth = myDocument.documentPreferences.pageWidth;
var myPageHeight = myDocument.documentPreferences.pageHeight
if(myPage.side == PageSideOptions.leftHand){
var myX2 = myPage.marginPreferences.left;
var myX1 = myPage.marginPreferences.right;
else{
var myX1 = myPage.marginPreferences.left;
var myX2 = myPage.marginPreferences.right;
var myY1 = myPage.marginPreferences.top;
var myX2 = myPageWidth - myX2;
var myY2 = myPageHeight - myPage.marginPreferences.bottom;
return [myY1, myX1, myY2, myX2];
/*******************ImagePlacer***************************
    this script will addimages to the document by
    substituting them with the name of the image file
    between @s (file format included[@mypic.bmp@]),
    selecting them from a specified file (see below)
    and applying object styles to them, as well as
    applying the right tab i necesary.
    It then looks for overflows in the document. If an
    overset is found, it will resize to margin size the
    text frame and if overset continues, it will add a
    new page and frame, which then will be linked
    to the previous frame, allowing the story flow.
    Questo file deve essere copiato nella cartella Script di InDesign
//Creates a new document using the specified document preset.
//Replace "myDocumentPreset" in the following line with the name
//of the document preset you want to use.
var myDocument = app.documents.add(true,app.documentPresets.item("Preset"));
//If the active document has not been saved (ever), save it.
if(app.activeDocument.saved == false){
//If you do not provide a file name, InDesign displays the Save dialog box.
app.activeDocument.save(new File("/Users/Paolo/Desktop/Documento.indd"));
function main()
var myDocument = app.documents.item(0);
var myPage = myDocument.pages.item(0);
var myTextFrame = myPage.textFrames.add({geometricBounds:myGetBounds(myDocument,myPage)});
myTextFrame.textFramePreferences.textColumnCount = 7;
myTextFrame.place(File("/Users/Paolo/Desktop/text.txt"));
//Place a text file in the text frame.
//Parameters for TextFrame.place():
//File as File object,
//[ShowingOptions as Boolean = False]
//You'll have to fill in your own file path.
//Define GREP search
var grepFind ="@@@.+@@@";
//Folders name where there are pdf, must be in the same place of the file
var myFiguresFolder = "testatine";
// Applied paragraph style
var myPStyle = myDocument.paragraphStyles.item("Paragraphstyle");
var NextPStyleCS = myDocument.paragraphStyles.item("Par_Style");
var NextPStyleEN = myDocument.paragraphStyles.item("Par_Style_en");
var NextPStyleDE = myDocument.paragraphStyles.item("Par_Style_de");
// Applied text style
var myCStyle = myDocument.characterStyles.item("text");
//Applied object style
var myOStyle = "";
var oStyle_1 = myDocument.objectStyles.item("Pictures");
var oStyle_2 = myDocument.objectStyles.item("Pictures");
var oStyle_3 = myDocument.objectStyles.item("Pictures");
//MEASUREMENTS
var maxWidth = 467; //Maximum width of an image
var maxHeight = 666; //Maximum Height of an image
var colWidth = 468; //Width of the main columb (340pt) + maximum Tab (128pt)
var maxTab = 0;
var xTab;
var xtTab;
var minTWidth = 340; //any image with a width below this will have the maximum Tab (maxTab) applied.
var PWidth; //Width of the Picture
var PHeight;//Picture Height
var myTotal;
//---------------------------------ALERTS---------------------------------\\
var notSaved = "Documento non salvato; devi prima salvare il documento";
var noFolder = "No such folder exists; "+myFiguresFolder;
var noImageMessage = "No Images were found";
var finished = " immagini sostituite"
//---------------------------------ALERTS---------------------------------\\
/************************END OF STORY*****************************************
*  The object of this bit of programming is to add an empty paragraph break *
*  at the end of the story, in order to make the actual script work in the case   *
*  that the LAST paragraph were a TABLE                                                              *
var findEnd_of_Story = "\\r(?=\\z)" //GREP for End of Story                        //
app.findGrepPreferences = NothingEnum.nothing;                              //
app.changeGrepPreferences = NothingEnum.nothing;                         //
app.findGrepPreferences.appliedParagraphStyle = myPStyle;              //
app.findGrepPreferences.findWhat = findEnd_of_Story;                      //
var fItems = myDocument.findGrep();                                              //
var myC = fItems.length-1;                                                             //
if (fItems =!0){                                                                              //
    do{                                                                                             //
        if (fItems.appliedParagraphStyle = myPStyle){                          //
            cItem = fItems[myC]                                                          //
            app.changeGrepPreferences.changeTo = "$0\\r";                  //
    myDocument.changeGrep();                                                       //
myC--;                                                                                           //
while (myC >= 0);                                                                       //
try{
var myDocPath = myDocument.filePath; //Complete Path to the Current Document
catch (myError){
alert (notSaved);
//throw("");
return;
var myFFldr =Folder(myDocPath+"/"+myFiguresFolder); //Complete Path in which the figures to be placed should be found
if(myFFldr.exists){
    flow();
    app.findGrepPreferences = app.changeGrepPreferences = null;
    app.findGrepPreferences.findWhat = grepFind;
    var myFoundItems = app.activeDocument.findGrep();
    var myCounter = myFoundItems.length-1
    myTotal = myCounter+1;
    for (i = myCounter; i >=0; i--) {
        var myName = myFoundItems[i].contents.replace (/@/g, "");
        app.selection = myFoundItems[i];
        var fFig=app.selection[0];//Found text for
        var cPStyle= fFig.appliedParagraphStyle;
        var myFile = new File( myFFldr + "/" + myName);
        if (myFile.exists) {
            var cFig = fFig.place(myFile);
            var sFig = cFig[0].parent;
          switch (cPStyle){
              case (myPStyle):
              myOStyle =oStyle_1;
              PWidth = sFig.geometricBounds[3] - sFig.geometricBounds[1];
              PHeight = sFig.geometricBounds[2] - sFig.geometricBounds[0];
              if (PWidth >= minTWidth){
                  xTab = (colWidth-PWidth);
              else{
                  xTab =maxTab;
              var currentPar = sFig.parent.paragraphs.item(0);
              currentPar.leftIndent = xTab;
              var nextPar= currentPar.insertionPoints[-1].paragraphs[0];
              var nextParStyle = nextPar.appliedParagraphStyle;
              if (nextParStyle == NextPStyleCS||nextParStyle ==NextPStyleEN||nextParStyle == NextPStyleDE){
                  xtTab = xTab
              else {
                  xtTab = nextPar.leftIndent;
              nextPar.leftIndent =xtTab;
              sFig.appliedObjectStyle = myOStyle;
              cPStyle = "";
              break;
              case (myPStyle):
              myOStyle = oStyle_3;
              sFig.appliedObjectStyle = myOStyle;
              cPStyle = "";
              break;
              default:
              myOStyle = oStyle_2;
              sFig.appliedObjectStyle = myOStyle;
              cPStyle = "";
              break;
          var oFig = sFig;
          sFig = ""
flow();
  //alert(myTotal + finished);
else{
    alert(noFolder);
var myDocument = app.documents.item(0);
//Clear the find/change grep preferences.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
//Set the find options.
app.findChangeGrepOptions.includeFootnotes = false;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
//Regular expression to use
app.findGrepPreferences.findWhat = "<(.+?)>";
//Apply the change to 24-point text only.
//app.findGrepPreferences.pointSize = 24;
//app.changeGrepPreferences.underline = true;
    var myFoundItems = app.activeDocument.findGrep();
    var myCounter = myFoundItems.length-1
    myTotal = myCounter+1;
    //alert("occorrenze" + myTotal);
    app.changeGrepPreferences.changeTo= "$1";
    app.changeGrepPreferences.appliedCharacterStyle= myDocument.characterStyles.item("head");
   myDocument.changeGrep();
  for (i = myCounter; i >=0; i--) {
        var myName = myFoundItems[i].contents.replace ("/</g", "");
        var myName = myFoundItems[i].contents.replace ("/>/g", "");
        app.selection = myFoundItems[i];
        var fFig=app.selection[0];//Found text for
        var myCStyle = myDocument.characterStyles.item("head");
        app.selection[0].applyCharacterStyle(myCStyle, true);
//Clear the find/change preferences after the search.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
main();

Similar Messages

  • Find text and replace with image - Help needed

    Hi,<br /><br />We need to place the images as inline in the appropriate places.<br /><br />texttexttext<<test1.eps>>texttexttexttexttexttext<<test2.eps>>texttexttexttexttexttext< <test3.eps>>texttexttexttexttexttext<<test4.eps>>texttexttexttexttexttext<<test5.eps>>text texttext<br /><br />This code is helpful for placing a single image at a time, we are unable to place all the images in one shot, can anyone help me out.<br /><br />I am not a programmer.<br /><br />-----------<br />var myDoc = app.activeDocument; <br />app.findPreferences = app.changePreferences = null; <br />var math=document.search("test.eps"); <br />for (i=math.length-1; i >=0; i--)<br />{ myDir = Folder.selectDialog(); <br />AllGraphics = Folder(myDir).getFiles('test.eps') <br />for (i=0; i<math.length; i++) { app.select(anil1[i]); <br />     myDoc.place(AllGraphics[i],false); } }<br />-----------<br /><br />Note: I have taken this code from forum and we have made some changes on this.<br /><br />Kavya

    Jongware,<br /><br />I try running it but gives errors:<br /><br />Error Number: 55<br />Error String: Object does not support the property or method 'changePreferences'<br />Line: 24<br />Source: app.findPreferences = app.changePreferences = null;<br /><br />This is the code I used<br /><br />// Find text and replace with image for InDesign CS3 <br />// http://www.adobeforums.com/webx?128@@.3bbf275d.59b6f012<br />var heyItsAnArray = new Array ( <br /><br />   "it contains this line!", <br /><br />   "as well as this one", <br /><br />   "or even more!", <br /><br />   "test.eps" ); <br /><br />for (arrayCount=0; arrayCount<heyItsAnArray.length; arrayCount++) <br /><br />{ <br /><br />   replaceImg (heyItsAnArray[arrayCount]); <br /><br /> } <br /><br />function replaceImg (name) <br /><br />{ var myDoc = app.activeDocument;  <br />     app.findPreferences = app.changePreferences = null;  <br />     var math=document.search(name); <br />     for (i=math.length-1; i >=0; i--)  <br />     { myDir = Folder.selectDialog();  <br />          AllGraphics = Folder(myDir).getFiles(name)  <br />          for (i=0; i<math.length; i++) { app.select(anil1[i]); <br />               myDoc.place(AllGraphics[i],false); <br /><br />               } <br /><br />          } <br /><br />     }<br /><br />Michael

  • Anyway to Find text and replace with variable FM10?

    I've just been informed that the current documentation set I've done will have different versions. I've created a brand variable, but I was wondering whether there was a quick way to find the text I need to convert, then replace it with the variable I've created?
    Mark

    Unless Fm10 is different than FM7 in this regard, you can copy an instance of the NewBrand variable in the text flow, then do an
    Edit > Find/Change
    Find [Text:] [OldBrand]
    Change [By Pasting]
    The usual issue is that each paste is not just pasting the variable, but also pasting the formats of the source instance of the variable. If all instances of the target text are the same format, say "Body", then this is not a problem.
    Otherwise, use the [Change & Find] button. Tweak formats as you go.
    I imagine that there are aftermarket enhancements for this. In FM10, you might even be able to script it, but it the number of changes is manageable, [Change & Find] suffices.

  • HT204053 how cant i use find me and see all my 3 iphones at the same time

    how can i use find me and see all my 3 iphones at the same time

    I assume you mean Find My iPhone.
    You must have the Find My iPhone service turned on inside each phone (Settings>iCloud).  Then either log into icloud.com and go to the Find My iPhone page to view a map and list of device, or use the Find My iPhone app on any device.
    "at the same time" - no you only view one map (associated with one phone) at a time.  You can't get all three phones on one map.

  • How to I share Itune library, and movies with a different user on the same computer?

    How do I share Itunes and movies with a different user on the same computer?

    https://discussions.apple.com/community/itunes

  • Problems with running Photoshop CS6 and Bridge with Lightroom 4 also on the same PC

    I was running Photoshop and Bridge, then purchased Lightroom 4. Before installingt 4 I had no problems with Bridge, but since installing 4 all of the photo's that were held in bridge are now gone, but they are in Lightroom. With Lightroom, you are able to edit photos out of Lightroom and into Photoshop when necessary, save and close and it automatically changed the Lightroom picture.
    I have two PC's, one has Bridge on it (this one) and the other without, but both have both editing prgrams installed. On the other PC I can switch between Lightroom and Photoshop with no problems, but when I try to switch with this PC, the one with Bridge installed, it will open Photoshop, but the photo will not transfer. If I close Photoshop program and go back to Lightroom, it will tell me that the picture could not be transfered to Photoshop because it would not launch. If I close that message window, it will then launch Photoshop and the picture transferes over allowing me to edit and save as normal.
    My question is; does anyone know if Lightroom and Bridge should run side by side, or should I delete Bridge from this PC and see what happens. Bridge is just a holder and organizer of photos, wherease Lightroom does the same, but also has post editing capabilities. The two programs seem redundant, but if your running Photoshop, it's hard to get files out of Lightroom. It seems that you need to open Lightroom first, then you can view and chose a photo to work on, then move it back and forth between the two programs. This seems to make Bridge redundant.
    Thanks for any help or suggestions.
    he_b_gb1947

    Hi, Yes, but that actually wasn't the problem. I start out in Lightroom,
    then move to Photoshop if I have something that can't be fixed in
    Lightroom. The problem was that when I tried to edit, out of Lightroom and
    into Photoshop, I was getting an error message that Lightroom couldn't
    prepare files for transfer because Photoshop wouldn't open. But, it had
    opened, the picture just wouldn't transfer. If I closed Photoshop,
    Lightroom would try again and it would open and transfer the second time. I
    ended up going to the Adobe help, chat line, and they looked into my PC and
    located the problem, it's now working fine. Thanks to everyone for your
    inputs. Most appreciated.
    Gary

  • Files from Windows 7 are not alphabetized correctly on OS X, and can match identically named files in the same folder

    I receive MS Word files from students using Macs or Windows-based computers.  This year, files prepared by students using Windows 7 are not alphabetized correctly on my Mac (under Snow Leopard or Mountain Lion).  The same four students keep having their files put at the END of the alphabetical sort by name, even though the files should appear earlier in the list.  I have to copy the file contents and paste the contents into a new document to get the new document to appear in the right order, and if I do so, then BOTH the old and new files appear in the Finder, even though the names appear to be identical!  So can have to files with the same name in the same folder, which ought to be impossible.  Does anyone have any idea what's going on?

    Bingo! 
    The problem is not the letters themselves, but non-letter characters in the file name; this showed up with the fixed-width fonts. The apparent duplicates and mis-sorting are caused by dashes, which differ because they're done as en-dashes in one file name and em-dashes in the other file name, or by curly or straight apostrophes.  I didn't see that in the Finder window.
    I never saw this behavior before this year.  Last year, when I was using a Mac for the first time, I did not see any such problem, even though my students' files were named using the same conventions. When I was using a Windows-based laptop before that, I never saw the problem.
    Windows must do something to style the non-letter characters differently than a Mac.  Is there any place in Windows Explorer or the OS X Finder that styles characters this way?  I can see this being a big problem for someone who needs to sort very important data by name, when the files are coming from different operating systems!
    (I just Googled en-dash, em-dash, and curly quotes with file names, and found a good number of posts on various sites about similar problems based on ASCI character coding, html coding, Windows Explorer, and other applications.  Sometimes the files don't appear at all, because the application reading the file name can't deal with a certain ASCI code.  What a mess.)

  • Search Text and Replace with Graphic InDesign CS3

    I will be working with an XML file to be reformatted in InDesign.
    Is there a plug-in or a way to global replace a character (e.g. "$") present in various places in the body text with a tiff image of similar size?
    Or is it possible for a web programmer to set it up so that when I import the XML file that InDesign will ask to re-link all occurrences with a graphic that I can specify?

    Place the graphic in your InDesign document. Copy it to the clipboard.
    Use find change and fill in the find field and click the flyout for the
    change field. Select ohter> clipboard contents unformatted.
    Bob

  • What is the recommended tool to convert all of my email and their attachments in one stroke to pdf files in the same folder structure that emails are stored in

    I have thousands of emails creatively stored in a host of sub folders. I would like to see if anyone knows of a tool that I can point at TB and convert all of my files into a similar file structure with the attachments embedded into the emails. I don't want much I realize. I bet there is a tool out there that will get me close.

    I don't know of a way to produce pdfs in a simple way (probably with a pdf printer driver), but if you export or save messages as eml files, the attachments are embedded in the emls, and emls can be read by most email programs. Besides saving through Ctrl-S, exporting complex folders to eml format is probably best done with [https://addons.mozilla.org/en-us/thunderbird/addon/importexporttools/ ImportExportTools].

  • Hello, I have updated my sister's mobile to the new ios7 and then i dont know what happened but she had the same data and names and contact numbers , photos, also messages text and whatsapp as mine. Its exactly the same, I want to restore her data help

    Hello, I have updated my sisters mobile with my Pc via itunes, and she then had the same wallpaper as mine, also the same applications, with the same username, password, same txt messages and whatsapp messages as mine. Everything is the same. Pls help me, how can I restore her info?
    Please tell me in precise, because I'm new to tech. problems. Thx. (Arwa) P.s. her iphone is 5.

    You probably used your backup, or iCloud backup.
    If she wants to restore it back, she must have a backup before. On iTunes, click Restore iPhone and choose her backup.
    If she doesn't, she has to start fresh.

  • HT204053 How do I delete an old apple ID on my I phone and replace with my new one. The old one keeps giving me updates that I can't access and want it deleted

    I have my ex apple id that we shared on my I phone and created new account. How can I delete his apple id on my I phone since I keep getting update notifications for updates of apps installed on my phone and I can't access and want the updates to stop. Please help!!! Thank u

    Welcome to the Apple Community.
    In order to change your Apple ID or password for your iCloud account on your iOS device, you need to delete the account from your iOS device first, then add it back using your updated details. (Settings > iCloud, scroll down and hit "Delete Account")

  • My hard drive died last week, and I needed to install a new one.  Previously, I was able to save a .doc with text and inserted photo to .pdf and then to .jpg.  Now I can get the .pdf but can't determine what to do to convert to .jpg.  Does anyone know ?

    My hard drive died last week, and I needed to install a new one.  Previously, I was able to save a .doc with text and inserted photo to .pdf and then to .jpg.  Now I can get the .pdf but can't determine what to do to convert to .jpg.  Does anyone know ?

    Rather than do that, which means starting over from scratch, losing all your edits, organisation and so on, why not simply use iPhoto Library Manager to revert the Library to the older version? Easier, less destructive.
    The instructions on that are here
    If you really want to start over: you can access the Originals folder simply by going to your Pictures Folder and finding the iPhoto Library there. Right (or Control-) Click on the icon and select 'Show Package Contents'. A finder window will open with the Library exposed.

  • Why were the colour icons taken away from the finder and itunes sidebars and and replaced with grey monochrome shade icons. It doesn't make any sense.

    Why were the colour icons taken away from the finder and itunes sidebars and and replaced with grey monochrome shade icons.
    Have apple rectified this yet ?
    It doesn't make sense to me why they changed this. Can anyone tell me the reason for the lack of colour ?
    On another note, can the the sidebar be changed back to the right hand side in preview (when opening PDF's). It has always been on the right in snow leopard and tiger.
    It seems to me that their has been too many unnecessary changes in the Lion operating system.
    Thanks.

    babowa wrote:
    Why were the colour icons taken away from the finder and itunes sidebars and and replaced with grey monochrome shade icons.
    Have apple rectified this yet ?
    It doesn't make sense to me why they changed this. Can anyone tell me the reason for the lack of colour ?
    You'd have to ask Apple, no one here would know - we are just users like you and aren't allowed to speculate on these forums. You have quite a bit of company though - many people preferred the color.
    And, I've not found a way to put the sidebar back on the right side in Preview, but maybe someone else can chime in with that.
    I much prefer the sidebar a la sinistra

  • Finding the "enable accessibility and reflow with tagged pdf" option in acrobat pro x?

    Hi I want to export the higlighted text from a .pdf to an office word doc. , but when I click the "export to word" option, I get a notice telline me to find the enable accessibility and reflow with tagged pdf option, now I've just clicked everything clickable in adobe acrobat and just can't find it. help its
    Any kind of help its apreciated.

    That's an option used when the original PDF file is created in Word. It's not something within Acrobat.

  • When i open emails, the text is replaced with question marks and boxes

    i have a macbook pro and when i open email attatchments which are mainly bodys of text, the text is replaced with question marks in boxes, any ideas as to how to help this or even fix it completely!?

    It means the text is a font not supported by whatever you are using

Maybe you are looking for