devexpress asp.net pdf viewer : Delete page from pdf acrobat control SDK system azure wpf winforms console AppleShellScripting-20149-part692

Youwillnoticethatthesecondscriptchangedthevalueofavariablethatwaslocaltothefirstscript.Unlike
executingascriptasanormalshellcommand,executingascriptwiththe
source
builtinresultsinthesecond
scriptexecutingwithinthesameoverallcontextasthefirstscript.Anyvariablesthataremodifiedbythesecond
scriptwillbeseenbythecallingscript.Whilethiscanbeverypowerful,itiseasytoclobbervariablesifyou
aren'tcareful.
C Shell Note:  TheCshellsupportsthe
source
builtin,butdoesnotsupporttheperiodform(
.
).
FindingtheAbsolutePathoftheCurrentScript
Occasionally,youmaywriteascriptthatneedstoexecuteitselforneedstosourceasubroutinelibraryinthe
samedirectory.Whenyoudo,itcanbeusefultoobtaintheabsolutepathofthescriptitself.
Theshellvariable
$0
containsthenamepassedinonthecommandline.Ifthescriptwasexecutedwithan
absolutepath,thisisallyouneed.However,ifthescriptisinadirectorycontainedinthe
PATH
environment
variable,thismaycontainnothingmorethanthenameofthescript.
Toobtaintheactualpathofthescript,youmusttakeadvantageoftheshell’sabilitytosearchthroughthe
locationsinthe
PATH
variable.Thefollowingsnippetreturnsthepathoftheexecutingscript.Thispathmay
berelativetothecurrentworkingdirectory.
SCRIPT="$(which $0)"
Yourscriptcanthenexecuteitselflikethis:
"$SCRIPT" arguments go here
Youcangetacompleteabsolutepathbyaddingafewmorelines:
SCRIPT="$(which $0)"
if [ "x$(echo $SCRIPT | grep '^\/')" = "x" ] ; then
SCRIPT="$PWD/$SCRIPT"
fi
Ifthepathstartswithaleadingslash(
/
),itisalreadyanabsolutepath,soyoudon’tneedtodoanythingtoit.
Ifitdoesnot,prependingthecurrentworkingdirectoryturnsitintoone.
Subroutines,Scoping,andSourcing
IncludingOneShellScriptInsideAnother(Sourcing)
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
91
Delete page from pdf acrobat - control SDK system:C# PDF Page Extract Library: copy, paste, cut PDF pages in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
Easy to Use C# Code to Extract PDF Pages, Copy Pages from One PDF File and Paste into Others
www.rasteredge.com
Delete page from pdf acrobat - control SDK system:VB.NET PDF Page Extract Library: copy, paste, cut PDF pages in vb.net, ASP.NET, MVC, Ajax, WinForms, WPF
Detailed VB.NET Guide for Extracting Pages from Microsoft PDF Doc
www.rasteredge.com
Note:  Thisresultisnotaminimizedabsolutepath;itmaycontainreferencestothecurrent(
.
)or
enclosing(
..
)directories.Itis,however,anabsolutepaththatiswillnotbreakevenifyourscript
changesdirectoriesormodifiesits
PATH
environmentvariable.
Subroutines,Scoping,andSourcing
IncludingOneShellScriptInsideAnother(Sourcing)
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
92
control SDK system:.NET PDF Document Viewing, Annotation, Conversion & Processing
Edit, update, delete PDF annotations from PDF file. Print. Support for all the print modes in Acrobat PDF. Print only specified page ranges.
www.rasteredge.com
control SDK system:C# PDF Converter Library SDK to convert PDF to other file formats
using other external third-party dependencies like Adobe Acrobat. to image or document, or from PDF document to other file formats, like multi-page TIFF file
www.rasteredge.com
Usingmathinshellscriptsisoneareathatisoftenignoredbyshellscriptingdocumentation—probablybecause
sofewpeopleactuallyunderstandthesubject.Shellscriptsweredesignedmoreforstring-basedprocessing,
withnumericalcomputationasabitofanafterthought,sothisshouldcomeasnosurprise.
Thischaptermainlycoversbasicintegermathoperationsinshellscripts.Morecomplicatedmathislargely
beyondtheabilityofshellscriptingingeneral,thoughyoucandosuchmaththroughtheuseofinlinePerl
scriptsorbyrunningthe
bc
command.ThesetwotechniquesaredescribedinBeyondBasicMath (page 98).
TheexprCommandAlsoDoesMath
Inshellscripts,numericcalculationsaredoneusingthecommand
expr
.Thiscommandtakesaseriesof
arguments,eachofwhichmustcontainasingletokenfromtheexpressiontobeevaluated.Eachnumber,or
symbolmustthusbeaseparateargument.
Forexample,theexpression
(3*4)+2
iswrittenas:
expr '(' '3' '*' '4' ')' '+' '2'
Thecommandwillprinttheresult(
14
)toitsstandardoutput,
Note:  Eachargumentinthisexampleissurroundedbysinglequotes.Thispreventstheshellfrom
tryingtointerpretthecontentsoftheargument.Certainthingslikeparenthesesandcomparison
operatorshavespecialmeaningtotheshell,sowithoutthesesinglequotes,thecommandwould
notbehaveasexpected.
Ifanargumentcontainsashellvariable,doublequotesmustbeusedbecauseshellvariablesinside
singlequotesarenotexpandedatall.Thusinsomecases,youwillseeexamplesinthischapter
containingdoublequotes.However,forsimplicity,theexamplesinthischapterwillgenerallyuse
singlequotesunlessthereisaspecificreasonthatdoublequotesarenecessary.
Fornumericalcomparisons,thesamebasicsyntaxisused.Totestthetruthoftheinequality
3 < -2
,usethe
followingstatement:
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
93
Paint by Numbers
control SDK system:C# powerpoint - PowerPoint Conversion & Rendering in C#.NET
without using other external third-party dependencies like Adobe Acrobat. PowerPoint to PDF Conversion. This page will tell you how to use XDoc.PowerPoint SDK
www.rasteredge.com
control SDK system:C# Word - Word Conversion in C#.NET
independently, without using other external third-party dependencies like Adobe Acrobat. Word to PDF Conversion. This page will tell you how to use XDoc.Word
www.rasteredge.com
expr '3' '<' '-2'
Thiswillreturnazero(
0
)becausethestatementisnottrue.Ifitweretrue,itwouldreturnaone(
1
).
Warning:  Thismathematicalexpressionoftrueisexactlytheoppositeofthatreturnedbythe
commands
true
and
false
.Thisdifferenceisoftenconfusingtopeoplewhoarenewtoshellscripting.
Thevaluesreturnedby
true
and
false
areintendedtorepresentreturnvaluesforshellscriptsand
command-linetools,notnumericalcomputation.Command-linetoolsandscriptstypicallyreturn0
onsuccess,1onaninvalidargument,oranegativevalueforseriousfailures.Youshouldavoid
comparingtheresultsreturnedby
expr
withthereturnvalueof
true
or
false
.
Themostcommonplacetousethiscommandisaspartofaloopinashellscript.Whatfollowsisasimple
exampleofafor-nextloopwritteninashellscript:
COUNT=0
while [ $COUNT -lt '4' ] ; do
echo "COUNT IS $COUNT"
COUNT="$(expr "$COUNT" '+' '1')"
done
ThisscriptisequivalenttothefollowingbitofC:
int i;
for (i=0; i<4; i++) {
printf("COUNT IS %d\n", i);
}
Note:  The
expr
commandcanalsobeusedforstringcomparison.Thisuseisdescribedinthe
similarlytitledsectionTheexprCommand (page 58)inShellScriptBasics (page 21).
TheEasyWay:Parentheses
Anotherwaytodomathoperationsin
some
Bourneshelldialectsiswithdoubleparenthesesinline.The
examplebelowillustratesthistechnique:
PaintbyNumbers
TheEasyWay:Parentheses
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
94
control SDK system:VB.NET PDF: How to Create Watermark on PDF Document within
or image (such as business's logo) on any desired PDF page. And with our PDF Watermark Creator, users need no external application plugin, like Adobe Acrobat.
www.rasteredge.com
control SDK system:C# Windows Viewer - Image and Document Conversion & Rendering in
standard image and document in .NET class applications independently, without using other external third-party dependencies like Adobe Acrobat. Convert to PDF.
www.rasteredge.com
echo $((3 + 4))
Thisformismucheasiertousethanthe
expr
commandbecauseitissomewhatlessstrictintermsofformatting.
Inparticular,withtheexceptionofvariabledecoding,shellexpansionisdisabled.Thus,operatorslikelessthan
andgreaterthandonotneedtobequoted.
Thisformisnotwithoutitsproblems,however.Inparticular,itisnotasbroadlycompatibleastheuseof
expr
.
ThisformisanextensionaddedbytheKornshell(
ksh
),andlateradoptedbytheZshell(
zsh
)andtheBourne
Againshell(
bash
).InapureBourneshellenvironment,thissyntaxwillprobablyfail.
WhilemostmodernUNIX-basedandUNIX-likeoperatingsystemsuseBASHtoemulatetheBourneshell,ifyou
aretryingtowritescriptsthataremoregenerallyusable,youshoulduse
expr
todointegermath,asdescribed
inTheexprCommandAlsoDoesMath (page 93).
CommonMistakes
Asmentionedin,ShellScriptBasics (page 21),theshellscriptinglanguagecontainsbasicequalitytesting
withouttheuseofthe
expr
command.Forexample:
if [ 1 = 2 ] ; then
echo "equal"
else
echo "not equal"
fi
Thiscodewillworkasexpected.However,itisn'tdoingwhatyoumightinitiallythinkitisdoing;itisperforming
astringcomparison,notanumericcomparison.Thusthefollowingcodewillnotbehavethewayyoumight
expectifyouassumedanumericalcomparison:
if [ 1 = "01" ] ; then
echo "equal"
else
echo "not equal"
fi
Itwillprintthewords"notequal",asthestrings"1"and"01"arenotthesamestring.
PaintbyNumbers
CommonMistakes
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
95
control SDK system:C# Excel - Excel Conversion & Rendering in C#.NET
independently, without using other external third-party dependencies like Adobe Acrobat. Excel to PDF Conversion. This page will tell you how to use XDoc.Excel
www.rasteredge.com
control SDK system:VB.NET PowerPoint: VB Code to Draw and Create Annotation on PPT
other documents are compatible, including PDF, TIFF, MS platform-friendly, this .NET PPT page annotating component more plug-ins needed like Acrobat or Adobe
www.rasteredge.com
Warning:  Donotinadvertentlyperformaredirectinsteadofaninequalitytest.Takethefollowing
codeforexample:
if [ 2 > 3 ] ; then
echo greater
fi
Thiswillbetrueeventhoughthecomparisonshouldbefalsebecausenocomparisonistakingplace.Instead,
thislineofcodeisactuallyredirectingtheoutputofthebracketcommand(anemptystring)intoafilecalled3,
whichisprobablynotwhatyouwant.
Thesamethingoccursifyouusetheexprcommandwithoutenclosingthelessthanorgreaterthanoperators
inquotes.
C Shell Note:  TheCshellmakesthisevenmoredifficult,asitdoesnotprovideoperatorsfornumerical
equalityatall.Instead,youmustdoatestlikethis:
if ($A <= $B && !($A < B))
Thiscanalsobeaproblemevenwhenworkingwiththe
expr
commandifyourscripttakesuserinput.The
expr
commandexpectsanumberorsymbolperargument.Ifyoufeeditsomethingthatisn'tjustanumber
orsymbol,itwilltreatitasastring,andwillperformstringcomparisoninsteadofnumericcomparison.
Thefollowingcodedemonstratesthisinaction:
expr '1' '+' '2'
expr ' 1' '+' '2'
expr '2' '<' '1'
expr ' 2' '<' '1'
Thefirstlinewillprintthenumber
3
.Thesecondlineproducesanerrormessage.Whendoingaddition,this
mistakeiseasytodetect.Whendoingcomparisons,however,asshowninthefollowingtwolines,theresults
aremoreinsidious.Thenumber
2
isclearlygreaterthanthenumber
1
.Instringcomparison,however,aspace
sortsbeforeanyletterornumber.Thus,thethirdlineprintsa
0
,whilethefourthlineprintsa
1
.Thisisprobably
notwhatyouwant.
PaintbyNumbers
CommonMistakes
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
96
Aswithmostthingsinshellscripting,therearemanywaystosolvethisproblem,dependingonyourneeds.
Ifyouareonlyworriedaboutspaces,andifthepurposeforthecomparisonistocontrolshellexecution,you
canusethenumericevaluationroutinesbuiltinto
test
,asdescribedinthe
test
manpage.
Forexample:
MYNUMBER=" 2" # Note this is a string, not a number.
# Force an integer comparison.
if [ "$MYNUMBER" -gt '1' ] ; then
echo 'greater'
fi
However,whilethisworksfortrivialcases,thereareanumberofplaceswherethisisnotsufficient.Forexample,
thiscannotbeusedif:
Floatingpointcomparisonisneeded(asdescribedinBeyondBasicMath (page 98)).
Thevalueisprecededbyadollarsignorsimilar.
Theintendeduseisasanumericaltruthvalueinamorecomplicatedmathematicalexpression(without
splittingtheexpression).
Acommonwaytosolvesuchproblemsistoprocesstheargumentswitharegularexpression.Forexample,
tostripanynonnumericcharactersfromanumber,youcoulddothefollowing:
MYRAWNUMBER=" 2" # Note this is a string, not a number.
# Strip off any characters that aren't in the range of 0-9
MYNUMBER="$(echo "$MYRAWNUMBER" | sed 's/[^0-9]//g')"
expr "$MYNUMBER" '<' '1'
Thisresultsinacomparisonbetweenthenumber
2
andthenumber
1
,asexpected.
Formoreinformationonregularexpressions,seeRegularExpressionsUnfettered (page 100).
PaintbyNumbers
CommonMistakes
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
97
BeyondBasicMath
Theshellscriptinglanguageprovidesonlythemostbasicmathematicaloperationsonintegervalues.Inmost
cases,integeroperationsaresufficient.However,sometimesyoumayneedtoexceedthoselimitationsto
performmorecomplicatedmathematicaloperations.
Therearetwomainwaystodofloatingpointmath(andother,moresophisticatedmath).Thefirstisthrough
theuseofinlinePerlcode,thesecondisthroughtheuseofthe
bc
command.Thissectionpresentsbothforms
briefly.
FloatingPointMathUsingInlinePerl
Thefirstmethodofdoingshellfloatingpointmath,inlinePerl,istheeasiesttograsp.Tousethismethod,you
essentiallywriteashortPerlscript,thensubstituteshellvariablesintothescript,thenpassittothe
perl
interpreter,eitherbywritingittoafileorbypassingitinasacommand-lineargument.
Note:  LengthlimitationsapplywhenpassinginaPerlscriptbywayofacommandlineargument.
TheexactlimitationsvaryfromoneOStoanother,butaregenerallyinthetensofkilobytes.Ifyour
scriptneedstobelonger,itshouldbewrittenouttoafile.
ThefollowingexampledemonstratesbasicfloatingpointmathusinginlinePerl.Itassumesabasicunderstanding
ofthePerlprogramminglanguage.
#!/bin/sh
PI=3.141592654
RAD=7
AREA=$(perl -e "print \"The value is \".($PI * ($RAD*$RAD)).\"\n\";")
echo $AREA
Undernormalcircumstances,youprobablydonotwanttoprintanentirestringwhendoingthis.However,
theuseofthestringwastodemonstrateanimportantpoint.Perlevaluatesstringsbetweensingleanddouble
quotemarksdifferently,sowhendoinginlinePerl,itisoftennecessarytousedoublequotes.However,the
shellonlyevaluatesshellvariableswithindoublequotes.Thus,thedoublequotemarksinthescriptmustbe
quotedsothattheyactuallygetpassedtothePerlinterpreterinsteadofendingorbeginningnewcommand-line
arguments.
PaintbyNumbers
BeyondBasicMath
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
98
Thisneedforquotingcanprovetobeachallengeformorecomplexinlinecode,particularlywhenregular
expressionsisinvolved.Inparticular,itcanoftenbetrickyfiguringouthowmanybackslashestousewhen
quotingthequotingofaquotationmarkwithinaregularexpression.Suchissuesarebeyondthescopeofthis
document,however.
FloatingPointMathUsingthebcCommand
The
bc
command,shortforbasiccalculator,isaPOSIXcommandfordoingvariousmathematicaloperations.
The
bc
commandoffersarbitraryprecisionfloatingpointmath,alongwithabuilt-inlibraryofcommon
mathematicalfunctionstomakeprogrammingeasier.
Cross-Platform Compatibility Note:  Themostcommonversionof
bc
(andtheoneincludedinOS
X)isGNU
bc
,whichoffersanumberofextensionsbeyondthoseavailableinthePOSIXversion.For
cross-platformcompatibility,youshouldgenerallyavoidtheseextensionsifpossible.Ifyouspecify
the
-s
flagtoGNU
bc
,itwilldisabletheGNUextensionsandwillthusemulatethePOSIXversion.
The
bc
commandtakesitsinputfromitsstandardinput,notfromthecommandline.Ifyoupassitcommand
linearguments,theyareinterpretedasfilenamestobeexecuted,whichisprobablynotwhatyouwanttodo
whenexecutingmathoperationsinlineinashellsscript.
Hereisanexampleofusing
bc
inashellscript:
#!/bin/sh
PI=3.141592654
RAD=7
AREA=$(echo "$PI * ($RAD ^ 2)" | bc)
echo "The area is $AREA"
The
bc
commandoffersmuchmorefunctionalitythandescribedinthissection.Thissectionisonlyintended
asabriefsynopsisoftheavailablefunctionality.Forfullusagenotes,seethemanpagefor
bc
.
PaintbyNumbers
BeyondBasicMath
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
99
Regularexpressionsareapowerfulmechanismfortextprocessing.Youcanuseregularexpressionstosearch
forapatternwithinablockoftext,toreplacebitsofthattextwithotherbitsoftext,andtomanipulatestrings
invariousothersubtleandinterestingways.
Theshellitselfdoesnotsupportregularexpressionsnatively.Touseregularexpressions,youmustinvokean
externaltool.
Sometoolsthatsupportregularexpressionsinclude:
awk
—Ascriptinglanguageinandofitself.DescribedfurtherinHowAWK-ward (page 122).
grep
—Returnsthelistoflinesthatmatchanexpression(orthelinesthatdonotmatchwiththe
-v
flag).
Exitswithastatusoftrue(0)ifamatchoccurredorfalse(1)ifnomatchoccurred.
perl
—Ascriptinglanguagewithmoreadvancedregularexpressionfunctionality.
sed
—Atoolthatperformstextsubstitutionsbasedonregularexpressions.
Youwillseethesecommandsusedthroughoutthischapter.
Forthepurposesofthischapter,youshouldpastethefollowinglinesoftextintoatextfilewithUNIXline
endings(newline):
Mary had a little lamb,
its fleece was white as snow,
and everywhere that Mary went,
the lamb was sure to go.
A few more lines to confuse things:
Marylamb had a little.
This is a test.
This is only a test.
Mary was married.
A lamb was nearby.
Mary, a little lamb, and my grocer's freezer...
Mary a lamb.
Marry a lamb.
Mary had a lamb looked like a lamb.
2014-03-10   |   Copyright © 2003, 2014 Apple Inc. All Rights Reserved.
100
Regular Expressions Unfettered
Documents you may be interested
Documents you may be interested