Create a tiff with only text and no images from a postscript file with ghostscript - tiff

Is it possible to create a tiff file from a postscript-file (created from a pdf-document with readable text and images) into a tiff file without the images and only the text?
Like add a maxbuffer so images will be removed and only text remaining?
And if boxes and lines around text could be removed as well that would be awesome.
Best regards!

You can redefine the various 'image' operators so that they don't do anything:
/image {
type /dicttype eq not { % uses up argument, only one if dict form
pop pop pop pop % remove the arguments for the non-dictionary form.
} ifelse
} bind def
/imagemask {
type /dicttype eq not { % uses up argument, only one if dict form
pop pop pop pop % remove the arguments for the non-dictionary form.
} ifelse
} bind def
/colorimage {
type /integertype eq {
pop % multi
0 1 3 -1 roll {pop} for % one for each colour component
} {
pop pop pop
} ifelse
} bind def
Save that as a file, and add the file to your GS invocation.
You can remove linework similarly by redefining the stroke operator:
/stroke {
newpath
} bind def
rectstroke is harder, I suggest you read the PLRM if you need that one.
Possibly also the fill operator:
/fill {
newpath
} bind def
/eofill {
newpath
} bind def
Beware! Some text is not drawn using the text 'show' operators, but is constructed from linework, or drawn as images. These techniques will be defeated if you redefine the operators as shown above.
Note that the PDF interpreter often doesn't allow re-definition of operators, so you may first have to convert your PDF file to PostScript, using the ps2write device, then run the resulting file through GS to get a TIFF file.

gs -sDEVICE=bitrgbtags -o out.tags <myfile>
will create a ppm file with tags - tags label each pixel as text, vector, image etc.
Then you can use the C programs in ghostpdl/tools/GOT to process the image. It sounds like you want to write a new C program to to set each non text pixel to the background color or maybe just white, this is fairly straightforward with the example C programs in the GOT subdirectory as a guide (if you are a programmer). Then you would convert the ppm to tiff. Ken provided a different way of doing this that doesn't require pixel processing.

Related

Formating parts of a string in TCL/ Tk tablelist cell

