PDF Thumbnail Image in DCL?

PDF Thumbnail Image in DCL?

mjshaffer117
Enthusiast Enthusiast
1,027 Views
16 Replies
Message 1 of 17

PDF Thumbnail Image in DCL?

mjshaffer117
Enthusiast
Enthusiast

I would like some insight on creating images for a pop-up box with PDF thumbnail images. I would like to create a dialog pop-up box through DCL that works similarly to the "PDFATTACH" command in AutoCAD.

I've been tasked to see if the existing command can be "tweaked" to allow for full automation of PDF sheet insertions so that the user does not need to specify the location, scale and rotation on each insertion. This would also help for instances where the insertions need to continue onto another sheet since the command doesn't seem to allow for this (at least to my knowledge).

The user would select the PDF file that they want to insert and then a dialog box would display showing the PDF thumbnails of each sheet as buttons that the user can select, just like the "PDFATTACH" command (image below).

 

mjshaffer117_0-1704318225105.png

 

I'm struggling with the PDF thumbnail portion of the code. How does this work in the PDFATTACH command? And is it possible to replicate something similar through LISP and DCL?

I'm able to extract information from the PDF through LISP but not sure if that is helpful at all...

 

I've searched online for a bit to see if this has been done before but haven't come across anything just yet unfortunately. My apologies if this has been asked previously.


Any feedback would be helpful! Thanks in advance!

0 Likes
1,028 Views
16 Replies
Replies (16)
Message 2 of 17

Sea-Haven
Mentor
Mentor

A quick search and yes a cost, Creation of Thumbnail Images from PDF Files pages (mapsoft.com)

 

Once exported thumbnail images may be able to show in a dcl. 

 

Anything approaching an answer will probably be a .net solution.

Message 3 of 17

mjshaffer117
Enthusiast
Enthusiast

Appreciate the input, thank you!

I'll look into it. Was hoping to be able to code up something myself but this may work!

0 Likes
Message 4 of 17

scot-65
Advisor
Advisor

MJ,

 

DCL will not be able to do your request unless you somehow build and associate all the PDF pages to individual .SLD files (bound as a .SLB file). This is time consuming and tedious to keep up with.

 

If you can get page number information from inside a PDF, the end user will not know what is on that particular page. (?)

 

The closest I can think of to your request is to create a directory containing the individual pages and build a dialog box to read the directory's file names and display in a dialog box.

For us, this is the "Documentation" directory.

 

PWA-Documentation.jpg

 

This program we use executes STARTAPP. You will need to use -PDFATTACH.

 

Hope this helps.

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 5 of 17

Sea-Haven
Mentor
Mentor

Using an external program should be fast to make images, I dont use Open-dcl but I think it accepts images in a form/dcl. Same with a custom .net dcl. I don't do programing in .net, some one else may comment, so no need for slides. Maybe VBA even with images in a form.

 

Bottom line is need the thumb nails.

0 Likes
Message 6 of 17

mjshaffer117
Enthusiast
Enthusiast

Thanks to both of you for your replies, sorry for the late response, been trying to catch up on other projects since after the break.

 

@scot-65 I had a similar idea to yours, I actually utilized Lee Mac's listbox code to display the sheet numbers and had the user select that way. Problem is, I'm never satisfied with just listing the PDF page numbers 🤣. That, and some of the users complained that they need to open the PDF to see the sheets...
I'm wondering if it would be worth trying to automate the slide files for each PDF file. The PDF's are going to vary from project to project so that could become a mess... I'd really only need them temporarily for the DCL selection and then after that they can be forgotten about and deleted by my automation.

 

@Sea-Haven I briefly talked to my IT department about bringing in a third party software like OpenDCL but they didn't seem too keen on that idea unfortunately. So it looks like this might become a bit of a side project for myself utilizing .NET in some way.

 

I'll continue working on this and attempt an outside solution to create the images, and then hopefully toss them into my DCL. I'm open to any suggestions from anyone with experience with .NET or creating .SLD files.

