How to add inline graphics programmatically into a table cell in InDesign - adobe-indesign

I have a table in an InDesign document. I will to add an inline image to the first cell.
var myPics = File("/c/test.png"),
myDoc = app.activeDocument,
myPage = myDoc.pages[0],
myTable = myDoc.stories.everyItem().tables[0],
myCell = myTable.cells[0];
myCell.contents = myPics;
I expect there should be an image put into the cell, but the file address is filled instead. What should I do?

The contents of text objects in InDesign are not exact equivalents of actual formatted native InDesign text; they are always cast to and from simple Javascript text strings. Reading the contents discards all of InDesign's text attributes (for instance, text formatting, hyperlinks, bookmarks, XML markers, and all meta-objects such as images); and writing contents fills the destination with plain text, formatted with the default formatting of the text container at the location you place the text.
You cannot store a PNG file "in" a Javascript variable; not as a File object (it will not be parsed into the actual file's contents), and not as 'an image' (the contents will be treated as a text string, not 'meaning' anything).
The proper way is to use place, which can work on an InDesign document as a whole, in which case the file will be imported directly 'on' a page, or using a text location through a valid property such as its insertionPoints:
var myPics = File("/c/test.png"),
myDoc = app.activeDocument,
myPage = myDoc.pages[0],
myTable = myDoc.stories.everyItem().tables[0],
myCell = myTable.cells[0];
myCell.insertionPoints[0].place(myPics);
If you want make sure the contents of myCell is empty before placing, you can add
if (myCell.texts[0].length > 0)
myCell.texts[0].remove();
A warning on your use of everyItem(): when used this way, it is a live collection. A collection acts like an array, except that each element of the collection is 'seen' as the one and only object. Thus, you can do something like
myTable.cells.everyItem().contents = "hello!";
and the text will appear in every single cell, because of the everyItem() command. But since you already created a collection of tables -- myDoc.stories.everyItem().tables[0] will be a list of "the" first table in all of the current document's stories -- you will find, to your surprise, that all of these will suddenly contain hello as well.
You can see this if you place a copy of your current text frame on the same page and run my version of your script again. You will find it inserts the same image in both the tables!
Presumably you want to insert the image only once, in the first table, in the first story, on the first page. That would then be
myTable = myPage.stories[0].tables[0];

Related

DXL script to copy object with pictures combined with strings

I wrote a dxl-script that reads out certain requirements in one module and place a new objct with some of its data in another module. Everything works just fine until there are pictures included. If there is a picture in the object heading and I want to copy this heading into another object, it simply fills in the text and skips the picture. Is there a way to cope with this?
Thanks in advance!
Suppose o1 is the source object with an "image" in its Object Text, while, o2 is the target object.
Let's copy all plain text, rich text and images(ole) from o1."Object text" to o2."Object Text":
Object o1, o2
string s = richTextWithOle(o1."Object Text")
o2."Object Text" = richText (s)
OLE Objects should be transferred to the destination attributes when you use the perm set (newObject.attrname, oldObject.attrname)

How can I display an image in a ms access 2013 report using relative paths stored in a field of a database

I have a simple database with table tblUsers containing the following fields:
id-number
name-short text
surname-short text
picture-short text
In the picture field I store the relative path to the linked image file for every record (using a form and a file dialog box for selecting picture).
I'm currently trying to make a report with 9 id cards on a page layout in which for every record, using an image control, to show the picture for the record by recreating the full path to the file and assingning it to the control's Picture property.
So, as an example:
I have 9 records with the values of the field Picture equal to: john_doe1.jpeg to john_doe9, stored as text.
When I load the report, I want to be able to see the 9 id cards with their respective photo atached.
I tried using the on current event for the report with this code
Private Sub Report_current()
Me.txtPathImg = Me.GetDBPath & [tblUsers.picture]
Me.imgControl.Picture = Me.txtPathImg
End Sub
but all I got is one picture for all the records in the report.
How can I display the correct picture for every record in report view?
Use a bound image control, i.e. set it's control source, e.g.
=GetDBPath() & "\" & [picture]
Then you don't need any code.
GetDBPath() must be a public function for this.
Or build the full path in a query, use that query as recordsource, then you can directly bind the image control to the full path.
hellow S.Overflow
tbl1students:
ID_FullName - dataType : text
Image_Path - dataType : text such as (D:\Imagefolder\FullName.jpg) you know that? ok
............
now create report wizard from tlblstudents table and then open report ac design
ok :
Add Imageframe from toolsbox
then make controlsource :Image_path
..............
you don't need to VBA cods to do that

Display Access data with image paths in Word document

I would like to make a Word product catalog from data stored in an Access 2007 database. I can of course use the "mail merge" function in Word for the text data, but I dont know how to make the images show up! They are they stored as file paths in Access and jpg-files in a directory on the hard drive. The images should have a special size, be right aligned to the text paragraphs so that the text is wrapping on the left side (see attached image).
This is possible, but works better in older versions of Word. Unfortunately, you don't mention which version you're using...
Anyway, the key to the question is to use an IncludePicture field to bring the picture in; pass the file path to the field using the MergeField (nested fields). You can find more information on the internet, for example: http://homepage.swissonline.ch/cindymeister/mergfaq1.htm#DBPic
The problem with an IncludePicture field is that it can't be wrapped. But if your version of Word is not too old, tables CAN wrap, so you put the IncludePicture field into a table that's a single cell. Position the table, wrap it, etc.

javafx get exactly display text of cell in tableview

this seem a simple question but I can get only the real value of cell, not the display text because I use tableColumn.setCellFactory to change the display text of cell (use a method to convert from real value to my disired text), so the cell will have 2 values: display text and real value. I can re-convert but it's a silly solution :(
cell = t.getColumns().get(col).getCellData(row);
You can't access the renderer directly. Among the reasons is that you'd have to access the VirtualFlow that contains the display nodes. However, I give you an answer to the detail information you posted:
In order to make an agnostic export functionality (to CSV, XLS etc.)
it would be very convenient to request cell text, rather than data,
from a table view. Is that possible?
For any kind of export use a converter.
You never know what target format your users have. Your users could have different number format settings in your JavaFX application than what they have in Excel. Using Excel you need to get your JavaFX model data and set Excel's model data. Don't export using the view data and expect importing in Excel view would work, you'll run into problems.
Same for CSV. If you are e. g. on german localization, a 2 decimals number will look like 123,45 in your table instead of 123.45. So when you export the table's view data, you'll break your CSV format.
You won't get around exporting your model data via a proper converter.
You can use the getItems() method to access the model of the Table. Based on the row id you can get the DataModel for that row.
tblSampleTable.getItems().get(rowId);
So you have a reference to the DataModel, that means you can access all the data (actual data)
If you need to get the display text of TableView you can do this:
public void showAllText(TableView<?> tv){
for (Node r: tv.lookupAll(".table-row-cell")) {
for (Node c: r.lookupAll(".table-cell")) {
TableCell<?, ?> tc=(TableCell<?, ?>) c;
System.out.print(tc.getText()+" \t ");
}
System.out.println("");
}
}
Good luck.

How to set the positon of table of content when using wkhtmltopdf

I'm using wkhtmltopdf to generate pdf from html pages.
My question is how to set the position of table of content page? It seems that it automatically generated in the beginning of first page. In addition, how to set the css of content of content?
There's an--xsl-style-sheet (file) parameter to wkhtmltopdf, detailed thusly in the extended command line --help (or -H).
A table of content can be added to the document by adding a toc object to
the command line. For example:
wkhtmltopdf toc http://doc.trolltech.com/4.6/qstring.html qstring.pdf
The table of content is generated based on the H tags in the input
documents. First a XML document is generated, then it is converted to
HTML using XSLT.
The generated XML document can be viewed by dumping it to a file using
the --dump-outline switch. For example:
wkhtmltopdf --dump-outline toc.xml http://doc.trolltech.com/4.6/qstring.html qstring.pdf
The XSLT document can be specified using the --xsl-style-sheet switch.
For example:
wkhtmltopdf toc --xsl-style-sheet my.xsl http://doc.trolltech.com/4.6/qstring.html qstring.pdf
The --dump-default-toc-xsl switch can be used to dump the default
XSLT style sheet to stdout. This is a good start for writing your
own style sheet
wkhtmltopdf --dump-default-toc-xsl
The XML document is in the namespace
http://code.google.com/p/wkhtmltopdf/outline
it has a root node called "outline" which contains a number of
"item" nodes. An item can contain any number of item. These are the
outline subsections to the section the item represents. A item node
has the following attributes:
- "title" the name of the section
- "page" the page number the section occurs on
- "link" a URL that links to the section.
- "backLink" the name of the anchor the the section will link back to.
The remaining TOC options only affect the default style sheet
so they will not work when specifying a custom style sheet.
So you define your own XSLT, possibly based on their default, and pass it in. No problemo.
If you want you can even make your customized TOC using a html file. e.g.; if you want to create TOC on names of html file name(s) which will be used in PDF creation (please note that for this you should know names in advance) then you can do this by passing a HTML file say user_toc.html. In this files you can put all your captions/css etc and make a placeholder for file name. This files needs to be parsed with server side code which should fill the file name in placeholder. Now the modified file can be used for TOC.
Example code in Perl:
my $TOCPage = "user_toc.html";
my $file1 = "Testfile1.html";
my $file2 = "Testfile2.html";
my $toc_file_lines;
# Open the user TOC for parsing and write in a buffer
open(FILE, $TOCPage);
read(FILE, $toc_file_lines, -s $TOCPage);
close(FILE);
# Substitute the placeholder with actual file name
$toc_file_lines =~ s/$file_name_placeholder/$file1/;
# Open the same file again and write back the buffer
open(FILE, ">".$TOCPage);
print FILE $toc_file_lines;
close(FILE);
# Linux path for wkhtmltopdf installation
my $wkhtmltopdf_path = '/usr/bin/wkhtmltopdf-i386';
my $command = "$wkhtmltopdf_path --margin-top 20mm --margin-bottom 15mm
--margin-left 15mm --margin-right 15mm
$TOCPage $file1 $file2 $pdf_manual_name";
`$command 2>&1`;
More over you can add a lot other info in TOC like chapter no/total page in chapter so on.
Hope this helps.

Resources