I wonder if it is possible to format part of a text string when using the (example)
.tbl cellconfigure $row,$col -text "ThisBoldArial AndThisAsSubscript"
command?
I do know about eg the -font option, but this sets the font of the whole cell. Can I somehow format different parts of the string different?
I don't think you can do it easily. Looking at the documentation, I can't see any way of indicating index ranges of cell text contents (which you'd need in order to apply a rendering variation to them). I guess you could work around it by embedding a text widget as the cell's renderer window with the -window cell option; the use of a text (or ctext) widget for this purpose is mentioned in passing in documentation of the -windowupdate cell option so it must be possible to fake it that way, but you'd need to figure out the details of how to make it happen right.
This example shows how to do window embedding, albeit with a frame or button instead of a text. You'll need to do some work to get a text widget in there (basically make it borderless, read only and not scrollable at all).
proc createButton {tbl row col w} {
set key [$tbl getkeys $row]
button $w -image openImg -highlightthickness 0 -takefocus 0 \
-command [list viewFile $tbl $key]
}
…
$tbl cellconfigure $row,$column -window createButton
Naturally, you'll want to do more work to make the embedded text widget render as you want. That's potentially its own special set of complexity…

Enable text copy from canvas in tcl

I want to enable copying of the text placed on canvas. Is it possible to do so?
I have placed text using:
.c.canvasName create text 100 90 $var -font {Courier -12} ...
where var contains a tcl tk matrix.
As Donal wrote, ctext.tcl gives many helpful hints on how to manage text items in canvases.
Note that it doesn't demonstrate copying text to the clipboard. Use the following code for a rudimentary clipboard copy function:
$c bind text <<Copy>> "textCopy $c"
...
proc textCopy {w} {
clipboard clear
clipboard append [selection get]
selection clear
}
clipboard clear empties the Tk clipboard, and clipboard append copies new text to it. On Windows you can then paste this text using the normal Ctrl+V.
selection get copies text from the current selection and throws an error if no text is selected. Use
catch {clipboard append [selection get]}
to suppress such errors.
selection clear unselects the selection.

if command not working Actionscript 3

I am making a console like program where you input text, and when you press enter, that text gets turned into the variable "code" which gets read by the if/elseif command to direct it to a certain frame.
When I did this though, actionscript completely ignored the if and just executed what was inside of the if.
There are no errors, but there is a warning. This is my full code
import flash.events.KeyboardEvent;
stop();
stage.focus=textbox;
var code:String=textbox.text;
textbox.addEventListener(KeyboardEvent.KEY_DOWN,thefunction);
function thefunction(event:KeyboardEvent){
if(event.charCode == 13){
code=textbox.text;
trace(code);
page();
}
}
function page(){
if(code="red"){
gotoAndPlay(19)
}
else{
gotoAndStop(1)
}
}
The warning is here=
function page(){
if(code="red"){
gotoAndPlay(19)
}
else{
gotoAndStop(1)
}
}
It says: Warning: 1100: Assignment within conditional. Did you mean == instead of =?
I then tried doing what it said, and nothing happens when I type in anything and press enter (charCode 13).
I have tried doing this with textbox.textinstead of the variable code, and still nothing happens. (trace(code) works fine, so it must be something with the bottom portion, but I'm not sure)
I am new to actionscript, so I do not know how to fix this (my excuse :D). If anybody knows how, I would love to figure out how to fix it.
first of all, as a general rule, you should never use the assignment operator (single =) in an if statement, always use the equality operator (double =)
what you're saying right now is "if you assigned the value 'red' to code without errors, then..." which of course is always true
then, to debug your problem, try to use trace("'" + code + "'"); to see exactly what your textfield contains. if you're still in doubt, convert your text in character codes and print those. Why? if there's a non-printable or non-visible character in your textfield, your if statement wouldn't match (think "red " == "red" > false)
my guess is that your textfield is set to multiline, so your enter key would be added to the text and break your check. set it to single line to avoid possible problems (if you do need a multiline input field, you need a smarter way to compare text, like using regular expressions and such ...)

Imwrite command didn't create an image with true value in Matlab

I'm trying to write .tif image. I wrote the following command either on command window or within function file in Matlab to write tif image with the name of 'A_exam'.
All value of output image (A_exam.tif) are 255, no image displayed, just white screen. A matrix is extracted from following code. When I calculated this code, values of A matrix are correct. The problem just comes from writing an image file.
[~,Ind_max] = max(vgt,[],3);
A= arrayfun(#(y) ...
arrayfun(#(x) emp(x,y, Ind_max(x,y)), 1:size(vgt,1)), ...
1:size(vgt,2), 'UniformOutput',false);
A = reshape([A{:}], size(Ind_max))
imwrite(A,'A_exam.tif','tif')
Thank you
whos A
Name Size Bytes Class Attributes
A 41x41 6724 single
That reshape before calling imwrite looks problematic. I would change the
imwrite(A,'A_exam.tif','tif')
to add a call to mat2gray
imwrite(mat2gray(A),'A_exam.tif');
to make sure you're not mixing matrices and images.

Deleting entire function definition in Vim

I've been trying Vim for any text editing work for almost a week now. I want to know the fastest way to select a C function definition.
For example, if I have a function like this:
void helloworlds( int num )
{
int n;
for ( n = 0; n < num; ++n ) {
printf( "Hello World!\n" );
}
}
How would I be able to delete the whole definition including the function name?
As is common in Vim, there are a bunch of ways!
Note that the first two solutions depend on an absence of blank lines.
If your cursor is on the line with the function name, try d}. It will delete everything to the next block (i.e. your function body).
Within the function body itself, dap will delete the 'paragraph'.
You can delete a curly brace block with da}. (If you like this syntax, I recommend Tim Pope's fantastic surround.vim, which adds more features with a similar feel).
You could also try using regular expressions to delete until the next far left-indented closing curly brace: d/^}Enter
]] and [[ move to the next/previous first-column curly brace (equivalent to using / and ? with that regex I mentioned above. Combine with the d motion, and you acheive the same effect. In addons like Python-mode, these operators are redefined to mean exactly what you're looking for: move from function to function.
How to delete the whole block, header included
If you're on the header/name, or the line before the block, da} should do the trick.
If you're below a block, you can also make use of the handy 'offset' feature of a Vim search. d?^{?-1 will delete backwards to one line before the first occurrence of a first-column opening curly brace. This command's a bit tricky to type. Maybe you could make a <leader> shortcut out of it.
Plugins
I don't do much C programming in Vim, but there are surely plugins to help with such a thing. Try Vim Scripts or their mirror at GitHub.
To delete an entire function, including its definition, such as:
function tick() {
// ...
}
Move to the line with the function name.
Move the cursor to the opening brace, f{ should do it, or simply $.
Press V%d (Visual line, move to matching pair, delete)
If your functions look like this:
function tick()
{
// ...
}
Move to the line with the function name.
Press J (join the current line with line bellow. This also puts your cursor at the last character on the resulting line, {, just the one we need for the next command.)
Press V%d (Visual line, move to matching pair, delete.)
or
Move to the line with the function name.
Press V[Down]%d (Visual line, move one line down, move to matching pair, delete.)
If you are willing to install plugins vim-textobj-function will give you vif for Visual select Inside Function and vaf for Visual select A Function.
daf will delete the function, both the line with the signature and the function body ({})
The text object defined by this plugin are more specific and they don't rely on the function body being a contiguous block of text or { being placed at the first character on the line.
The drawback is that you depend on an external plugin.
You can use this shortcut to delete not only the function, also the lines between curly braces, i.e the code between if-else statements,while,for loops ,etc.
Press Shitf + v [Will get you in visual Mode] at the curly brace start/end.
Then Press ] + } i.e ] + Shitf ] - If you are in start brace.
Then Press [ + { i.e [ + Shitf [ - If you are in end brace.
Then DEL to delete the lines selected.
The simplest and most direct way way is as follows (works anywhere inside function):
v enter visual mode
{ move to first brace in function (may have to press more than once)
o exchange cursor from top to bottom of selection
} extend selection to bottom of function
d delete selected text
The complete command sequence would be v{o}d. Note that you can do other operations besides delete the same way. For example, to copy the function, use y (yank) instead of d.
Use this simple way
1.Go to the function definition
2.dd - delete function definition
3.d -start delete operation
4.shift+5(%) - delete the lines between { to }
If your function were separated by the blank lines, just type:
dip
which means "delete inner paragraph".
Another way is to go to the line of the start of your function and hit: Vj% (or V%% if your style puts the opening brace on the same line). This puts you into Visual-Line mode and the percent takes you to the matching closing brace. In the second style, the first % takes you to the opening brace on the line that you selected and the second to its matching closing brace.
Also works for parentheses, brackets, C-style multi-line comments and preprocessor directives.
See the manual for more info.
Pre-condition: be somewhere inside the function.
Go to the previous closing curly bracket on the first line using
[]
Then delete down to the next closing curly bracket on the first line using
d][
Most posted methods have a downside or two. Usually, when working withing a class definition of some object oriented language, you might not have an empty line after the function body, because many code formatters put the closing braces of last method and class on consecutive lines. Also, you might have annotations on top of the function. To make matters worse, there might be empty lines within your function body. Additionally you'd prefer a method that works with the cursor anywhere within the function, because having to move it to a specific line or worse, character, takes valuable time. Imagine something like
public class Test {
/* ... */
#Test
public void testStuff() {
// given
doSetup();
// when
doSomething();
// then
assertSomething();
}
}
In this scenario, vap won't do you any good, since it stops at the first empty line within your function. v{o} is out for the same reason. va{V is better but doesn't catch the annotation on top of the method. So what I would do in the most general case is va{o{. va{ selects the whole function body (caveat: if your cursor is within a nested block, for instance an inner if statement, then you'll only get that block), o puts the cursor to the beginning of the selection and { selects the whole paragraph prepending your selection. This means you'll get the function definition, all annotations and doc comments.
the most easy way I found is:
Get to the line where the function starts and do this: ^^vf{% to mark the entire function and then whatever you like.
^^ - start of the line
v - start visual mode
f - jump to the next search character
{ - this is the search character
% - jump to the closing brackets
This is also very logical after you have used it a few times.
non-visual way:
d/^}/e
... delete by searching for } at line beining, including it for deletion.
without /e (not mentioned in above answers), solution is incomplete.
with /e - searching goes to end of match, so closing bracket is included, and command is well for yanking too:
y/^}/e
if you use neovim version :>0.5
the modern way is to use treesitter and build your model, then you can be selected or yanked or deleted...
Tree-sitter is a parser generator tool and an incremental parsing library. It can build a concrete syntax tree for a source file and efficiently update the syntax tree as the source file is edited
I suggested this video on youtube to learn how to use treesitter to build your model : Let's create a Neovim plugin using Treesitter and Lua
I tried all the top answers here, but none of them works except the one by Nick which suggests to press f{ to get to the opening curly brace. Then V%d to delete the whole function.
Note that, the whole function gets yanked, so you can paste it elsewhere. I come across this use-case frequently, especially when moving if blocks inside another.
I use this map. It work for me
"delete function definition
"only support function body surround by {}
nnoremap <LEADER>df {v/{<cr>%d