0 Likes
Message 7 of 17

Sea-Haven
Mentor
Mentor

Critical is the 1st step how to make the thumbnails. Places like Github may have something. Opendcl has been around for a long time, same as maybe a VBA Form with images. I am pretty sure Lee-mac has something about number of pages in a pdf I think its one of those properties you can get from a pdf file. 

 

I think the most promising is Ghostscript I have used the product before and its very powerful, I use it to join multiple PDF's into a single PDF, from what I could find it looks like it has an option to make thumbnails, nice thing is you can call Ghostscript from lisp. So should be able to process a file transparently.

0 Likes
Message 8 of 17

scot-65
Advisor
Advisor

MJ,

 

I have not given up on you just yet. Have a look:


Most community members that have a badge number equal to or greater
than my number knows that I do not write code for your project but rather

provide a blueprint and tips for writing a successful dialog box.

 


Pre-Dialog:
Provide a support path to the directory containing all the PDF's.
If not, browse for directory using (vlax-invoke a "BrowseForFolder" 0 tx f dir)
Where tx= "Window title", f= bitcode (0), dir= "", and a= (vlax-get-or-create-object "shell.application").
Search this forum as required.
If browse for directory method, the dialog will need a row at the top containing an edit box and button ellipse "...".

It is optional to store the specific path for a specific project as a dictionary item, later to be retrieved.

 


Dialog:
 1. Create a row container.
 2. First item in the row is a column container.
 3. Column will contain two list boxes "Lis1", "Lis2".
 4. Lis1 is all the PDF's in the directory gathered with vl-directory-files "*.pdf".

     4a. Further process this list to strip away the file extension.
 5. Lis2 displays all the page numbers of the _selected_ line in Lis1.
 6. Second item in the row will be the image_tile with a x/y ratio equal to the boxes described below.
 7. Next row OK, Cancel, Help as needed.

 

action_tile "Lis1" will populate "Lis2" with all page numbers.
  also (mode_tile "accept" 1) to avoid errors.

 

action_tile "Lis2" will display the slide in the image tile.
  also (mode_tile "accept" 0) to turn back on the OK button as a selection in the list box was made.

 

(action_tile "accept" "(setq a (list (atoi (get tile \"Lis1\"))(atoi (get_tile \"Lis2\"))))(done_dialog 1)")
Where a= PDF file name index and page number.

 


Automating for the slides:
 a. Start AutoCAD.
 b. In model space create a row of boxes that represent one page each of a PDF document (8.5 x 11).
 c. One row of boxes for each PDF file.
 d. Drag and drop from the file manager the PDF, supply the page number, and drop each page into one of the boxes. Lather, rinse, repeat.
 e. Create one Paper Space tab for each PDF file.
 f. Add multiple viewports in each paper space (COPY the viewport and -PAN inside an active viewport will be your best friends).
g. One by one make a viewport active and command MSLIDE.
h. Create subdirectory "slides" and populate.
i. Convert SLD files to SLB.
j. Save AutoCAD and close.

 


Issues that may arise:
 Functions employed here were written when DOS was the OS and I do not know if they were revised to follow NTFS.
 File names shall not include spaces " " or dots ".".
 If there are still issues, rename the slide file to a maximum 8 characters (I'm unable to verify).

 As I mentioned earlier, the relationship of the PDF file name and slide (SLB) name may be of concern.

 

Hope this helps.


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 9 of 17

Sea-Haven
Mentor
Mentor

 d. Drag and drop from the file manager the PDF, supply the page number, and drop each page into one of the boxes. Lather, rinse, repeat.
 e. Create one Paper Space tab for each PDF file.

 

That is what he does not want to do, you can currently say I want page 3 of my pdf in code, but you cannot see a preview of what page 3 looks like unless you open the pdf to view re Acrobat, the answer is to not create a dwg with 88 layouts, one project I worked had 88 pages in a pdf a full set of construction dwgs. Nor is it to guess which page they want.

 

Thinking more now imageattach may be the way to go making a matrix of the pdf thumbnail pages then choose, which ones, I had a "where is that person" dwg for new staff its showed where they were located and their staff photo, had about 100 images. But again export the thumbnails from a pdf. Each image would be known as say page1, page2 etc then erase all images.

 

Will do some more research about using Ghostscript. 1st step download latest version. This is working.

 

 

cd c:\program files\gs
cd \gs10.02.1\bin
gswin64c -sDEVICE=jpeg -dPDFFitPage=true -dDEVICEWIDTHPOINTS=250 -dDEVICEHEIGHTPOINTS=250 -dNOPAUSE -sOutputFile="d:\acadtemp\PD_006-%d.jpeg" "d:\BIGAL\Bulding code.pdf"

 

 

I will convert the Windows code to lisp. 

0 Likes
Message 10 of 17

scot-65
Advisor
Advisor

@Sea-Haven 

The section of text you quoted from my response is for creating slides of the PDF pages.

From there create the slide library to be used in the dialog.

 

Regarding the naming convention a CFG (INI) file can be created and parsed to coorelate

the PDF page number to the actual slide name.

[FileName]

1=SlideName1

2=SlideName2

etc.

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 11 of 17

Sea-Haven
Mentor
Mentor

The ghostscript makes the images have tested, they can be named the same as the dwg name but suffix -1 -2 etc.

 

I am looking at sqrt of number of images, eg 88 = 9.38 so use a 10 x 10 matrix of images. For small numbers may use a 2x1 2x2 2x3 3x3 3x4.

 

Just select image's. Then run pdfattach.

SeaHaven_0-1705112523530.png

 

In my to do list.

0 Likes
Message 12 of 17

Sea-Haven
Mentor
Mentor

This is just some test code as its hard coded for an output directory, it will ask for a point for images, so use say a pdf with max 5 pages. It is a work in progress. You can see the name of the image including its page number. The scale may need to be changed its set to 1000 at moment. You will need to download ghostscript and edit path. Dont remove %d its part of ghostscript.

 

Will try later to add more functionality.

 

 

Code removed

 

 Can you post a sample pdf ? Need to look at pixels size etc 

0 Likes
Message 13 of 17

Sea-Haven
Mentor
Mentor

Ok going around in circles, a quick catch up, a slected PDF has 84 pages, when I do manually line by line the created pdfmulti.bat ie CMD, the 84 images are made in about 2 seconds. Can then do the test imageattach part

 

Running the bat file does not work, trying to run as a startapp in lisp does not work either, tried Shell also. 

 

The code is provided but you will need to download Ghostscript if you want to test and edit code to suit, I recommend don't save in "Program files". I am sure some one will say this is what your doing wrong.

 

 

(defun c:wowimages ( / )
(setq filein (getfiled "Select PDF file " "" "pdf" 16))
(setq gsexe "D:/gs/gs10.02.1/bin/gswin64c.exe ")
(setq fout (strcat  "D:/Acadtemp/PDF-" (chr 37) "d.jpeg"  " "))
(setq fo (open (setq fname "D:/Acadtemp/PDFMULTI.bat") "W"))
(write-line "c:" fo)
(write-line "CD\\" fo)
(write-line (strcat gsExe 
" -sDEVICE=jpeg -dPDFFitPage=true -dDEVICEWIDTHPOINTS=250 -dDEVICEHEIGHTPOINTS=250 -dNOPAUSE -sOutputFile="
fout " "
filein
) Fo)
(close fo)

(startapp "d:\\acadtemp\\pdfmulti.bat")

(setq jpgs (vl-directory-files "D:\\acadtemp\\" "PDF*.jpeg" 0))
(alert "Close cmd window ")
(setq num (+ 1 (sqrt (length jpgs))))
(if (> num 2)
(foreach img jpgs
(command "imageattach" (strcat "D:\\acadtemp\\" img) (getpoint "\nPick a point ") 1000 0)
)
)
(princ)
)

 

0 Likes
Message 14 of 17

mjshaffer117
Enthusiast
Enthusiast

Scot,

 

Is this the only way to create the slides? (Forgive me, I've literally just started learning about slides and .SLB) Bringing the PDF pages into cad and separating them into their own layouts will not work for me unfortunately. The PDF files will vary based on the project and could be over 100 pages at times.
To add insult to injury, the PDF pages will also vary in size as well. Most will be 8.5x11 but some can be 17x11 or larger at times.

 

I appreciate the run down pseudo-code for the dialog box.

0 Likes
Message 15 of 17

mjshaffer117
Enthusiast
Enthusiast

Sea,

 

GhostScript looks like a promising start. It's starting to look like I may have to use a third party software, though I would really like to write something up myself. Was potentially thinking about a Python script for creating the thumbnails and saving them in a temporary location specific to the users current project. I just don't know how practical that is or if it's possible to call a Python exe within LISP, that's something I have yet to try.

Will I need to then convert the .jpeg files into .sld files to make use in my dialog box? Or will .jpeg still work in DCL?

0 Likes
Message 16 of 17

Sea-Haven
Mentor
Mentor

Apart from the running problem of ghostscript, even though I use it in other code no problems, I will do the insert images so you select an image or 2 or 3 etc so no need for a dcl, can do the normal attach pdf options in the code.

 

SeaHaven_0-1705619548033.png

Try calling via Python the run ghostscript, I am still trying to work out why it wont run.

0 Likes
Message 17 of 17

Sea-Haven
Mentor
Mentor

Had another go still having problems with running Ghostscript but made a work around for the moment by open CMD and just past ghostscript command. Reset fout to suit. You will need to download Ghostscript.

 

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/pdf-thumbnail-image-in-dcl/td-p/12475333


(defun c:wowimages ( / filein gsexe fout txt jpgs img k x y num pt)

(setq filein (getfiled "Select PDF file " "" "pdf" 16))
(setq gsexe "D:\\gs\\gs10.02.1\\bin\\gswin64c.exe ")
(setq fout (strcat  "D:\\Acadtemp\\PDF-" (chr 37) "d.jpeg"  " "))
(setq txt (strcat gsexe " -sDEVICE=jpeg -dPDFFitPage=true -dDEVICEWIDTHPOINTS=250 -dDEVICEHEIGHTPOINTS=250 -dNOPAUSE -sOutputFile=" fout " " filein))
(vlax-invoke
    (vlax-get (vlax-get (vlax-create-object "htmlfile") 'ParentWindow) 'ClipBoardData)
    'setData
    "TEXT"
    txt
)
(startapp "cmd.exe")
(alert "A windows command window will appear \n\nClick on last line and do Ctrl + V\n\nThen press Enter \n\nClose window by clicking X top right")
(setq jpgs (vl-directory-files "D:\\acadtemp\\" "PDF*.jpeg" 0))
(setq pt (getpoint "\nPick a point "))
(setq x (car pt))
(setq Y (cadr pt))
(setq num (fix (+ 1 (sqrt (length jpgs)))))
(setq k 1)

(if (> num 2)
  (while (< k (length jpgs))
    (repeat num
    (if (< k (length jpgs))
    (progn
      (setq img (nth k jpgs))
      (command "imageattach" (strcat "D:\\acadtemp\\" img) pt 1000 0)
      (setq pt (mapcar '+ pt (list 1500 0.0 0.0)))
      (setq k (1+ k))
    )
    )
    )
	
    (setq y (+ y 1200))
    (setq pt (list x y))
	
  )
)
(Princ)
)

 

SeaHaven_0-1707187479748.png

Are the images acceptable rather than a pdf page as can move images or make a list of what to keep and erase the rest, including the data source.

 

 

 

 

0 Likes