We have used ghostscript to generate PDF files using postscript files created by our system services for years. Currently if three topics are bookmarked for a singled page all three bookmarks point to the top of the page.
We have been asked to have the bookmarks open the page and position the viewer at the location where the topic originates on the page. My understanding is that bookmarks in the postscript file as shown should provide this functionality. Topic 1 should be at the top of the 14" page and Topic 2 should be near the bottom.
[ /Page 1 /Count -1 /Title (Topic 1) /VIEW [/XYZ 0 1008 0] /OUT pdfmark
[ /Title (Topic 2) /VIEW [/XYZ 0 55 0] /OUT pdfmark
However both bookmarks position at the top of the page.
I have attached the actual postscript file and a command file containing the actual ghostscript commands used to generate the PDF.
Postscript file
Ghostscript command fileu
Any help appreciated.
I don't think this is really a Ghostscript question (nor ghostscript.net) its really more 'how do I use the pdfmark operator'. Ghostscript produces a file which is identical (in terms of outline) with the PDF file produced by Adobe Acrobat Distiller.
I'm assuming, of course, that the pdfmarks you want are the ones in the PostScript file and you aren't intending to supply them externally.
Both Acrobat and Ghostscript produce a PDF file which has only a single Outline entry with one subordinate clause, the outline entry is closed. In both cases the destination is stored as:
/XYZ null null null
which would explain why both appear to be the same; in fact neither of them does anything.
The reason is that you have put:
[ /Count -1 /Title (Assets) /VIEW [/XYZ 0 1008 0] /OUT pdfmark
[ /Title (Assets Write-ins) /VIEW [/XYZ 0 55 0] /OUT pdfmark
PostScript is case sensitive, the actual arguments should be:
[ /Count -1 /Title (Assets) /View [/XYZ 0 1008 0] /OUT pdfmark
[ /Title (Assets Write-ins) /View [/XYZ 0 55 0] /OUT pdfmark
Cannot believe I missed this: thank you for the answer:
[ /Count -1 /Title (Assets) /VIEW [/XYZ 0 1008 0] /OUT pdfmark
[ /Title (Assets Write-ins) /VIEW [/XYZ 0 55 0] /OUT pdfmark
PostScript is case sensitive, the actual arguments should be:
[ /Count -1 /Title (Assets) /View [/XYZ 0 1008 0] /OUT pdfmark
[ /Title (Assets Write-ins) /View [/XYZ 0 55 0] /OUT pdfmark
Related
I have a 2,000+ page PDF that I need to add page numbers to. The PDF is already setup for binding. Meaning there is extra margin on right and lefthand pages to accommodate the binding. I found the following solution from Brian M. Hunt, but it always places the page number in the same position. I know I can modify the, "sub 20 sub 20" value to change the position, but how do I make the position conditional so that righthand pages have the number near the right edge and lefthand pages have the number near the left edge?
gs \
-dBATCH -dNOPAUSE \
-sDEVICE=pdfwrite -dPDFSETTINGS=/prepress \
-sOutputFile=/path/to/merged.pdf \
-c 'globaldict /MyPageCount 1 put << /EndPage {exch pop 0 eq dup {/Helvetica 12 selectfont MyPageCount =string cvs dup stringwidth pop currentpagedevice /PageSize get 0 get exch sub 20 sub 20 moveto show globaldict /MyPageCount MyPageCount 1 add put } if } bind >> setpagedevice'
-f input1.pdf -f input2.pdf
You already have MyPageCount, so you know the page number. Using that you can determine if the page count is odd or even. Then you just select different positional logic.
Something like :
MyPageCount 2 mod 1 eq
{
%%insert odd numbered page positioning
}{
%%insert even numbered page positioning
} ifelse
[add simplified program]
gs -q -sDEVICE=pdfwrite -dBATCH -dNOPAUSE -dPDFX -sOutputFile=step_4.pdf \
-c 'globaldict /MyPageCount 1 put
<<
/EndPage {
exch pop 0 eq dup {
/Helvetica 12 selectfont MyPageCount 256 string cvs dup stringwidth pop currentpagedevice
/PageSize get 0 get exch sub
MyPageCount 2 mod 1 eq {
60
}
{
505
} ifelse
sub 36 moveto
show globaldict
/MyPageCount MyPageCount 1 add put
} if
} bind
>>
setpagedevice' \
-f "test_in.pdf"
Note that =string is unique to Ghostscript (ie won't work on any other PostScript interpreter) and pulls a pre-defined 256 character string from userdict. There are dangers to using this that I doubt you realise, because its a subtlety of PostScript. I have instead replaced it with the portable (ie standard PostScript) construction 256 string which has the same effect for your purposes, but creates a scratch string that can't be reused unexpectedly, unlike =string.
You have set -dPDFX (to create a PDF/X-3 compliant file) but you haven't supplied a PDF/X definition file, this means that the resulting file may not be PDF/X compliant. The process is documented here
Thanks to KenS's suggestion I was able to get the page numbers added with the following script.
gs -q -sDEVICE=pdfwrite -dBATCH -dNOPAUSE -dPDFX -sOutputFile=step_4.pdf \
-c 'globaldict /MyPageCount 1 put
<<
/EndPage {
MyPageCount 2 mod 1 eq
{
exch pop 0 eq dup {
/Helvetica 12 selectfont MyPageCount =string cvs dup stringwidth pop currentpagedevice
/PageSize get 0 get exch sub 60 sub 36 moveto show globaldict
/MyPageCount MyPageCount 1 add put
} if
}{
exch pop 0 eq dup {
/Helvetica 12 selectfont MyPageCount =string cvs dup stringwidth pop currentpagedevice
/PageSize get 0 get exch sub 505 sub 36 moveto show globaldict
/MyPageCount MyPageCount 1 add put
} if
} ifelse
} bind
>>
setpagedevice' \
-f "test_in.pdf"
I have several indices in elasticsearch, one of them has only around 100 documents in it, but it must be updated every other second.
Result of GET _cat/indices is as following:
green open index1 8naYU5e-R-iHvfSKnrEiGw 1 0 2 9 25.5kb 25.5kb
yellow open index2 ZPQWzY7VRYGnBG0i6AL5ag 5 1 5658 89 1.2mb 1.2mb
yellow open index3 MTIDbt4uQbOv4K-0uuyOKA 5 1 0 0 1.1kb 1.1kb
yellow open index4 laF0UcIYTFKQQ6bB9dtQyw 5 1 0 0 1.1kb 1.1kb
yellow open index5 d5SYGXhYTPiVH_GKSA47lQ 5 1 0 0 1.1kb 1.1kb
yellow open index6 nIiNMwNWRZu-aISdLWa8ZA 5 1 110964 61 16.1mb 16.1mb
yellow open index7 g492XL4ZRKy4NOIBwF1yzA 5 1 111054 352 12.5mb 12.5mb
yellow open index8 C2g2RI_oQaOxUvpbzSnVIQ 5 1 123 400 484.8kb 484.8kb
As you can see, index7 has only 123 documents in it and it should not take more than 500kb on disk.
But result of du -sh ./* is like this:
128K ./8naYU5e-R-iHvfSKnrEiGw
1.5G ./C2g2RI_oQaOxUvpbzSnVIQ
172K ./d5SYGXhYTPiVH_GKSA47lQ
1.1G ./g492XL4ZRKy4NOIBwF1yzA
172K ./laF0UcIYTFKQQ6bB9dtQyw
172K ./MTIDbt4uQbOv4K-0uuyOKA
424M ./nIiNMwNWRZu-aISdLWa8ZA
276M ./ZPQWzY7VRYGnBG0i6AL5ag
It's taking more than 1GB on disk.
My question is why and how can I fix it?
I'm using elasticsearch 6.2.4 on Ubuntu 16.04
UPDATE
result of du -sh ./g492XL4ZRKy4NOIBwF1yzA/*
3.2M ./indices/g492XL4ZRKy4NOIBwF1yzA/0/index
8.0K ./indices/g492XL4ZRKy4NOIBwF1yzA/0/_state
241M ./indices/g492XL4ZRKy4NOIBwF1yzA/0/translog
3.1M ./indices/g492XL4ZRKy4NOIBwF1yzA/1/index
8.0K ./indices/g492XL4ZRKy4NOIBwF1yzA/1/_state
238M ./indices/g492XL4ZRKy4NOIBwF1yzA/1/translog
3.2M ./indices/g492XL4ZRKy4NOIBwF1yzA/2/index
8.0K ./indices/g492XL4ZRKy4NOIBwF1yzA/2/_state
241M ./indices/g492XL4ZRKy4NOIBwF1yzA/2/translog
3.1M ./indices/g492XL4ZRKy4NOIBwF1yzA/3/index
8.0K ./indices/g492XL4ZRKy4NOIBwF1yzA/3/_state
241M ./indices/g492XL4ZRKy4NOIBwF1yzA/3/translog
3.1M ./indices/g492XL4ZRKy4NOIBwF1yzA/4/index
8.0K ./indices/g492XL4ZRKy4NOIBwF1yzA/4/_state
241M ./indices/g492XL4ZRKy4NOIBwF1yzA/4/translog
4.0K ./indices/g492XL4ZRKy4NOIBwF1yzA/_state/state-4.st
The size you measured using du -h on the index folder doesn't only include the size taken by the documents stored in the index, but also contains the translog files, which by default can go up to 512mb.
In your case, _cat/indices reveals that your index7 index is 12.5mb big and when running du -h on your index folder, you can see that each index sub-folder located within each shard folder is approximately 3.1mb, so about the same magnitude as reported by _cat/indices.
How can I turn the output of zpool status -v into something usable, with data that match by row in a data.oriented format, instead of the silly "visual" output it uses, so that it's something scriptable, using standard unix-like utilities? I had a python script that did something acceptable, but python 3 completely breaks it, and I'm not fixing it just to have some new version of python break it again. (after screwing around getting the script to run with no errors, it returns nothing :)
bascially this space-bar alinged mess:
pool: data
state: ONLINE
status: Some supported features are not enabled on the pool. The pool can
still be used, but some features are unavailable.
action: Enable all features using 'zpool upgrade'. Once this is done,
the pool may no longer be accessible by software that does not support
the features. See zpool-features(7) for details.
scan: scrub repaired 0 in 4h52m with 0 errors on Fri Aug 18 04:52:47 2017
config:
NAME STATE READ WRITE CKSUM
data ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
gptid/6dfb7dbe-68c5-11e6-982d-00e04c68f511 ONLINE 0 0 0
gptid/27f40ebe-8f1b-11e4-94f8-3085a9405b85 ONLINE 0 0 0
gptid/9244318f-c1b4-11e6-a31d-0cc47ae2abe8 ONLINE 0 0 0
mirror-1 ONLINE 0 0 0
gptid/1993f2d7-8f1b-11e4-94f8-3085a9405b85 ONLINE 0 0 0
gptid/529e2c88-f1d1-11e6-89c3-0cc47ae2abe8 ONLINE 0 0 0
gptid/53a09a3e-f1d1-11e6-89c3-0cc47ae2abe8 ONLINE 0 0 0
mirror-2 ONLINE 0 0 0
gptid/51f3b377-6a20-11e6-be8c-00e04c68f511 ONLINE 0 0 0
gptid/9fb54bde-1e2d-11e7-a83e-0cc47ae2abe8 ONLINE 0 0 0
gptid/9eebde32-1e2d-11e7-a83e-0cc47ae2abe8 ONLINE 0 0 0
cache
gptid/63db5172-20bd-11e7-b561-0cc47ae2abe8 ONLINE 0 0 0
errors: No known data errors
to something with actual columnns like this:
NAME STATE READ WRITE CKSUM
data ONLINE 0 0 0
data mirror-0 ONLINE 0 0 0
data mirror-0 gptid/6dfb7dbe-68c5-11e6-982d-00e04c68f511 ONLINE 0 0 0
data mirror-0 gptid/27f40ebe-8f1b-11e4-94f8-3085a9405b85 ONLINE 0 0 0
data mirror-0 gptid/9244318f-c1b4-11e6-a31d-0cc47ae2abe8 ONLINE 0 0 0
data mirror-1 ONLINE 0 0 0
data mirror-1 gptid/1993f2d7-8f1b-11e4-94f8-3085a9405b85 ONLINE 0 0 0
data mirror-1 gptid/529e2c88-f1d1-11e6-89c3-0cc47ae2abe8 ONLINE 0 0 0
data mirror-1 gptid/53a09a3e-f1d1-11e6-89c3-0cc47ae2abe8 ONLINE 0 0 0
data mirror-2 ONLINE 0 0 0
data mirror-2 gptid/51f3b377-6a20-11e6-be8c-00e04c68f511 ONLINE 0 0 0
data mirror-2 gptid/9fb54bde-1e2d-11e7-a83e-0cc47ae2abe8 ONLINE 0 0 0
data mirror-2 gptid/9eebde32-1e2d-11e7-a83e-0cc47ae2abe8 ONLINE 0 0 0
data cache
data cache gptid/63db5172-20bd-11e7-b561-0cc47ae2abe8 ONLINE 0 0 0
I can use perl to remove and rearrange, but I can't work out how to match the rows dynamically, in a way that would work with mirror/raidz123/stripe/cache.
datadata ONLINE 0 0 0
data mirror-0 ONLINE 0 0 0
data gptid/6dfb7dbe-68c5-11e6-982d-00e04c68f511 ONLINE 0 0 0
data gptid/27f40ebe-8f1b-11e4-94f8-3085a9405b85 ONLINE 0 0 0
data gptid/9244318f-c1b4-11e6-a31d-0cc47ae2abe8 ONLINE 0 0 0
data mirror-1 ONLINE 0 0 0
data gptid/1993f2d7-8f1b-11e4-94f8-3085a9405b85 ONLINE 0 0 0
data gptid/529e2c88-f1d1-11e6-89c3-0cc47ae2abe8 ONLINE 0 0 0
data gptid/53a09a3e-f1d1-11e6-89c3-0cc47ae2abe8 ONLINE 0 0 0
data mirror-2 ONLINE 0 0 0
data gptid/51f3b377-6a20-11e6-be8c-00e04c68f511 ONLINE 0 0 0
data gptid/9fb54bde-1e2d-11e7-a83e-0cc47ae2abe8 ONLINE 0 0 0
data gptid/9eebde32-1e2d-11e7-a83e-0cc47ae2abe8 ONLINE 0 0 0
datacache
data gptid/63db5172-20bd-11e7-b561-0cc47ae2abe8 ONLINE 0 0 0
This is the code that generates the above.
zpool status -v data | sed '/ data/, $!d' | grep -v errors: > /tmp/diskslistzpoolstatusdata
perl -pi -e 's/^\n$//' /tmp/diskslistzpoolstatusdata #remove blank lines
perl -pi -e 's/\t$//' /tmp/diskslistzpoolstatusdata
perl -p -i -e 's/\t//g' /tmp/diskslistzpoolstatusdata
perl -pi -e 's/^/data/' /tmp/diskslistzpoolstatusdata
extra:
include the scrub summary and error lines per gptid
NAME STATE READ WRITE CKSUM
misc ONLINE 0 0 0
misc mirror-0 ONLINE 0 0 0
misc mirror-0 gptid/aefbaf6e-e004-11e6-8f42-0cc47ae2abe8 ONLINE 0 0 0 0err/4h52m/0err/Fri Aug 18 04:52:47 2017 No known data errors
misc mirror-0 gptid/affc3cac-e004-11e6-8f42-0cc47ae2abe8 ONLINE 0 0 0 0err/4h52m/0err/Fri Aug 18 04:52:47 2017 No known data errors
misc cache gptid/3139819b-20bd-11e7-b561-0cc47ae2abe8 ONLINE 0 0 0 0err/4h52m/0err/Fri Aug 18 04:52:47 2017 No known data errors
Unfortunately there is no integrated solution available. You have two options:
Parse it yourself in a language of your choice. You already extracted the essential information. The layout is relatively static, as vdevs and pools cannot be nested (pools contain vdevs, never pools themselves), the order is respected (no devices from vdev A come after vdev B), the keywords are few and fixed (mirror-N, raidzX-N, etc), and the output is quite small (less than hundreds of lines usually). This means you just have to go through each row, read the info you need, store it in nested objects or simply arrays and go to the next line.
Directly call the appropriate C functions to get the status in non-readable form and convert the output. To do this, have a look at status_callback(zpool_handle_t *zhp, void *data), where all printf-output is generated from the pool data. You could mirror this function to convert the output into a format you like instead of the indented format, and then call your mini-application from your script to give you your data.
If you are familiar with C, option 2 would be faster I think. Performance-wise it does not matter much, as the data is small (even on big systems) and the calls will most likely be very infrequent (as pool layouts do not change often).
I'm working towards understanding the ext3 file system. i have added printk statements into the files inside kernel source files of ext3, to see how things get executed by watching the kernel buffer messages (dmesg). I have followed the steps given in this link: https://askubuntu.com/questions/168279/how-do-i-build-a-single-in-tree-kernel-module . i am using following commands to build ext3 as a module to experiment on it by loading and unloading it using modprobe.
The commands are:
cd $HOME/linux-3.12.36/
make oldconfig # copy old .config to ./
vi .config # i have made CONFIG_EXT3_FS=m
make prepare
make modules_prepare
make SUBDIRS=scripts/mod
make SUBDIRS=fs/ext3 modules
# Then I created 'ext3' directory in /lib/modules/3.12.36/kernel/fs, which was not there earlier.
cp fs/ext3/ext3.ko /lib/modules/3.12.36/kernel/fs/ext3/
depmod
modprobe ext3
all executes ok... except the last statement which gives the error:
modprobe: ERROR: could not insert 'ext3': Device or resource busy.
my lsmod result in case helpfull:
Module Size Used by
ums_realtek 18045 0
usb_storage 62230 1 ums_realtek
auth_rpcgss 59261 0
rfcomm 69078 0
bnep 19704 2
bluetooth 372312 10 bnep,rfcomm
sunrpc 284347 2 auth_rpcgss
arc4 12608 2
iwldvm 236564 0
snd_hda_codec_hdmi 41149 1
snd_hda_codec_realtek 56979 1
mac80211 607387 1 iwldvm
snd_hda_intel 56546 3
snd_hda_codec 192906 3 snd_hda_codec_realtek,snd_hda_codec_hdmi,snd_hda_intel
i915 711131 8
snd_hwdep 13602 1 snd_hda_codec
snd_pcm 102042 3 snd_hda_codec_hdmi,snd_hda_codec,snd_hda_intel
iwlwifi 165575 1 iwldvm
snd_page_alloc 18710 2 snd_pcm,snd_hda_intel
snd_seq_midi 13324 0
snd_seq_midi_event 14899 1 snd_seq_midi
parport_pc 32741 0
snd_rawmidi 30144 1 snd_seq_midi
uvcvideo 80843 0
snd_seq 61560 2 snd_seq_midi_event,snd_seq_midi
snd_seq_device 14497 3 snd_seq,snd_rawmidi,snd_seq_midi
videobuf2_vmalloc 13216 1 uvcvideo
snd_timer 29427 2 snd_pcm,snd_seq
videobuf2_memops 13362 1 videobuf2_vmalloc
cfg80211 483503 3 iwlwifi,mac80211,iwldvm
videobuf2_core 40625 1 uvcvideo
ppdev 17635 0
snd 69274 17 snd_hda_codec_realtek,snd_hwdep,snd_timer,snd_hda_codec_hdmi,snd_pcm,snd_seq,snd_rawmidi,snd_hda_codec,snd_hda_intel,snd_seq_device,snd_seq_midi
intel_powerclamp 14727 0
drm_kms_helper 52758 1 i915
videodev 134093 2 uvcvideo,videobuf2_core
drm 297924 4 i915,drm_kms_helper
lp 17759 0
dell_laptop 17369 0
dcdbas 14888 1 dell_laptop
dell_wmi 12681 0
joydev 17393 0
sparse_keymap 13948 1 dell_wmi
coretemp 13435 0
i2c_algo_bit 13413 1 i915
shpchp 37047 0
mei_me 18437 0
kvm_intel 143006 0
mei 78023 1 mei_me
lpc_ich 21093 0
parport 42313 3 lp,ppdev,parport_pc
serio_raw 13483 0
kvm 445551 1 kvm_intel
intel_ips 18484 0
soundcore 12680 1 snd
wmi 19193 1 dell_wmi
video 19058 1 i915
psmouse 106319 0
ahci 29929 5
atl1c 46050 0
libahci 32009 1 ahci
after observing lsmod you can see that there is no ext3 or jbd module. What am i missing here or why else there is no ext3 module. yet i have installed my operating system on a drive partitioned with ext3.
i have unloaded the ext3 module for inserting my own, by typing:
modprobe -r ext3
and then,
modeprobe ext3
But still the error persists. Please help me to solve the modprobe problem.
PS: I'm using Ubuntu.
I have some inputs values (32-bit unsigned integer) defined as follow, with their associated identifier, in a file :
var=0x000000001
var1=0x000000002
var2=0x000000004
var3=0x000000008
toto=0x000000010
titi=0x000000020
tata=0x000000040
toto1=0x000000080
toto2=0x000000100
toto3=0x000000200
titi2=0x000000400
titi3=0x000000800
tito0=0x000001000
tito1=0x000002000
tito2=0x000004000
tito3=0x000008000
tito4=0x000010000
I would like to implement a second function name GetConfig() which must return an uint32 value. Based on this value, I would to quote the associated variable. If I enter 300 I should display toto2 toto3.
function Config()
{
vartest=$1
if [ -f $file ]; then
while read lines
do
value=${lines##*=}
mask=$(($vartest & $value))
echo $mask
done < $file
else
exitError 101
fi
}
If I enter ./script Config 3840 I obtain :
0
0
0
0
0
0
0
0
256
512
1024
2048
0
0
0
0
0
I can easily display toto2 toto3 titi5 titii, but if I enter ./script Config 4812, I obtain :
0
0
4
8
0
0
64
128
0
512
0
0
4096
0
0
0
0
This result can not allows me to display var1 titi titii test1
I am not sure to be clear but I am really currently blocked on this mask issue.
Thank in advance
Your problem statement isn't very clear but I hope this snippet can help put you back on track. The real meat is in using ${lines%=*} to obtain the key corresponding to the value in this lines.
Config() {
vartest=$1
if [ -f $file ]; then
while read lines
do
value=${lines##*=}
test $(($vartest & $value)) = 0 && continue
echo "${lines%=*}"
done < $file
else
exitError 101
fi
}
file=/dev/stdin
Config 3840 <<':'
var=0x000000001
var1=0x000000002
var2=0x000000004
var3=0x000000008
toto=0x000000010
titi=0x000000020
tata=0x000000040
toto1=0x000000080
toto2=0x000000100
toto3=0x000000200
titi2=0x000000400
titi3=0x000000800
tito0=0x000001000
tito1=0x000002000
tito2=0x000004000
tito3=0x000008000
tito4=0x000010000
:
Test run:
toto2
toto3
titi2
titi3
I would expect a more-useful function to not require the values in a file; this incidentally also illustrates how to put them in a here document (I did some weird stuff to not have to change those parts of your function).