Results 1 to 9 of 9

Thread: loop question?

  1. #1
    Join Date
    Mar 2008
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default loop question?

    Hi to all...

    I have this code that will combine 2 pdf to one in dest.pdf...
    Which works fine...
    dim C
    Set C=CreateObject("Combine.Combine")
    C.Convert "c:\1.pdf"+Chr(13)+"c:\2.pdf", "c:\dest.pdf", ""
    set C = nothing

    What i would like to do is with check boxes i would select the pdf i want and it will combine them...

    How would i do a loop in the command line that would add the file name if there are 2, 4 or 8...

    Or is it a loop that i need...

    Please help...

    Thanking you in advance...

    Rino

  2. #2
    Join Date
    Feb 2008
    Location
    Buenos Aires, Argentina
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Lightbulb What I would do...

    I would do a form in the previous screen with all the possible PDF files to be included, make one checkbox for each PDF available, and name it with the same name, let's say "pdf", but the value of each one would be the name of the file, example:

    Code:
    <body>
    <form name="form1">
      <input type="checkbox" name="pdfs" value="c:\file1.pdf">This is PDF 1<br>
      <input type="checkbox" name="pdfs" value="c:\file2.pdf">This is PDF 2<br>
      <input type="checkbox" name="pdfs" value="c:\file3.pdf">This is PDF 3<br>
      <input type="checkbox" name="pdfs" value="c:\file4.pdf">This is PDF 4<br>
      <input type="checkbox" name="pdfs" value="c:\file5.pdf">This is PDF 5 
    </form>
    </body>
    What browsers do is join, sepparated by commas every form element with the same name, so the POST of this form to the next page, which would be your ASP code will get from the "pdfs" checkbox is "c:\file1.pdf, c:\file2.pdf, c:\file3.pdf, c:\file4.pdf, c:\file5.pdf"

    Now, before the Convert thing, you simply have to split (with the split function) the entire string into small strings sepparated by commas. The only LOOP you have to do now is a FOR / NEXT, getting every filename, one by one, example:

    Code:
    filenames = Split(Request.Form("pdfs"), ",")
    maxfiles = Ubound(filenames)
    For thisfile = 0 to maxfiles
      totalfiles = filenames(thisfile) & Chr(13)
    Next
    Set C=CreateObject("Combine.Combine")
    C.Convert totalfiles, "c:\dest.pdf", ""
    Maybe the code needs a little fix, I don't know how the Combine component works at all! Let me know if it works. Regards! Diego.

  3. #3
    Join Date
    Mar 2008
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Looks like this will help...
    I'll try it and let you know...

    Thanks Rino

  4. #4
    Join Date
    Mar 2008
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I tried it and it worked fine...
    I went to my c:\ drive and found the dest.pdf with the ones i selected...

    just that in my second .asp page where i point to and where it does the loop...
    i put the a href line
    <A HREF="c:\dest.pdf"><img border="0" height="32" width="33" SRC="/Images/pdf.gif"></A>
    but when i mouse over it becomes clickable but nothing happenes...

    would you know why...

    thanking you in advance...

    Rino

  5. #5
    Join Date
    Feb 2008
    Location
    Buenos Aires, Argentina
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Wink Hmmm...

    Try something like this in the ASP part:

    Response.Write("<A HREF='" & Server.MapPath("c:\dest.pdf") & "'><img border='0' height='32' width='33' SRC='/Images/pdf.gif'></A>")

    Let me know! Regards. Diego.

  6. #6
    Join Date
    Mar 2008
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I didn't try eyt your response because the merge is not working...
    Can you see if the loop is correct...
    TestSample.asp
    <form action="TestSample2.asp" method="post" name="form" >
    <INPUT TYPE=CHECKBOX name="pdfs" value="c:\1.pdf"> pdf 1<BR>
    <INPUT TYPE=CHECKBOX name="pdfs" value="c:\2.pdf"> pdf 2<BR>
    <INPUT TYPE=CHECKBOX name="pdfs" value="c:\3.pdf"> pdf 3<BR>
    <INPUT TYPE=CHECKBOX name="pdfs" value="c:\4.pdf"> pdf 4<BR>
    <input type="Submit" Value="Submit" STYLE="color:#000000">
    </form>

    in TestSample2.asp page
    filenames = Split(Request.Form("pdfs"), ",")
    maxfiles = Ubound(filenames)

    For thisfile = 0 to maxfiles
    totalfiles = filenames(thisfile) & Chr(13)
    Next

    Set C=CreateObject("PDFCombine.PDFCombineX")
    sC.Convert totalfiles, "c:\dest.pdf", ""

    If i select one it works and the files gets created, if i select 2 or more it doesn't work....

  7. #7
    Join Date
    Feb 2008
    Location
    Buenos Aires, Argentina
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cool Hmmm....!

    Try replacing the SPLIT line from:

    filenames = Split(Request.Form("pdfs"), ",")

    to:

    filenames = Split(Trim(Request.Form("pdfs")), ",")

    or to:

    filenames = Split(Request.Form("pdfs"), ", ")

  8. #8
    Join Date
    Mar 2008
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i found the problem...
    totalfiles only had one file name because in my line i was overwriting everytime it came in
    totalfiles = filenames(thisfile) & Chr(13)
    it should be like this...
    totalfiles = totalfiles & "+" & filenames(thisfile)

    now its working... thank you...

    Does anyone know if there a right way to end a loop command...
    because i'm getting a microsoft debug error "COM Surrogate"
    i searched for it and they say it can be an infinite loop in an ASP page...
    here's my loop

    For thisfile = 0 to maxfiles
    If thisfile = 0 then
    totalfiles = filenames(thisfile)
    Else
    totalfiles = totalfiles & "+" & filenames(thisfile)
    End if
    Next

  9. #9
    Join Date
    May 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile weight loss : exercises , slimming pills

    As it is known to all, we often follow these ways when we are building the weight loss plan : exercises , slimming pills, diet therapy, slimming machine ( eg. High-frequency vibration belly fat removing instrument), acupuncture treatment , healthy diet , reducing alcohol take-in, and herbal weight loss . Unfortunately , few of them are effective and no rebound .

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •