ParamConverter.cs 126 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164
  1. using ComPDFKit.Import;
  2. using ComPDFKit.Measure;
  3. using ComPDFKit.PDFAnnotation;
  4. using ComPDFKit.PDFAnnotation.Form;
  5. using ComPDFKit.PDFDocument;
  6. using ComPDFKit.PDFDocument.Action;
  7. using ComPDFKit.PDFPage;
  8. using ComPDFKit.PDFPage.Edit;
  9. using ComPDFKit.Tool.SettingParam;
  10. using ComPDFKit.Tool.UndoManger;
  11. using ComPDFKit.Viewer.Helper;
  12. using System.Collections.Generic;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Windows;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using static ComPDFKit.PDFAnnotation.CTextAttribute;
  19. using static ComPDFKit.PDFAnnotation.CTextAttribute.CFontNameHelper;
  20. namespace ComPDFKit.Tool.Help
  21. {
  22. /// <summary>
  23. /// Some quick conversion tools for parameters
  24. /// </summary>
  25. public static class ParamConverter
  26. {
  27. public enum FormField
  28. {
  29. /// <summary>
  30. /// Visible
  31. /// </summary>
  32. Visible,
  33. /// <summary>
  34. /// Hidden
  35. /// </summary>
  36. Hidden,
  37. /// <summary>
  38. /// Visible but unprintable
  39. /// </summary>
  40. VisibleNoPrint,
  41. /// <summary>
  42. /// Hidden but printable
  43. /// </summary>
  44. HiddenPrintable
  45. }
  46. public static AnnotHistory CreateHistory(CPDFAnnotation cPDFAnnotation)
  47. {
  48. AnnotHistory annotHistory = null;
  49. switch (cPDFAnnotation.Type)
  50. {
  51. case C_ANNOTATION_TYPE.C_ANNOTATION_NONE:
  52. break;
  53. case C_ANNOTATION_TYPE.C_ANNOTATION_UNKOWN:
  54. break;
  55. case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
  56. annotHistory = new StickyNoteAnnotHistory();
  57. break;
  58. case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
  59. annotHistory = new LinkAnnotHistory();
  60. break;
  61. case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
  62. annotHistory = new FreeTextAnnotHistory();
  63. break;
  64. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  65. if ((cPDFAnnotation as CPDFLineAnnotation).IsMeasured())
  66. {
  67. annotHistory = new LineMeasureAnnotHistory();
  68. }
  69. else
  70. {
  71. annotHistory = new LineAnnotHistory();
  72. }
  73. break;
  74. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
  75. annotHistory = new SquareAnnotHistory();
  76. break;
  77. case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
  78. annotHistory = new CircleAnnotHistory();
  79. break;
  80. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  81. annotHistory = new PolygonMeasureAnnotHistory();
  82. break;
  83. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  84. annotHistory = new PolyLineMeasureAnnotHistory();
  85. break;
  86. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  87. annotHistory = new HighlightAnnotHistory();
  88. break;
  89. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  90. annotHistory = new UnderlineAnnotHistory();
  91. break;
  92. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  93. annotHistory = new SquigglyAnnotHistory();
  94. break;
  95. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  96. annotHistory = new StrikeoutAnnotHistory();
  97. break;
  98. case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
  99. annotHistory = new StampAnnotHistory();
  100. break;
  101. case C_ANNOTATION_TYPE.C_ANNOTATION_CARET:
  102. break;
  103. case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
  104. annotHistory = new InkAnnotHistory();
  105. break;
  106. case C_ANNOTATION_TYPE.C_ANNOTATION_POPUP:
  107. break;
  108. case C_ANNOTATION_TYPE.C_ANNOTATION_FILEATTACHMENT:
  109. break;
  110. case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
  111. annotHistory = new SoundAnnotHistory();
  112. break;
  113. case C_ANNOTATION_TYPE.C_ANNOTATION_MOVIE:
  114. break;
  115. case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
  116. switch ((cPDFAnnotation as CPDFWidget).WidgetType)
  117. {
  118. case C_WIDGET_TYPE.WIDGET_NONE:
  119. break;
  120. case C_WIDGET_TYPE.WIDGET_PUSHBUTTON:
  121. annotHistory = new PushButtonHistory();
  122. break;
  123. case C_WIDGET_TYPE.WIDGET_CHECKBOX:
  124. annotHistory = new CheckBoxHistory();
  125. break;
  126. case C_WIDGET_TYPE.WIDGET_RADIOBUTTON:
  127. annotHistory = new RadioButtonHistory();
  128. break;
  129. case C_WIDGET_TYPE.WIDGET_TEXTFIELD:
  130. annotHistory = new TextBoxHistory();
  131. break;
  132. case C_WIDGET_TYPE.WIDGET_COMBOBOX:
  133. annotHistory = new ComboBoxHistory();
  134. break;
  135. case C_WIDGET_TYPE.WIDGET_LISTBOX:
  136. annotHistory = new ListBoxHistory();
  137. break;
  138. case C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS:
  139. annotHistory = new SignatureHistory();
  140. break;
  141. case C_WIDGET_TYPE.WIDGET_UNKNOWN:
  142. break;
  143. default:
  144. break;
  145. }
  146. break;
  147. case C_ANNOTATION_TYPE.C_ANNOTATION_SCREEN:
  148. break;
  149. case C_ANNOTATION_TYPE.C_ANNOTATION_PRINTERMARK:
  150. break;
  151. case C_ANNOTATION_TYPE.C_ANNOTATION_TRAPNET:
  152. break;
  153. case C_ANNOTATION_TYPE.C_ANNOTATION_WATERMARK:
  154. break;
  155. case C_ANNOTATION_TYPE.C_ANNOTATION_3D:
  156. break;
  157. case C_ANNOTATION_TYPE.C_ANNOTATION_RICHMEDIA:
  158. break;
  159. case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
  160. annotHistory = new RedactAnnotHistory();
  161. break;
  162. case C_ANNOTATION_TYPE.C_ANNOTATION_INTERCHANGE:
  163. break;
  164. default:
  165. break;
  166. }
  167. return annotHistory;
  168. }
  169. public static bool RemovePageAnnot(Dictionary<int, List<int>> removeAnnots, CPDFDocument cPDFDocument)
  170. {
  171. if (cPDFDocument == null || removeAnnots.Count <= 0)
  172. {
  173. return false;
  174. }
  175. foreach (int pageIndex in removeAnnots.Keys)
  176. {
  177. CPDFPage pageCore = cPDFDocument.PageAtIndex(pageIndex);
  178. List<CPDFAnnotation> cPDFAnnotations = pageCore.GetAnnotations();
  179. foreach (int annotIndex in removeAnnots[pageIndex])
  180. {
  181. CPDFAnnotation cPDFAnnotation = cPDFAnnotations.ElementAtOrDefault(annotIndex);
  182. if (cPDFAnnotation != null)
  183. {
  184. cPDFAnnotation.RemoveAnnot();
  185. }
  186. }
  187. }
  188. return false;
  189. }
  190. public static FormField ConverterWidgetFormFlags(int Flags, bool IsHidden)
  191. {
  192. int flag = Flags;
  193. bool invisible = (flag & (int)CPDFAnnotationFlags.CPDFAnnotationFlagInvisible) != 0;
  194. bool noview = (flag & (int)CPDFAnnotationFlags.CPDFAnnotationFlagNoView) != 0;
  195. bool print = (flag & (int)CPDFAnnotationFlags.CPDFAnnotationFlagPrint) != 0;
  196. if (noview && print)
  197. {
  198. return FormField.HiddenPrintable;
  199. }
  200. if (IsHidden || noview || invisible)
  201. {
  202. return FormField.Hidden;
  203. }
  204. bool visibleflag = !IsHidden && !invisible && !noview && !print;
  205. if (visibleflag)
  206. {
  207. return FormField.VisibleNoPrint;
  208. }
  209. return FormField.Visible;
  210. }
  211. public static int GetFormFlags(FormField field, CPDFWidget widget)
  212. {
  213. int flag = widget.GetFlags();
  214. switch (field)
  215. {
  216. case FormField.Hidden:
  217. widget.SetIsHidden(true);
  218. flag = widget.GetFlags();
  219. break;
  220. case FormField.Visible:
  221. {
  222. int newflag = (int)CPDFAnnotationFlags.CPDFAnnotationFlagNoView | (int)CPDFAnnotationFlags.CPDFAnnotationFlagHidden
  223. | (int)CPDFAnnotationFlags.CPDFAnnotationFlagInvisible;
  224. flag &= ~newflag;
  225. flag |= (int)CPDFAnnotationFlags.CPDFAnnotationFlagPrint;
  226. }
  227. break;
  228. case FormField.VisibleNoPrint:
  229. {
  230. int newflag = (int)CPDFAnnotationFlags.CPDFAnnotationFlagNoView | (int)CPDFAnnotationFlags.CPDFAnnotationFlagPrint |
  231. (int)CPDFAnnotationFlags.CPDFAnnotationFlagHidden | (int)CPDFAnnotationFlags.CPDFAnnotationFlagInvisible;
  232. flag &= ~newflag;
  233. }
  234. break;
  235. case FormField.HiddenPrintable:
  236. {
  237. flag = flag | (int)CPDFAnnotationFlags.CPDFAnnotationFlagNoView | (int)CPDFAnnotationFlags.CPDFAnnotationFlagPrint;
  238. }
  239. break;
  240. default:
  241. break;
  242. }
  243. return flag;
  244. }
  245. public static Color ConverterByteForColor(byte[] bytes)
  246. {
  247. if (bytes != null && bytes.Length == 3)
  248. {
  249. return new Color { R = bytes[0], G = bytes[1], B = bytes[2], A = 255};
  250. }
  251. return new Color { R = 0, G = 0, B = 0, A = 0 };
  252. }
  253. public static void ParseDashStyle(DashStyle dashStyle, out float[] LineDash, out C_BORDER_STYLE BorderStyle)
  254. {
  255. if (dashStyle == DashStyles.Solid || dashStyle == null)
  256. {
  257. LineDash = new float[0];
  258. BorderStyle = C_BORDER_STYLE.BS_SOLID;
  259. }
  260. else
  261. {
  262. List<float> floatArray = new List<float>();
  263. foreach (double num in dashStyle.Dashes)
  264. {
  265. floatArray.Add((float)num);
  266. }
  267. LineDash = floatArray.ToArray();
  268. BorderStyle = C_BORDER_STYLE.BS_DASHDED;
  269. }
  270. }
  271. public static AnnotParam CPDFDataConverterToAnnotParam(CPDFDocument cPDFDocument, int PageIndex, CPDFAnnotation cPDFAnnotation)
  272. {
  273. if (cPDFAnnotation == null && !cPDFAnnotation.IsValid() && cPDFDocument == null && !cPDFDocument.IsValid())
  274. {
  275. return null;
  276. }
  277. AnnotParam annotParam = null;
  278. if (cPDFAnnotation.Type == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
  279. {
  280. annotParam = WidgetConverter(cPDFDocument, cPDFAnnotation);
  281. }
  282. else
  283. {
  284. annotParam = AnnotConverter(cPDFDocument, cPDFAnnotation);
  285. }
  286. if (annotParam != null)
  287. {
  288. annotParam.PageIndex = PageIndex;
  289. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(annotParam.PageIndex, false);
  290. List<CPDFAnnotation> cPDFAnnotations = cPDFPage.GetAnnotations();
  291. annotParam.AnnotIndex = cPDFAnnotations.IndexOf(cPDFAnnotation);
  292. }
  293. return annotParam;
  294. }
  295. public static PDFEditParam CPDFDataConverterToPDFEitParam(CPDFDocument cPDFDocument, CPDFEditArea cPDFEditArea, int pageIndex)
  296. {
  297. PDFEditParam annotParam = null;
  298. if (cPDFEditArea == null && !cPDFEditArea.IsValid() && cPDFDocument == null && !cPDFDocument.IsValid() && pageIndex >= 0)
  299. {
  300. return null;
  301. }
  302. switch (cPDFEditArea.Type)
  303. {
  304. case CPDFEditType.None:
  305. break;
  306. case CPDFEditType.EditText:
  307. annotParam = GetTextEditParam(cPDFDocument, cPDFEditArea as CPDFEditTextArea, pageIndex);
  308. break;
  309. case CPDFEditType.EditImage:
  310. annotParam = GetImageEditParam(cPDFDocument, cPDFEditArea as CPDFEditImageArea, pageIndex);
  311. break;
  312. case CPDFEditType.EditPath:
  313. annotParam = GetPathEditParam(cPDFDocument, cPDFEditArea as CPDFEditPathArea, pageIndex);
  314. break;
  315. default:
  316. break;
  317. }
  318. return annotParam;
  319. }
  320. #region PDFEdit
  321. internal static TextEditParam GetTextEditParam(CPDFDocument cPDFDocument, CPDFEditTextArea cPDFEditArea, int pageIndex)
  322. {
  323. TextEditParam textEditParam = new TextEditParam();
  324. string fontName = "Helvetica";
  325. float fontSize = 14;
  326. byte[] fontColor = {0,0,0};
  327. byte transparency = 255;
  328. bool isBold = false;
  329. bool isItalic = false;
  330. cPDFEditArea.GetTextStyle(ref fontName,ref fontSize, ref fontColor, ref transparency, ref isBold, ref isItalic);
  331. textEditParam.FontName = fontName;
  332. textEditParam.FontSize = fontSize;
  333. textEditParam.FontColor = fontColor;
  334. textEditParam.Transparency = transparency;
  335. textEditParam.TextAlign = cPDFEditArea.GetTextSectionAlign();
  336. textEditParam.EditType = CPDFEditType.EditText;
  337. CPDFPage docPage = cPDFDocument.PageAtIndex(pageIndex);
  338. CPDFEditPage editPage = docPage.GetEditPage();
  339. textEditParam.EditIndex = editPage.GetEditAreaList().IndexOf(cPDFEditArea);
  340. textEditParam.PageIndex = pageIndex;
  341. if(string.IsNullOrEmpty(cPDFEditArea.SelectText))
  342. {
  343. textEditParam.IsBold = isBold;
  344. textEditParam.IsItalic = isItalic;
  345. }
  346. else
  347. {
  348. textEditParam.IsBold = cPDFEditArea.IsCharsFontBold();
  349. textEditParam.IsItalic = cPDFEditArea.IsCharsFontItalic();
  350. }
  351. return textEditParam;
  352. }
  353. internal static ImageEditParam GetImageEditParam(CPDFDocument cPDFDocument, CPDFEditImageArea cPDFEditArea, int pageIndex)
  354. {
  355. ImageEditParam imageEditParam = new ImageEditParam();
  356. imageEditParam.Transparency = cPDFEditArea.GetImageTransparency();
  357. imageEditParam.EditType = CPDFEditType.EditImage;
  358. CPDFPage docPage = cPDFDocument.PageAtIndex(pageIndex);
  359. CPDFEditPage editPage = docPage.GetEditPage();
  360. imageEditParam.EditIndex = editPage.GetEditAreaList().IndexOf(cPDFEditArea);
  361. imageEditParam.PageIndex = pageIndex;
  362. return imageEditParam;
  363. }
  364. internal static PathEditParam GetPathEditParam(CPDFDocument cPDFDocument, CPDFEditPathArea cPDFEditArea, int pageIndex)
  365. {
  366. PathEditParam pathEditParam = new PathEditParam();
  367. pathEditParam.Transparency = cPDFEditArea.GetTransparency();
  368. pathEditParam.EditType = CPDFEditType.EditImage;
  369. CPDFPage docPage = cPDFDocument.PageAtIndex(pageIndex);
  370. CPDFEditPage editPage = docPage.GetEditPage();
  371. pathEditParam.EditIndex = editPage.GetEditAreaList().IndexOf(cPDFEditArea);
  372. pathEditParam.PageIndex = pageIndex;
  373. return pathEditParam;
  374. }
  375. #endregion
  376. #region Widegt
  377. internal static AnnotParam WidgetConverter(CPDFDocument document, CPDFAnnotation cPDFAnnotation)
  378. {
  379. AnnotParam annotParam = null;
  380. if (cPDFAnnotation is CPDFWidget)
  381. {
  382. switch ((cPDFAnnotation as CPDFWidget).WidgetType)
  383. {
  384. case C_WIDGET_TYPE.WIDGET_NONE:
  385. break;
  386. case C_WIDGET_TYPE.WIDGET_PUSHBUTTON:
  387. annotParam = GetPushButtonParam(document, cPDFAnnotation as CPDFPushButtonWidget);
  388. break;
  389. case C_WIDGET_TYPE.WIDGET_CHECKBOX:
  390. annotParam = GetCheckBoxParam(cPDFAnnotation as CPDFCheckBoxWidget);
  391. break;
  392. case C_WIDGET_TYPE.WIDGET_RADIOBUTTON:
  393. annotParam = GetRadioButtonParam(cPDFAnnotation as CPDFRadioButtonWidget);
  394. break;
  395. case C_WIDGET_TYPE.WIDGET_TEXTFIELD:
  396. annotParam = GetTextBoxParam(cPDFAnnotation as CPDFTextWidget);
  397. break;
  398. case C_WIDGET_TYPE.WIDGET_COMBOBOX:
  399. annotParam = GetComboBoxParam(cPDFAnnotation as CPDFComboBoxWidget);
  400. break;
  401. case C_WIDGET_TYPE.WIDGET_LISTBOX:
  402. annotParam = GetListBoxParam(cPDFAnnotation as CPDFListBoxWidget);
  403. break;
  404. case C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS:
  405. annotParam = GetSignatureParam(cPDFAnnotation as CPDFSignatureWidget);
  406. break;
  407. case C_WIDGET_TYPE.WIDGET_UNKNOWN:
  408. break;
  409. default:
  410. break;
  411. }
  412. }
  413. return annotParam;
  414. }
  415. internal static PushButtonParam GetPushButtonParam(CPDFDocument document, CPDFPushButtonWidget cPDFWidget)
  416. {
  417. PushButtonParam pushButtonParam = null;
  418. if (cPDFWidget != null && cPDFWidget.IsValid())
  419. {
  420. pushButtonParam = new PushButtonParam();
  421. CTextAttribute cTextAttribute = cPDFWidget.GetTextAttribute();
  422. pushButtonParam.IsBold = IsBold(cTextAttribute.FontName);
  423. pushButtonParam.IsItalic = IsItalic(cTextAttribute.FontName);
  424. pushButtonParam.Text = cPDFWidget.GetButtonTitle();
  425. pushButtonParam.FontColor = cTextAttribute.FontColor;
  426. pushButtonParam.FontName = cTextAttribute.FontName;
  427. pushButtonParam.FontSize = cTextAttribute.FontSize;
  428. CPDFAction cPDFAction = cPDFWidget.GetButtonAction();
  429. if (cPDFAction != null)
  430. {
  431. switch (cPDFAction.ActionType)
  432. {
  433. case C_ACTION_TYPE.ACTION_TYPE_URI:
  434. pushButtonParam.Uri = (cPDFAction as CPDFUriAction)?.GetUri();
  435. break;
  436. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  437. CPDFGoToAction gotoAction = cPDFAction as CPDFGoToAction;
  438. CPDFDestination dest = gotoAction.GetDestination(document);
  439. pushButtonParam.DestinationPageIndex = dest.PageIndex;
  440. pushButtonParam.DestinationPosition = new CPoint(dest.Position_X, dest.Position_Y);
  441. break;
  442. default:
  443. break;
  444. }
  445. pushButtonParam.Action = cPDFAction.ActionType;
  446. }
  447. pushButtonParam.WidgetType = cPDFWidget.WidgetType;
  448. pushButtonParam.BorderStyle = cPDFWidget.GetWidgetBorderStyle();
  449. byte[] LineColor = new byte[3];
  450. pushButtonParam.HasLineColor = cPDFWidget.GetWidgetBorderRGBColor(ref LineColor);
  451. pushButtonParam.LineColor = LineColor;
  452. byte[] BgColor = new byte[3];
  453. bool hasBgColor = cPDFWidget.GetWidgetBgRGBColor(ref BgColor);
  454. pushButtonParam.HasBgColor = hasBgColor;
  455. pushButtonParam.BgColor = BgColor;
  456. pushButtonParam.LineWidth = cPDFWidget.GetBorderWidth();
  457. pushButtonParam.FieldName = cPDFWidget.GetFieldName();
  458. pushButtonParam.Flags = cPDFWidget.GetFlags();
  459. pushButtonParam.IsReadOnly = cPDFWidget.GetIsReadOnly();
  460. pushButtonParam.IsHidden = cPDFWidget.GetIsHidden();
  461. GetAnnotCommonParam(cPDFWidget, pushButtonParam);
  462. }
  463. return pushButtonParam;
  464. }
  465. internal static CheckBoxParam GetCheckBoxParam(CPDFCheckBoxWidget cPDFWidget)
  466. {
  467. CheckBoxParam checkBoxParam = null;
  468. if (cPDFWidget != null && cPDFWidget.IsValid())
  469. {
  470. checkBoxParam = new CheckBoxParam();
  471. checkBoxParam.CheckStyle = cPDFWidget.GetWidgetCheckStyle();
  472. checkBoxParam.IsChecked = cPDFWidget.IsChecked();
  473. checkBoxParam.WidgetType = cPDFWidget.WidgetType;
  474. checkBoxParam.BorderStyle = cPDFWidget.GetWidgetBorderStyle();
  475. byte[] LineColor = new byte[3];
  476. checkBoxParam.HasLineColor = cPDFWidget.GetWidgetBorderRGBColor(ref LineColor);
  477. checkBoxParam.LineColor = LineColor;
  478. byte[] BgColor = new byte[3];
  479. bool hasBgColor = cPDFWidget.GetWidgetBgRGBColor(ref BgColor);
  480. checkBoxParam.HasBgColor = hasBgColor;
  481. checkBoxParam.BgColor = BgColor;
  482. CTextAttribute cTextAttribute = cPDFWidget.GetTextAttribute();
  483. checkBoxParam.FontColor = cTextAttribute.FontColor;
  484. checkBoxParam.FontName = cTextAttribute.FontName;
  485. checkBoxParam.FontSize = cTextAttribute.FontSize;
  486. checkBoxParam.LineWidth = cPDFWidget.GetBorderWidth();
  487. checkBoxParam.FieldName = cPDFWidget.GetFieldName();
  488. checkBoxParam.Flags = cPDFWidget.GetFlags();
  489. checkBoxParam.IsReadOnly = cPDFWidget.GetIsReadOnly();
  490. checkBoxParam.IsHidden = cPDFWidget.GetIsHidden();
  491. GetAnnotCommonParam(cPDFWidget, checkBoxParam);
  492. }
  493. return checkBoxParam;
  494. }
  495. internal static RadioButtonParam GetRadioButtonParam(CPDFRadioButtonWidget cPDFWidget)
  496. {
  497. RadioButtonParam radioButtonParam = null;
  498. if (cPDFWidget != null && cPDFWidget.IsValid())
  499. {
  500. radioButtonParam = new RadioButtonParam();
  501. radioButtonParam.CheckStyle = cPDFWidget.GetWidgetCheckStyle();
  502. radioButtonParam.IsChecked = cPDFWidget.IsChecked();
  503. radioButtonParam.WidgetType = cPDFWidget.WidgetType;
  504. radioButtonParam.BorderStyle = cPDFWidget.GetWidgetBorderStyle();
  505. byte[] LineColor = new byte[3];
  506. radioButtonParam.HasLineColor = cPDFWidget.GetWidgetBorderRGBColor(ref LineColor);
  507. radioButtonParam.LineColor = LineColor;
  508. byte[] BgColor = new byte[3];
  509. bool hasBgColor = cPDFWidget.GetWidgetBgRGBColor(ref BgColor);
  510. radioButtonParam.HasBgColor = hasBgColor;
  511. radioButtonParam.BgColor = BgColor;
  512. CTextAttribute cTextAttribute = cPDFWidget.GetTextAttribute();
  513. radioButtonParam.FontColor = cTextAttribute.FontColor;
  514. radioButtonParam.FontName = cTextAttribute.FontName;
  515. radioButtonParam.FontSize = cTextAttribute.FontSize;
  516. radioButtonParam.LineWidth = cPDFWidget.GetBorderWidth();
  517. radioButtonParam.FieldName = cPDFWidget.GetFieldName();
  518. radioButtonParam.Flags = cPDFWidget.GetFlags();
  519. radioButtonParam.IsReadOnly = cPDFWidget.GetIsReadOnly();
  520. radioButtonParam.IsHidden = cPDFWidget.GetIsHidden();
  521. GetAnnotCommonParam(cPDFWidget, radioButtonParam);
  522. }
  523. return radioButtonParam;
  524. }
  525. internal static TextBoxParam GetTextBoxParam(CPDFTextWidget cPDFWidget)
  526. {
  527. TextBoxParam textBoxParam = null;
  528. if (cPDFWidget != null && cPDFWidget.IsValid())
  529. {
  530. textBoxParam = new TextBoxParam();
  531. CTextAttribute cTextAttribute = cPDFWidget.GetTextAttribute();
  532. textBoxParam.Text = cPDFWidget.Text;
  533. textBoxParam.IsMultiLine = cPDFWidget.IsMultiLine;
  534. textBoxParam.IsPassword = cPDFWidget.IsPassword;
  535. textBoxParam.IsItalic = IsItalic(cTextAttribute.FontName);
  536. textBoxParam.IsBold = IsBold(cTextAttribute.FontName);
  537. textBoxParam.Alignment = cPDFWidget.Alignment;
  538. textBoxParam.WidgetType = cPDFWidget.WidgetType;
  539. textBoxParam.BorderStyle = cPDFWidget.GetWidgetBorderStyle();
  540. byte[] LineColor = new byte[3];
  541. textBoxParam.HasLineColor = cPDFWidget.GetWidgetBorderRGBColor(ref LineColor);
  542. textBoxParam.LineColor = LineColor;
  543. byte[] BgColor = new byte[3];
  544. bool hasBgColor = cPDFWidget.GetWidgetBgRGBColor(ref BgColor);
  545. textBoxParam.HasBgColor = hasBgColor;
  546. textBoxParam.BgColor = BgColor;
  547. textBoxParam.FontColor = cTextAttribute.FontColor;
  548. textBoxParam.FontName = cTextAttribute.FontName;
  549. textBoxParam.FontSize = cTextAttribute.FontSize;
  550. textBoxParam.LineWidth = cPDFWidget.GetBorderWidth();
  551. textBoxParam.FieldName = cPDFWidget.GetFieldName();
  552. textBoxParam.Flags = cPDFWidget.GetFlags();
  553. textBoxParam.IsReadOnly = cPDFWidget.GetIsReadOnly();
  554. textBoxParam.IsHidden = cPDFWidget.GetIsHidden();
  555. GetAnnotCommonParam(cPDFWidget, textBoxParam);
  556. }
  557. return textBoxParam;
  558. }
  559. internal static ComboBoxParam GetComboBoxParam(CPDFComboBoxWidget cPDFWidget)
  560. {
  561. ComboBoxParam comboBoxParam = null;
  562. if (cPDFWidget != null && cPDFWidget.IsValid())
  563. {
  564. comboBoxParam = new ComboBoxParam();
  565. CTextAttribute cTextAttribute = cPDFWidget.GetTextAttribute();
  566. comboBoxParam.IsItalic = IsItalic(cTextAttribute.FontName);
  567. comboBoxParam.IsBold = IsBold(cTextAttribute.FontName);
  568. //Support for multiple selections needs to be adjusted later.
  569. CWidgetItem[] cWidgetItem = cPDFWidget.LoadWidgetItems();
  570. CWidgetItem cWidgetItem1 = cPDFWidget.GetSelectedItem();
  571. if (cWidgetItem != null)
  572. {
  573. for (int i = 0; i < cWidgetItem.Length; i++)
  574. {
  575. CWidgetItem item = cWidgetItem[i];
  576. comboBoxParam.OptionItems.Add(item.Value, item.Text);
  577. if (cWidgetItem1 != null && cWidgetItem1.Text == item.Text && cWidgetItem1.Value == item.Value)
  578. {
  579. comboBoxParam.SelectItemsIndex = new List<int> { i };
  580. }
  581. }
  582. }
  583. comboBoxParam.WidgetType = cPDFWidget.WidgetType;
  584. comboBoxParam.BorderStyle = cPDFWidget.GetWidgetBorderStyle();
  585. byte[] LineColor = new byte[3];
  586. comboBoxParam.HasLineColor = cPDFWidget.GetWidgetBorderRGBColor(ref LineColor);
  587. comboBoxParam.LineColor = LineColor;
  588. byte[] BgColor = new byte[3];
  589. bool hasBgColor = cPDFWidget.GetWidgetBgRGBColor(ref BgColor);
  590. comboBoxParam.HasBgColor = hasBgColor;
  591. comboBoxParam.BgColor = BgColor;
  592. comboBoxParam.FontColor = cTextAttribute.FontColor;
  593. comboBoxParam.FontName = cTextAttribute.FontName;
  594. comboBoxParam.FontSize = cTextAttribute.FontSize;
  595. comboBoxParam.LineWidth = cPDFWidget.GetBorderWidth();
  596. comboBoxParam.FieldName = cPDFWidget.GetFieldName();
  597. comboBoxParam.Flags = cPDFWidget.GetFlags();
  598. comboBoxParam.IsReadOnly = cPDFWidget.GetIsReadOnly();
  599. comboBoxParam.IsHidden = cPDFWidget.GetIsHidden();
  600. GetAnnotCommonParam(cPDFWidget, comboBoxParam);
  601. }
  602. return comboBoxParam;
  603. }
  604. internal static ListBoxParam GetListBoxParam(CPDFListBoxWidget cPDFWidget)
  605. {
  606. ListBoxParam listBoxParam = null;
  607. if (cPDFWidget != null && cPDFWidget.IsValid())
  608. {
  609. listBoxParam = new ListBoxParam();
  610. CTextAttribute cTextAttribute = cPDFWidget.GetTextAttribute();
  611. listBoxParam.IsItalic = IsItalic(cTextAttribute.FontName);
  612. listBoxParam.IsBold = IsBold(cTextAttribute.FontName);
  613. CWidgetItem[] cWidgetItem = cPDFWidget.LoadWidgetItems();
  614. //Support for multiple selections needs to be adjusted later.
  615. CWidgetItem cWidgetItem1 = cPDFWidget.GetSelectedItem();
  616. if (cWidgetItem != null)
  617. {
  618. for (int i = 0; i < cWidgetItem.Length; i++)
  619. {
  620. CWidgetItem item = cWidgetItem[i];
  621. listBoxParam.OptionItems.Add(item.Value, item.Text);
  622. if (cWidgetItem1 != null && cWidgetItem1.Text == item.Text && cWidgetItem1.Value == item.Value)
  623. {
  624. listBoxParam.SelectItemsIndex = new List<int> { i };
  625. }
  626. }
  627. }
  628. listBoxParam.WidgetType = cPDFWidget.WidgetType;
  629. listBoxParam.BorderStyle = cPDFWidget.GetWidgetBorderStyle();
  630. byte[] LineColor = new byte[3];
  631. listBoxParam.HasLineColor = cPDFWidget.GetWidgetBorderRGBColor(ref LineColor);
  632. listBoxParam.LineColor = LineColor;
  633. byte[] BgColor = new byte[3];
  634. bool hasBgColor = cPDFWidget.GetWidgetBgRGBColor(ref BgColor);
  635. listBoxParam.HasBgColor = hasBgColor;
  636. listBoxParam.BgColor = BgColor;
  637. listBoxParam.FontColor = cTextAttribute.FontColor;
  638. listBoxParam.FontName = cTextAttribute.FontName;
  639. listBoxParam.FontSize = cTextAttribute.FontSize;
  640. listBoxParam.LineWidth = cPDFWidget.GetBorderWidth();
  641. listBoxParam.FieldName = cPDFWidget.GetFieldName();
  642. listBoxParam.Flags = cPDFWidget.GetFlags();
  643. listBoxParam.IsReadOnly = cPDFWidget.GetIsReadOnly();
  644. listBoxParam.IsHidden = cPDFWidget.GetIsHidden();
  645. GetAnnotCommonParam(cPDFWidget, listBoxParam);
  646. }
  647. return listBoxParam;
  648. }
  649. internal static SignatureParam GetSignatureParam(CPDFSignatureWidget cPDFWidget)
  650. {
  651. SignatureParam signatureParam = null;
  652. if (cPDFWidget != null && cPDFWidget.IsValid())
  653. {
  654. signatureParam = new SignatureParam();
  655. signatureParam.WidgetType = cPDFWidget.WidgetType;
  656. signatureParam.BorderStyle = cPDFWidget.GetWidgetBorderStyle();
  657. byte[] LineColor = new byte[3];
  658. signatureParam.HasLineColor = cPDFWidget.GetWidgetBorderRGBColor(ref LineColor);
  659. signatureParam.LineColor = LineColor;
  660. byte[] BgColor = new byte[3];
  661. bool hasBgColor = cPDFWidget.GetWidgetBgRGBColor(ref BgColor);
  662. signatureParam.HasBgColor = hasBgColor;
  663. signatureParam.BgColor = BgColor;
  664. CTextAttribute cTextAttribute = cPDFWidget.GetTextAttribute();
  665. signatureParam.FontColor = cTextAttribute.FontColor;
  666. signatureParam.FontName = cTextAttribute.FontName;
  667. signatureParam.FontSize = cTextAttribute.FontSize;
  668. signatureParam.LineWidth = cPDFWidget.GetBorderWidth();
  669. signatureParam.FieldName = cPDFWidget.GetFieldName();
  670. signatureParam.Flags = cPDFWidget.GetFlags();
  671. signatureParam.IsReadOnly = cPDFWidget.GetIsReadOnly();
  672. signatureParam.IsHidden = cPDFWidget.GetIsHidden();
  673. GetAnnotCommonParam(cPDFWidget, signatureParam);
  674. }
  675. return signatureParam;
  676. }
  677. #endregion
  678. #region Annot
  679. internal static AnnotParam MeasureAnnotConverter(CPDFAnnotation pdfAnnot)
  680. {
  681. if (pdfAnnot == null || pdfAnnot.IsValid() == false)
  682. {
  683. return null;
  684. }
  685. switch (pdfAnnot.Type)
  686. {
  687. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  688. {
  689. CPDFLineAnnotation lineAnnot = pdfAnnot as CPDFLineAnnotation;
  690. if (lineAnnot != null)
  691. {
  692. return GetLineMeasureParam(lineAnnot);
  693. }
  694. }
  695. break;
  696. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  697. {
  698. CPDFPolylineAnnotation polylineAnnot = pdfAnnot as CPDFPolylineAnnotation;
  699. if (polylineAnnot != null)
  700. {
  701. return GetPolylineParam(polylineAnnot);
  702. }
  703. }
  704. break;
  705. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  706. {
  707. CPDFPolygonAnnotation polygonAnnot = pdfAnnot as CPDFPolygonAnnotation;
  708. if (polygonAnnot != null)
  709. {
  710. return GetPolygonParam(polygonAnnot);
  711. }
  712. }
  713. break;
  714. }
  715. return null;
  716. }
  717. internal static AnnotParam AnnotConverter(CPDFDocument pdfDoc, CPDFAnnotation pdfAnnot)
  718. {
  719. if (pdfAnnot == null || pdfAnnot.IsValid() == false)
  720. {
  721. return null;
  722. }
  723. switch (pdfAnnot.Type)
  724. {
  725. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
  726. {
  727. CPDFSquareAnnotation squareAnnot = pdfAnnot as CPDFSquareAnnotation;
  728. if (squareAnnot != null)
  729. {
  730. return GetSquareParam(squareAnnot);
  731. }
  732. }
  733. break;
  734. case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
  735. {
  736. CPDFCircleAnnotation circleAnnot = pdfAnnot as CPDFCircleAnnotation;
  737. if (circleAnnot != null)
  738. {
  739. return GetCircleParam(circleAnnot);
  740. }
  741. }
  742. break;
  743. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  744. {
  745. CPDFLineAnnotation lineAnnot = pdfAnnot as CPDFLineAnnotation;
  746. if (lineAnnot != null)
  747. {
  748. if(lineAnnot.IsMeasured())
  749. {
  750. return GetLineMeasureParam(lineAnnot);
  751. }
  752. return GetLineParam(lineAnnot);
  753. }
  754. }
  755. break;
  756. case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
  757. {
  758. CPDFInkAnnotation inkAnnot = pdfAnnot as CPDFInkAnnotation;
  759. if (inkAnnot != null)
  760. {
  761. return GetInkParam(inkAnnot);
  762. }
  763. }
  764. break;
  765. case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
  766. {
  767. CPDFFreeTextAnnotation freetextAnnot = pdfAnnot as CPDFFreeTextAnnotation;
  768. if (freetextAnnot != null)
  769. {
  770. return GetFreeTextParam(freetextAnnot);
  771. }
  772. }
  773. break;
  774. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  775. {
  776. CPDFHighlightAnnotation highlightAnnot = pdfAnnot as CPDFHighlightAnnotation;
  777. if (highlightAnnot != null)
  778. {
  779. return GetHighlightParam(highlightAnnot);
  780. }
  781. }
  782. break;
  783. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  784. {
  785. CPDFUnderlineAnnotation underlineAnnot = pdfAnnot as CPDFUnderlineAnnotation;
  786. if (underlineAnnot != null)
  787. {
  788. return GetUnderlineParam(underlineAnnot);
  789. }
  790. }
  791. break;
  792. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  793. {
  794. CPDFStrikeoutAnnotation strikeoutAnnot = pdfAnnot as CPDFStrikeoutAnnotation;
  795. if (strikeoutAnnot != null)
  796. {
  797. return GetStrikeoutParam(strikeoutAnnot);
  798. }
  799. }
  800. break;
  801. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  802. {
  803. CPDFSquigglyAnnotation squigglyAnnot = pdfAnnot as CPDFSquigglyAnnotation;
  804. if (squigglyAnnot != null)
  805. {
  806. return GetSquigglyParam(squigglyAnnot);
  807. }
  808. }
  809. break;
  810. case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
  811. {
  812. CPDFTextAnnotation stickyAnnot = pdfAnnot as CPDFTextAnnotation;
  813. if (stickyAnnot != null)
  814. {
  815. return GetStickynoteParam(stickyAnnot);
  816. }
  817. }
  818. break;
  819. case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
  820. {
  821. CPDFStampAnnotation stampAnnot = pdfAnnot as CPDFStampAnnotation;
  822. if (stampAnnot != null)
  823. {
  824. return GetStampParam(stampAnnot);
  825. }
  826. }
  827. break;
  828. case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
  829. {
  830. CPDFLinkAnnotation linkAnnot = pdfAnnot as CPDFLinkAnnotation;
  831. if (linkAnnot != null)
  832. {
  833. return GetLinkParam(linkAnnot, pdfDoc);
  834. }
  835. }
  836. break;
  837. case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
  838. {
  839. CPDFSoundAnnotation soundAnnot = pdfAnnot as CPDFSoundAnnotation;
  840. if (soundAnnot != null)
  841. {
  842. return GetSoundParam(soundAnnot);
  843. }
  844. }
  845. break;
  846. case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
  847. {
  848. CPDFRedactAnnotation redactAnnot= pdfAnnot as CPDFRedactAnnotation;
  849. if(redactAnnot != null)
  850. {
  851. return GetRedactParam(redactAnnot);
  852. }
  853. }
  854. break;
  855. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  856. {
  857. CPDFPolylineAnnotation polylineAnnot= pdfAnnot as CPDFPolylineAnnotation;
  858. if (polylineAnnot!=null && polylineAnnot.IsMeasured())
  859. {
  860. return GetPolyLineMeasureParam(polylineAnnot);
  861. }
  862. }
  863. break;
  864. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  865. {
  866. CPDFPolygonAnnotation polygonAnnot= pdfAnnot as CPDFPolygonAnnotation;
  867. if(polygonAnnot!=null && polygonAnnot.IsMeasured())
  868. {
  869. return GetPolygonMeasureParam(polygonAnnot);
  870. }
  871. }
  872. break;
  873. default:
  874. break;
  875. }
  876. return null;
  877. }
  878. internal static void GetAnnotCommonParam(CPDFAnnotation pdfAnnot, AnnotParam annotParam)
  879. {
  880. if (pdfAnnot == null || annotParam == null || !pdfAnnot.IsValid())
  881. {
  882. return;
  883. }
  884. annotParam.CurrentType = pdfAnnot.Type;
  885. annotParam.Author = pdfAnnot.GetAuthor();
  886. annotParam.Transparency = pdfAnnot.GetTransparency();
  887. annotParam.Content = pdfAnnot.GetContent();
  888. annotParam.UpdateTime = pdfAnnot.GetModifyDate();
  889. annotParam.CreateTime = pdfAnnot.GetCreationDate();
  890. annotParam.Locked = pdfAnnot.GetIsLocked();
  891. annotParam.ClientRect = pdfAnnot.GetRect();
  892. annotParam.AnnotIndex = pdfAnnot.Page.GetAnnotations().IndexOf(pdfAnnot);
  893. //Annotation object exists, but the list cannot be found, it can only be a newly created annotation object.
  894. if (annotParam.AnnotIndex == -1)
  895. {
  896. annotParam.AnnotIndex = pdfAnnot.Page.GetAnnotCount() - 1;
  897. }
  898. annotParam.PageIndex = pdfAnnot.Page.PageIndex;
  899. }
  900. internal static SquareParam GetSquareParam(CPDFSquareAnnotation squareAnnot)
  901. {
  902. if (squareAnnot == null || squareAnnot.IsValid() == false)
  903. {
  904. return null;
  905. }
  906. SquareParam squareParam = new SquareParam();
  907. if (squareAnnot.LineColor != null && squareAnnot.LineColor.Length == 3)
  908. {
  909. squareParam.LineColor = new byte[3]
  910. {
  911. squareAnnot.LineColor[0],
  912. squareAnnot.LineColor[1],
  913. squareAnnot.LineColor[2]
  914. };
  915. }
  916. if (squareAnnot.HasBgColor && squareAnnot.BgColor != null)
  917. {
  918. if (squareAnnot.BgColor.Length == 3)
  919. {
  920. squareParam.HasBgColor = true;
  921. squareParam.BgColor = new byte[3]
  922. {
  923. squareAnnot.BgColor[0],
  924. squareAnnot.BgColor[1],
  925. squareAnnot.BgColor[2]
  926. };
  927. }
  928. }
  929. squareParam.LineWidth = squareAnnot.LineWidth;
  930. squareParam.BorderStyle = squareAnnot.BorderStyle;
  931. if (squareAnnot.Dash != null && squareAnnot.Dash.Length > 0)
  932. {
  933. squareParam.LineDash = new float[squareAnnot.Dash.Length];
  934. squareAnnot.Dash.CopyTo(squareParam.LineDash, 0);
  935. }
  936. GetAnnotCommonParam(squareAnnot, squareParam);
  937. return squareParam;
  938. }
  939. internal static CircleParam GetCircleParam(CPDFCircleAnnotation circleAnnot)
  940. {
  941. if (circleAnnot == null || circleAnnot.IsValid() == false)
  942. {
  943. return null;
  944. }
  945. CircleParam circleParam = new CircleParam();
  946. if (circleAnnot.LineColor != null && circleAnnot.LineColor.Length == 3)
  947. {
  948. circleParam.LineColor = new byte[3]
  949. {
  950. circleAnnot.LineColor[0],
  951. circleAnnot.LineColor[1],
  952. circleAnnot.LineColor[2]
  953. };
  954. }
  955. if (circleAnnot.HasBgColor && circleAnnot.BgColor != null)
  956. {
  957. if (circleAnnot.BgColor.Length == 3)
  958. {
  959. circleParam.HasBgColor = true;
  960. circleParam.BgColor = new byte[3]
  961. {
  962. circleAnnot.BgColor[0],
  963. circleAnnot.BgColor[1],
  964. circleAnnot.BgColor[2]
  965. };
  966. }
  967. }
  968. circleParam.LineWidth = circleAnnot.LineWidth;
  969. circleParam.BorderStyle = circleAnnot.BorderStyle;
  970. if (circleAnnot.Dash != null && circleAnnot.Dash.Length > 0)
  971. {
  972. circleParam.LineDash = new float[circleAnnot.Dash.Length];
  973. circleAnnot.Dash.CopyTo(circleParam.LineDash, 0);
  974. }
  975. GetAnnotCommonParam(circleAnnot, circleParam);
  976. return circleParam;
  977. }
  978. private static AnnotParam GetPolylineParam(CPDFPolylineAnnotation polylineAnnot)
  979. {
  980. if (polylineAnnot == null || polylineAnnot.IsValid() == false)
  981. {
  982. return null;
  983. }
  984. PolyLineMeasureParam polylineParam = new PolyLineMeasureParam();
  985. if (polylineAnnot.LineColor != null && polylineAnnot.LineColor.Length == 3)
  986. {
  987. polylineParam.LineColor = new byte[3]
  988. {
  989. polylineAnnot.LineColor[0],
  990. polylineAnnot.LineColor[1],
  991. polylineAnnot.LineColor[2]
  992. };
  993. }
  994. polylineParam.LineWidth = polylineAnnot.LineWidth;
  995. polylineParam.BorderStyle = polylineAnnot.BorderStyle;
  996. if (polylineAnnot.Dash != null && polylineAnnot.Dash.Length > 0)
  997. {
  998. polylineParam.LineDash = new float[polylineAnnot.Dash.Length];
  999. polylineAnnot.Dash.CopyTo(polylineParam.LineDash, 0);
  1000. }
  1001. if (polylineAnnot.Points != null && polylineAnnot.Points.Count > 0)
  1002. {
  1003. polylineParam.SavePoints = new List<CPoint>();
  1004. foreach (CPoint point in polylineAnnot.Points)
  1005. {
  1006. polylineParam.SavePoints.Add(point);
  1007. }
  1008. }
  1009. CTextAttribute cTextAttribute = polylineAnnot.GetTextAttribute();
  1010. polylineParam.FontName = cTextAttribute.FontName;
  1011. polylineParam.FontSize = cTextAttribute.FontSize;
  1012. polylineParam.FontColor = cTextAttribute.FontColor;
  1013. GetAnnotCommonParam(polylineAnnot, polylineParam);
  1014. return polylineParam;
  1015. }
  1016. private static AnnotParam GetPolygonParam(CPDFPolygonAnnotation polygonAnnot)
  1017. {
  1018. if (polygonAnnot == null || polygonAnnot.IsValid() == false)
  1019. {
  1020. return null;
  1021. }
  1022. PolygonMeasureParam polygonParam = new PolygonMeasureParam();
  1023. if (polygonAnnot.LineColor != null && polygonAnnot.LineColor.Length == 3)
  1024. {
  1025. polygonParam.LineColor = new byte[3]
  1026. {
  1027. polygonAnnot.LineColor[0],
  1028. polygonAnnot.LineColor[1],
  1029. polygonAnnot.LineColor[2]
  1030. };
  1031. }
  1032. if(polygonAnnot.HasBgColor && polygonAnnot.BgColor != null)
  1033. {
  1034. polygonParam.HasFillColor = true;
  1035. polygonParam.FillColor = new byte[3]
  1036. {
  1037. polygonAnnot.BgColor[0],
  1038. polygonAnnot.BgColor[1],
  1039. polygonAnnot.BgColor[2]
  1040. };
  1041. }
  1042. polygonParam.LineWidth = polygonAnnot.LineWidth;
  1043. polygonParam.BorderStyle = polygonAnnot.BorderStyle;
  1044. if (polygonAnnot.Dash != null && polygonAnnot.Dash.Length > 0)
  1045. {
  1046. polygonParam.LineDash = new float[polygonAnnot.Dash.Length];
  1047. polygonAnnot.Dash.CopyTo(polygonParam.LineDash, 0);
  1048. }
  1049. if (polygonAnnot.Points != null && polygonAnnot.Points.Count > 0)
  1050. {
  1051. polygonParam.SavePoints = new List<CPoint>();
  1052. foreach (CPoint point in polygonAnnot.Points)
  1053. {
  1054. polygonParam.SavePoints.Add(point);
  1055. }
  1056. }
  1057. CTextAttribute cTextAttribute = polygonAnnot.GetTextAttribute();
  1058. polygonParam.FontName = cTextAttribute.FontName;
  1059. polygonParam.FontSize = cTextAttribute.FontSize;
  1060. polygonParam.FontColor = cTextAttribute.FontColor;
  1061. GetAnnotCommonParam(polygonAnnot, polygonParam);
  1062. return polygonParam;
  1063. }
  1064. internal static LineParam GetLineParam(CPDFLineAnnotation lineAnnot)
  1065. {
  1066. if (lineAnnot == null || lineAnnot.IsValid() == false)
  1067. {
  1068. return null;
  1069. }
  1070. LineParam lineParam = new LineParam();
  1071. if (lineAnnot.LineColor != null && lineAnnot.LineColor.Length == 3)
  1072. {
  1073. lineParam.LineColor = new byte[3]
  1074. {
  1075. lineAnnot.LineColor[0],
  1076. lineAnnot.LineColor[1],
  1077. lineAnnot.LineColor[2]
  1078. };
  1079. }
  1080. if (lineAnnot.HasBgColor && lineAnnot.BgColor != null)
  1081. {
  1082. if (lineAnnot.BgColor.Length == 3)
  1083. {
  1084. lineParam.HasBgColor = true;
  1085. lineParam.BgColor = new byte[3]
  1086. {
  1087. lineAnnot.BgColor[0],
  1088. lineAnnot.BgColor[1],
  1089. lineAnnot.BgColor[2]
  1090. };
  1091. }
  1092. }
  1093. lineParam.LineWidth = lineAnnot.LineWidth;
  1094. lineParam.BorderStyle = lineAnnot.BorderStyle;
  1095. if (lineAnnot.Dash != null && lineAnnot.Dash.Length > 0)
  1096. {
  1097. lineParam.LineDash = new float[lineAnnot.Dash.Length];
  1098. lineAnnot.Dash.CopyTo(lineParam.LineDash, 0);
  1099. }
  1100. lineParam.HeadLineType = lineAnnot.HeadLineType;
  1101. lineParam.TailLineType = lineAnnot.TailLineType;
  1102. if (lineAnnot.Points != null && lineAnnot.Points.Length == 2)
  1103. {
  1104. lineParam.HeadPoint = lineAnnot.Points[0];
  1105. lineParam.TailPoint = lineAnnot.Points[1];
  1106. }
  1107. GetAnnotCommonParam(lineAnnot, lineParam);
  1108. return lineParam;
  1109. }
  1110. internal static LineMeasureParam GetLineMeasureParam(CPDFLineAnnotation lineAnnot)
  1111. {
  1112. if (lineAnnot == null || lineAnnot.IsValid() == false || lineAnnot.IsMeasured()==false)
  1113. {
  1114. return null;
  1115. }
  1116. LineMeasureParam measureParam = new LineMeasureParam();
  1117. CPDFDistanceMeasure distanceMeasure = lineAnnot.GetDistanceMeasure();
  1118. measureParam.measureInfo = distanceMeasure.MeasureInfo;
  1119. if (lineAnnot.LineColor != null && lineAnnot.LineColor.Length == 3)
  1120. {
  1121. measureParam.LineColor = new byte[3] { lineAnnot.LineColor[0], lineAnnot.LineColor[1], lineAnnot.LineColor[2] };
  1122. }
  1123. measureParam.BorderStyle = lineAnnot.BorderStyle;
  1124. measureParam.LineWidth = lineAnnot.LineWidth;
  1125. measureParam.Transparency = lineAnnot.Transparency;
  1126. measureParam.LineDash = lineAnnot.Dash;
  1127. CTextAttribute textAttr = lineAnnot.GetTextAttribute();
  1128. measureParam.FontName = textAttr.FontName;
  1129. measureParam.FontSize = textAttr.FontSize;
  1130. if (textAttr.FontColor != null && textAttr.FontColor.Length == 3)
  1131. {
  1132. measureParam.FontColor = new byte[] { textAttr.FontColor[0], textAttr.FontColor[1], textAttr.FontColor[2] };
  1133. }
  1134. measureParam.IsBold = CFontNameHelper.IsBold(textAttr.FontName);
  1135. measureParam.IsItalic = CFontNameHelper.IsItalic(textAttr.FontName);
  1136. measureParam.HeadLineType=lineAnnot.HeadLineType;
  1137. measureParam.TailLineType=lineAnnot.TailLineType;
  1138. measureParam.HeadPoint = lineAnnot.Points[0];
  1139. measureParam.TailPoint = lineAnnot.Points[1];
  1140. GetAnnotCommonParam(lineAnnot, measureParam);
  1141. return measureParam;
  1142. }
  1143. internal static InkParam GetInkParam(CPDFInkAnnotation inkAnnot)
  1144. {
  1145. if (inkAnnot == null || inkAnnot.IsValid() == false)
  1146. {
  1147. return null;
  1148. }
  1149. InkParam inkParam = new InkParam();
  1150. inkParam.Thickness = inkAnnot.Thickness;
  1151. if (inkAnnot.InkColor != null && inkAnnot.InkColor.Length == 3)
  1152. {
  1153. inkParam.InkColor = new byte[3]
  1154. {
  1155. inkAnnot.InkColor[0],
  1156. inkAnnot.InkColor[1],
  1157. inkAnnot.InkColor[2]
  1158. };
  1159. }
  1160. if (inkAnnot.InkPath != null && inkAnnot.InkPath.Count > 0)
  1161. {
  1162. List<List<CPoint>> inkPath = new List<List<CPoint>>();
  1163. foreach (List<CPoint> copyList in inkAnnot.InkPath)
  1164. {
  1165. if (copyList.Count == 0)
  1166. {
  1167. continue;
  1168. }
  1169. List<CPoint> saveList = new List<CPoint>();
  1170. foreach (CPoint item in copyList)
  1171. {
  1172. saveList.Add(item);
  1173. }
  1174. if (saveList.Count > 0)
  1175. {
  1176. inkPath.Add(saveList);
  1177. }
  1178. }
  1179. if (inkPath.Count > 0)
  1180. {
  1181. inkParam.InkPath = inkPath;
  1182. }
  1183. }
  1184. if(inkAnnot.Dash!=null && inkAnnot.Dash.Length>0)
  1185. {
  1186. inkParam.Dash =new float[inkAnnot.Dash.Length];
  1187. inkAnnot.Dash.CopyTo(inkParam.Dash, 0);
  1188. }
  1189. GetAnnotCommonParam(inkAnnot, inkParam);
  1190. return inkParam;
  1191. }
  1192. internal static FreeTextParam GetFreeTextParam(CPDFFreeTextAnnotation freetextAnnot)
  1193. {
  1194. if (freetextAnnot == null || freetextAnnot.IsValid() == false)
  1195. {
  1196. return null;
  1197. }
  1198. FreeTextParam freetextParam = new FreeTextParam();
  1199. if (freetextAnnot.LineColor != null && freetextAnnot.LineColor.Length == 3)
  1200. {
  1201. freetextParam.LineColor = new byte[3]
  1202. {
  1203. freetextAnnot.LineColor[0],
  1204. freetextAnnot.LineColor[1],
  1205. freetextAnnot.LineColor[2]
  1206. };
  1207. }
  1208. if (freetextAnnot.HasBgColor && freetextAnnot.BgColor != null)
  1209. {
  1210. if (freetextAnnot.BgColor.Length == 3)
  1211. {
  1212. freetextParam.HasBgColor = true;
  1213. freetextParam.BgColor = new byte[3]
  1214. {
  1215. freetextAnnot.BgColor[0],
  1216. freetextAnnot.BgColor[1],
  1217. freetextAnnot.BgColor[2]
  1218. };
  1219. }
  1220. }
  1221. freetextParam.LineWidth = freetextAnnot.LineWidth;
  1222. if (freetextAnnot.FreeTextDa != null)
  1223. {
  1224. byte[] fontColor = freetextAnnot.FreeTextDa.FontColor;
  1225. if (fontColor != null && fontColor.Length == 3)
  1226. {
  1227. freetextParam.FontColor = new byte[3]
  1228. {
  1229. fontColor[0],
  1230. fontColor[1],
  1231. fontColor[2]
  1232. };
  1233. }
  1234. string fontName = freetextAnnot.FreeTextDa.FontName;
  1235. if (!string.IsNullOrEmpty(fontName))
  1236. {
  1237. freetextParam.FontName = fontName;
  1238. freetextParam.IsBold = IsBold(fontName);
  1239. freetextParam.IsItalic = IsItalic(fontName);
  1240. }
  1241. freetextParam.FontSize = freetextAnnot.FreeTextDa.FontSize;
  1242. freetextParam.Alignment = freetextAnnot.Alignment;
  1243. }
  1244. if (freetextAnnot.Dash != null && freetextAnnot.Dash.Length > 0)
  1245. {
  1246. freetextParam.Dash = new float[freetextAnnot.Dash.Length];
  1247. freetextAnnot.Dash.CopyTo(freetextParam.Dash, 0);
  1248. }
  1249. GetAnnotCommonParam(freetextAnnot, freetextParam);
  1250. return freetextParam;
  1251. }
  1252. internal static HighlightParam GetHighlightParam(CPDFHighlightAnnotation highlightAnnot)
  1253. {
  1254. if (highlightAnnot == null || highlightAnnot.IsValid() == false)
  1255. {
  1256. return null;
  1257. }
  1258. HighlightParam highlightParam = new HighlightParam();
  1259. if (highlightAnnot.Color != null && highlightAnnot.Color.Length == 3)
  1260. {
  1261. highlightParam.HighlightColor = new byte[3]
  1262. {
  1263. highlightAnnot.Color[0],
  1264. highlightAnnot.Color[1],
  1265. highlightAnnot.Color[2]
  1266. };
  1267. }
  1268. if (highlightAnnot.QuardRects != null && highlightAnnot.QuardRects.Count > 0)
  1269. {
  1270. List<CRect> saveList = new List<CRect>();
  1271. foreach (CRect saveRect in highlightAnnot.QuardRects)
  1272. {
  1273. saveList.Add(saveRect);
  1274. }
  1275. highlightParam.QuardRects = saveList;
  1276. }
  1277. GetAnnotCommonParam(highlightAnnot, highlightParam);
  1278. return highlightParam;
  1279. }
  1280. internal static UnderlineParam GetUnderlineParam(CPDFUnderlineAnnotation underlineAnnot)
  1281. {
  1282. if (underlineAnnot == null || underlineAnnot.IsValid() == false)
  1283. {
  1284. return null;
  1285. }
  1286. UnderlineParam underlineParam = new UnderlineParam();
  1287. if (underlineAnnot.Color != null && underlineAnnot.Color.Length == 3)
  1288. {
  1289. underlineParam.UnderlineColor = new byte[3]
  1290. {
  1291. underlineAnnot.Color[0],
  1292. underlineAnnot.Color[1],
  1293. underlineAnnot.Color[2]
  1294. };
  1295. }
  1296. if (underlineAnnot.QuardRects != null && underlineAnnot.QuardRects.Count > 0)
  1297. {
  1298. List<CRect> saveList = new List<CRect>();
  1299. foreach (CRect saveRect in underlineAnnot.QuardRects)
  1300. {
  1301. saveList.Add(saveRect);
  1302. }
  1303. underlineParam.QuardRects = saveList;
  1304. }
  1305. GetAnnotCommonParam(underlineAnnot, underlineParam);
  1306. return underlineParam;
  1307. }
  1308. internal static StrikeoutParam GetStrikeoutParam(CPDFStrikeoutAnnotation strikeoutAnnot)
  1309. {
  1310. if (strikeoutAnnot == null || strikeoutAnnot.IsValid() == false)
  1311. {
  1312. return null;
  1313. }
  1314. StrikeoutParam strikeoutParam = new StrikeoutParam();
  1315. if (strikeoutAnnot.Color != null && strikeoutAnnot.Color.Length == 3)
  1316. {
  1317. strikeoutParam.StrikeoutColor = new byte[3]
  1318. {
  1319. strikeoutAnnot.Color[0],
  1320. strikeoutAnnot.Color[1],
  1321. strikeoutAnnot.Color[2]
  1322. };
  1323. }
  1324. if (strikeoutAnnot.QuardRects != null && strikeoutAnnot.QuardRects.Count > 0)
  1325. {
  1326. List<CRect> saveList = new List<CRect>();
  1327. foreach (CRect saveRect in strikeoutAnnot.QuardRects)
  1328. {
  1329. saveList.Add(saveRect);
  1330. }
  1331. strikeoutParam.QuardRects = saveList;
  1332. }
  1333. GetAnnotCommonParam(strikeoutAnnot, strikeoutParam);
  1334. return strikeoutParam;
  1335. }
  1336. internal static SquigglyParam GetSquigglyParam(CPDFSquigglyAnnotation squigglyAnnot)
  1337. {
  1338. if (squigglyAnnot == null || squigglyAnnot.IsValid() == false)
  1339. {
  1340. return null;
  1341. }
  1342. SquigglyParam squigglyParam = new SquigglyParam();
  1343. if (squigglyAnnot.Color != null && squigglyAnnot.Color.Length == 3)
  1344. {
  1345. squigglyParam.SquigglyColor = new byte[3]
  1346. {
  1347. squigglyAnnot.Color[0],
  1348. squigglyAnnot.Color[1],
  1349. squigglyAnnot.Color[2]
  1350. };
  1351. }
  1352. if (squigglyAnnot.QuardRects != null && squigglyAnnot.QuardRects.Count > 0)
  1353. {
  1354. List<CRect> saveList = new List<CRect>();
  1355. foreach (CRect saveRect in squigglyAnnot.QuardRects)
  1356. {
  1357. saveList.Add(saveRect);
  1358. }
  1359. squigglyParam.QuardRects = saveList;
  1360. }
  1361. GetAnnotCommonParam(squigglyAnnot, squigglyParam);
  1362. return squigglyParam;
  1363. }
  1364. internal static StickyNoteParam GetStickynoteParam(CPDFTextAnnotation stickyAnnot)
  1365. {
  1366. if (stickyAnnot == null || stickyAnnot.IsValid() == false)
  1367. {
  1368. return null;
  1369. }
  1370. StickyNoteParam stickyParam = new StickyNoteParam();
  1371. if (stickyAnnot.Color != null && stickyAnnot.Color.Length == 3)
  1372. {
  1373. stickyParam.StickyNoteColor = new byte[3]
  1374. {
  1375. stickyAnnot.Color[0],
  1376. stickyAnnot.Color[1],
  1377. stickyAnnot.Color[2]
  1378. };
  1379. }
  1380. stickyParam.IconName=stickyAnnot.GetIconName();
  1381. GetAnnotCommonParam(stickyAnnot, stickyParam);
  1382. return stickyParam;
  1383. }
  1384. internal static StampParam GetStampParam(CPDFStampAnnotation stampAnnot)
  1385. {
  1386. if (stampAnnot == null || stampAnnot.IsValid() == false)
  1387. {
  1388. return null;
  1389. }
  1390. StampParam stampParam = new StampParam();
  1391. C_STAMP_TYPE stampType = stampAnnot.GetStampType();
  1392. switch (stampType)
  1393. {
  1394. case C_STAMP_TYPE.STANDARD_STAMP:
  1395. {
  1396. stampParam.StampText = stampAnnot.GetStandardStamp();
  1397. stampParam.StampType = stampType;
  1398. }
  1399. break;
  1400. case C_STAMP_TYPE.TEXT_STAMP:
  1401. {
  1402. string stampText = string.Empty;
  1403. string dateText = string.Empty;
  1404. C_TEXTSTAMP_SHAPE stampShape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_NONE;
  1405. C_TEXTSTAMP_COLOR stampColor = C_TEXTSTAMP_COLOR.TEXTSTAMP_WHITE;
  1406. stampAnnot.GetTextStamp(ref stampText,
  1407. ref dateText,
  1408. ref stampShape,
  1409. ref stampColor);
  1410. stampParam.StampText = stampText;
  1411. stampParam.DateText = dateText;
  1412. stampParam.TextStampShape = stampShape;
  1413. stampParam.TextStampColor = stampColor;
  1414. stampParam.StampType = stampType;
  1415. }
  1416. break;
  1417. case C_STAMP_TYPE.IMAGE_STAMP:
  1418. case C_STAMP_TYPE.UNKNOWN_STAMP:
  1419. {
  1420. stampParam.StampType = stampType;
  1421. CRect rawRect = stampAnnot.GetRect();
  1422. int width = (int)(rawRect.width() / 72D * 96D);
  1423. int height = (int)(rawRect.height() / 72D * 96D);
  1424. if (width > 0 && height > 0)
  1425. {
  1426. Rect rotateRect = new Rect(0, 0, width, height);
  1427. Matrix rotateMatrix = new Matrix();
  1428. rotateMatrix.RotateAt(-90 * stampAnnot.Page.Rotation, width / 2, height / 2);
  1429. rotateRect.Transform(rotateMatrix);
  1430. int imageWidth = (int)rotateRect.Width;
  1431. int imageHeight = (int)rotateRect.Height;
  1432. byte[] ImageArray = new byte[imageWidth * imageHeight * 4];
  1433. stampAnnot.RenderAnnot(imageWidth, imageHeight, ImageArray);
  1434. WriteableBitmap writeBitmap = new WriteableBitmap(
  1435. imageWidth,
  1436. imageHeight,
  1437. 96,
  1438. 96,
  1439. PixelFormats.Bgra32,
  1440. null);
  1441. writeBitmap.WritePixels(new Int32Rect(0, 0, imageWidth, imageHeight), ImageArray, imageWidth * 4, 0);
  1442. PngBitmapEncoder pngEncoder = new PngBitmapEncoder();
  1443. pngEncoder.Frames.Add(BitmapFrame.Create(writeBitmap));
  1444. MemoryStream memStream = new MemoryStream();
  1445. pngEncoder.Save(memStream);
  1446. stampParam.ImageStream = memStream;
  1447. }
  1448. }
  1449. break;
  1450. default:
  1451. return null;
  1452. }
  1453. GetAnnotCommonParam(stampAnnot, stampParam);
  1454. return stampParam;
  1455. }
  1456. internal static LinkParam GetLinkParam(CPDFLinkAnnotation linkAnnot, CPDFDocument pdfDoc)
  1457. {
  1458. if (linkAnnot == null || linkAnnot.IsValid() == false)
  1459. {
  1460. return null;
  1461. }
  1462. LinkParam linkParam = new LinkParam();
  1463. CPDFAction linkAction = linkAnnot.GetLinkAction();
  1464. if (linkAction != null)
  1465. {
  1466. switch (linkAction.ActionType)
  1467. {
  1468. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  1469. {
  1470. CPDFGoToAction gotoAction = linkAction as CPDFGoToAction;
  1471. if (gotoAction != null && pdfDoc != null && pdfDoc.IsValid())
  1472. {
  1473. CPDFDestination dest = gotoAction.GetDestination(pdfDoc);
  1474. if (dest != null)
  1475. {
  1476. linkParam.Action = C_ACTION_TYPE.ACTION_TYPE_GOTO;
  1477. linkParam.DestinationPageIndex = dest.PageIndex;
  1478. linkParam.DestinationPosition = new CPoint(dest.Position_X, dest.Position_Y);
  1479. }
  1480. }
  1481. }
  1482. break;
  1483. case C_ACTION_TYPE.ACTION_TYPE_URI:
  1484. {
  1485. CPDFUriAction urlAction = linkAction as CPDFUriAction;
  1486. if (urlAction != null)
  1487. {
  1488. linkParam.Uri = urlAction.GetUri();
  1489. linkParam.Action = C_ACTION_TYPE.ACTION_TYPE_URI;
  1490. }
  1491. }
  1492. break;
  1493. default:
  1494. break;
  1495. }
  1496. }
  1497. GetAnnotCommonParam(linkAnnot, linkParam);
  1498. return linkParam;
  1499. }
  1500. internal static SoundParam GetSoundParam(CPDFSoundAnnotation stampAnnot)
  1501. {
  1502. if (stampAnnot == null || stampAnnot.IsValid() == false)
  1503. {
  1504. return null;
  1505. }
  1506. SoundParam soundParam = new SoundParam();
  1507. GetAnnotCommonParam(stampAnnot, soundParam);
  1508. return soundParam;
  1509. }
  1510. internal static RedactParam GetRedactParam(CPDFRedactAnnotation redactAnnot)
  1511. {
  1512. if(redactAnnot == null || redactAnnot.IsValid() == false)
  1513. {
  1514. return null;
  1515. }
  1516. RedactParam redactParam = new RedactParam();
  1517. if (redactAnnot.OutlineColor != null && redactAnnot.OutlineColor.Length == 3)
  1518. {
  1519. redactParam.LineColor = new byte[3] { redactAnnot.OutlineColor[0], redactAnnot.OutlineColor[1], redactAnnot.OutlineColor[2] };
  1520. }
  1521. if (redactAnnot.FillColor != null && redactAnnot.FillColor.Length == 3)
  1522. {
  1523. redactParam.BgColor = new byte[3] { redactAnnot.FillColor[0], redactAnnot.FillColor[1], redactAnnot.FillColor[2] };
  1524. }
  1525. if (redactAnnot.TextDa != null)
  1526. {
  1527. if (redactAnnot.TextDa.FontColor != null && redactAnnot.TextDa.FontColor.Length == 3)
  1528. {
  1529. redactParam.FontColor = new byte[3] { redactAnnot.TextDa.FontColor[0], redactAnnot.TextDa.FontColor[1], redactAnnot.TextDa.FontColor[2] };
  1530. }
  1531. redactParam.FontName= redactAnnot.TextDa.FontName;
  1532. redactParam.FontSize = redactAnnot.TextDa.FontSize;
  1533. redactParam.Alignment=redactAnnot.TextAlignment;
  1534. }
  1535. if(redactAnnot.QuardRects!=null)
  1536. {
  1537. redactParam.QuardRects = new List<CRect>(redactAnnot.QuardRects);
  1538. }
  1539. redactParam.OverlayText = redactAnnot.OverlayText;
  1540. GetAnnotCommonParam(redactAnnot, redactParam);
  1541. return redactParam;
  1542. }
  1543. internal static PolyLineMeasureParam GetPolyLineMeasureParam(CPDFPolylineAnnotation polylineAnnot)
  1544. {
  1545. if (polylineAnnot == null || polylineAnnot.IsValid() == false || polylineAnnot.IsMeasured()==false)
  1546. {
  1547. return null;
  1548. }
  1549. PolyLineMeasureParam measureParam = new PolyLineMeasureParam();
  1550. CPDFPerimeterMeasure perimeterMeasure = polylineAnnot.GetPerimeterMeasure();
  1551. measureParam.measureInfo= perimeterMeasure.MeasureInfo;
  1552. if (polylineAnnot.LineColor != null && polylineAnnot.LineColor.Length == 3)
  1553. {
  1554. measureParam.LineColor = new byte[3] { polylineAnnot.LineColor[0], polylineAnnot.LineColor[1], polylineAnnot.LineColor[2] };
  1555. }
  1556. measureParam.SavePoints = polylineAnnot.Points;
  1557. measureParam.BorderStyle = polylineAnnot.BorderStyle;
  1558. measureParam.LineWidth=polylineAnnot.LineWidth;
  1559. measureParam.Transparency=polylineAnnot.Transparency;
  1560. measureParam.LineDash=polylineAnnot.Dash;
  1561. CTextAttribute textAttr = polylineAnnot.GetTextAttribute();
  1562. measureParam.FontName = textAttr.FontName;
  1563. measureParam.FontSize = textAttr.FontSize;
  1564. if(textAttr.FontColor!=null && textAttr.FontColor.Length == 3)
  1565. {
  1566. measureParam.FontColor = new byte[] { textAttr.FontColor[0], textAttr.FontColor[1], textAttr.FontColor[2] };
  1567. }
  1568. measureParam.IsBold = CFontNameHelper.IsBold(textAttr.FontName);
  1569. measureParam.IsItalic = CFontNameHelper.IsItalic(textAttr.FontName);
  1570. GetAnnotCommonParam(polylineAnnot, measureParam);
  1571. return measureParam;
  1572. }
  1573. internal static PolygonMeasureParam GetPolygonMeasureParam(CPDFPolygonAnnotation polygonAnnot)
  1574. {
  1575. if (polygonAnnot == null || polygonAnnot.IsValid() == false || polygonAnnot.IsMeasured() == false)
  1576. {
  1577. return null;
  1578. }
  1579. PolygonMeasureParam measureParam = new PolygonMeasureParam();
  1580. CPDFAreaMeasure areaMeasure = polygonAnnot.GetAreaMeasure();
  1581. measureParam.measureInfo = areaMeasure.MeasureInfo;
  1582. if (polygonAnnot.LineColor != null && polygonAnnot.LineColor.Length == 3)
  1583. {
  1584. measureParam.LineColor = new byte[] { polygonAnnot.LineColor[0], polygonAnnot.LineColor[1], polygonAnnot.LineColor[2] };
  1585. }
  1586. if(polygonAnnot.BgColor!=null && polygonAnnot.BgColor.Length == 3)
  1587. {
  1588. measureParam.HasFillColor = true;
  1589. measureParam.FillColor = new byte[] { polygonAnnot.BgColor[0], polygonAnnot.BgColor[1], polygonAnnot.BgColor[2] };
  1590. }
  1591. measureParam.SavePoints = polygonAnnot.Points;
  1592. measureParam.BorderStyle = polygonAnnot.BorderStyle;
  1593. measureParam.LineWidth = polygonAnnot.LineWidth;
  1594. measureParam.Transparency = polygonAnnot.Transparency;
  1595. measureParam.LineDash = polygonAnnot.Dash;
  1596. CTextAttribute textAttr = polygonAnnot.GetTextAttribute();
  1597. measureParam.FontName = textAttr.FontName;
  1598. measureParam.FontSize = textAttr.FontSize;
  1599. if (textAttr.FontColor != null && textAttr.FontColor.Length == 3)
  1600. {
  1601. measureParam.FontColor = new byte[] { textAttr.FontColor[0], textAttr.FontColor[1], textAttr.FontColor[2] };
  1602. }
  1603. measureParam.IsBold = CFontNameHelper.IsBold(textAttr.FontName);
  1604. measureParam.IsItalic = CFontNameHelper.IsItalic(textAttr.FontName);
  1605. GetAnnotCommonParam(polygonAnnot, measureParam);
  1606. return measureParam;
  1607. }
  1608. #endregion
  1609. public static bool SetParamForPDFAnnot(CPDFDocument cPDFDocument, CPDFAnnotation cPDFAnnotation, AnnotParam param)
  1610. {
  1611. bool successful = false;
  1612. if (cPDFAnnotation == null && !cPDFAnnotation.IsValid() && cPDFDocument == null && !cPDFDocument.IsValid())
  1613. {
  1614. return successful;
  1615. }
  1616. if (cPDFAnnotation.Type == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
  1617. {
  1618. successful = SetWidgetParamForPDFAnnot(cPDFDocument, cPDFAnnotation, param);
  1619. }
  1620. else
  1621. {
  1622. successful = SetAnnotParamForPDFAnnot(cPDFDocument, cPDFAnnotation, param);
  1623. }
  1624. return successful;
  1625. }
  1626. #region SetWidegt
  1627. internal static bool SetWidgetParamForPDFAnnot(CPDFDocument cPDFDocument, CPDFAnnotation cPDFAnnotation, AnnotParam param)
  1628. {
  1629. bool successful = false;
  1630. if (cPDFAnnotation is CPDFWidget)
  1631. {
  1632. switch ((cPDFAnnotation as CPDFWidget).WidgetType)
  1633. {
  1634. case C_WIDGET_TYPE.WIDGET_PUSHBUTTON:
  1635. successful = SetPushButtonParamForPDFAnnot(cPDFDocument, cPDFAnnotation, param);
  1636. break;
  1637. case C_WIDGET_TYPE.WIDGET_CHECKBOX:
  1638. successful = SetCheckBoxParamForPDFAnnot(cPDFAnnotation, param);
  1639. break;
  1640. case C_WIDGET_TYPE.WIDGET_RADIOBUTTON:
  1641. successful = SetRadioButtonParamForPDFAnnot(cPDFAnnotation, param);
  1642. break;
  1643. case C_WIDGET_TYPE.WIDGET_TEXTFIELD:
  1644. successful = SetTextBoxParamForPDFAnnot(cPDFAnnotation, param);
  1645. break;
  1646. case C_WIDGET_TYPE.WIDGET_COMBOBOX:
  1647. successful = SetComboBoxParamForPDFAnnot(cPDFAnnotation, param);
  1648. break;
  1649. case C_WIDGET_TYPE.WIDGET_LISTBOX:
  1650. successful = SetListBoxParamForPDFAnnot(cPDFAnnotation, param);
  1651. break;
  1652. case C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS:
  1653. successful = SetSignatureParamForPDFAnnot(cPDFAnnotation, param);
  1654. break;
  1655. default:
  1656. successful = false;
  1657. break;
  1658. }
  1659. }
  1660. return successful;
  1661. }
  1662. internal static bool SetPushButtonParamForPDFAnnot(CPDFDocument cPDFDocument, CPDFAnnotation cPDFAnnotation, AnnotParam param)
  1663. {
  1664. PushButtonParam CurrentParam = param as PushButtonParam;
  1665. CPDFPushButtonWidget pushbuttonWidget = cPDFAnnotation as CPDFPushButtonWidget;
  1666. bool successful = false;
  1667. if (pushbuttonWidget == null && !pushbuttonWidget.IsValid() && CurrentParam == null)
  1668. {
  1669. return successful;
  1670. }
  1671. else
  1672. {
  1673. if (!string.IsNullOrEmpty(CurrentParam.FieldName))
  1674. {
  1675. pushbuttonWidget.SetFieldName(CurrentParam.FieldName);
  1676. }
  1677. if (CurrentParam.HasLineColor)
  1678. {
  1679. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  1680. {
  1681. pushbuttonWidget.SetWidgetBorderRGBColor(CurrentParam.LineColor);
  1682. }
  1683. }
  1684. if (CurrentParam.HasBgColor)
  1685. {
  1686. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  1687. {
  1688. pushbuttonWidget.SetWidgetBgRGBColor(CurrentParam.BgColor);
  1689. }
  1690. }
  1691. if (!string.IsNullOrEmpty(CurrentParam.Text))
  1692. {
  1693. pushbuttonWidget.SetButtonTitle(CurrentParam.Text);
  1694. }
  1695. pushbuttonWidget.SetBorderWidth((float)CurrentParam.LineWidth);
  1696. pushbuttonWidget.SetWidgetBorderStyle(CurrentParam.BorderStyle);
  1697. CTextAttribute textAttr = new CTextAttribute();
  1698. byte[] fontColor = new byte[3];
  1699. if (CurrentParam.FontColor != null && CurrentParam.FontColor.Length == 3)
  1700. {
  1701. fontColor = CurrentParam.FontColor;
  1702. }
  1703. textAttr.FontColor = fontColor;
  1704. textAttr.FontSize = (float)CurrentParam.FontSize;
  1705. textAttr.FontName = ObtainFontName(
  1706. GetFontType(CurrentParam.FontName),
  1707. CurrentParam.IsBold,
  1708. CurrentParam.IsItalic);
  1709. pushbuttonWidget.SetTextAttribute(textAttr);
  1710. switch (CurrentParam.Action)
  1711. {
  1712. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  1713. {
  1714. CPDFGoToAction gotoAction = new CPDFGoToAction();
  1715. CPDFDestination destination = new CPDFDestination();
  1716. destination.Position_X = CurrentParam.DestinationPosition.x;
  1717. destination.Position_Y = CurrentParam.DestinationPosition.y;
  1718. destination.PageIndex = CurrentParam.DestinationPageIndex;
  1719. gotoAction.SetDestination(cPDFDocument, destination);
  1720. pushbuttonWidget.SetButtonAction(gotoAction);
  1721. }
  1722. break;
  1723. case C_ACTION_TYPE.ACTION_TYPE_URI:
  1724. {
  1725. CPDFUriAction uriAction = new CPDFUriAction();
  1726. uriAction.SetUri(CurrentParam.Uri);
  1727. pushbuttonWidget.SetButtonAction(uriAction);
  1728. }
  1729. break;
  1730. default:
  1731. break;
  1732. }
  1733. pushbuttonWidget.SetRect(CurrentParam.ClientRect);
  1734. pushbuttonWidget.SetFlags(CurrentParam.Flags);
  1735. pushbuttonWidget.SetIsLocked(CurrentParam.Locked);
  1736. pushbuttonWidget.SetIsReadOnly(CurrentParam.IsReadOnly);
  1737. pushbuttonWidget.SetIsHidden(CurrentParam.IsHidden);
  1738. pushbuttonWidget.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  1739. pushbuttonWidget.UpdateFormAp();
  1740. successful = true;
  1741. return successful;
  1742. }
  1743. }
  1744. internal static bool SetCheckBoxParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  1745. {
  1746. CheckBoxParam CurrentParam = param as CheckBoxParam;
  1747. CPDFCheckBoxWidget checkboxWidget = cPDFAnnotation as CPDFCheckBoxWidget;
  1748. bool successful = false;
  1749. if (checkboxWidget == null && !checkboxWidget.IsValid() && CurrentParam == null)
  1750. {
  1751. return successful;
  1752. }
  1753. else
  1754. {
  1755. if (!string.IsNullOrEmpty(CurrentParam.FieldName))
  1756. {
  1757. checkboxWidget.SetFieldName(CurrentParam.FieldName);
  1758. }
  1759. checkboxWidget.SetWidgetCheckStyle(CurrentParam.CheckStyle);
  1760. checkboxWidget.SetChecked(CurrentParam.IsChecked);
  1761. if (CurrentParam.HasLineColor)
  1762. {
  1763. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  1764. {
  1765. checkboxWidget.SetWidgetBorderRGBColor(CurrentParam.LineColor);
  1766. }
  1767. }
  1768. if (CurrentParam.HasBgColor)
  1769. {
  1770. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  1771. {
  1772. checkboxWidget.SetWidgetBgRGBColor(CurrentParam.BgColor);
  1773. }
  1774. }
  1775. checkboxWidget.SetBorderWidth((float)CurrentParam.LineWidth);
  1776. checkboxWidget.SetWidgetBorderStyle(CurrentParam.BorderStyle);
  1777. if (CurrentParam.FontColor != null && CurrentParam.FontColor.Length == 3)
  1778. {
  1779. CTextAttribute textAttr = checkboxWidget.GetTextAttribute();
  1780. textAttr.FontColor = CurrentParam.FontColor;
  1781. checkboxWidget.SetTextAttribute(textAttr);
  1782. }
  1783. checkboxWidget.SetRect(CurrentParam.ClientRect);
  1784. checkboxWidget.SetFlags(CurrentParam.Flags);
  1785. checkboxWidget.SetIsLocked(CurrentParam.Locked);
  1786. checkboxWidget.SetIsReadOnly(CurrentParam.IsReadOnly);
  1787. checkboxWidget.SetIsHidden(CurrentParam.IsHidden);
  1788. checkboxWidget.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  1789. checkboxWidget.UpdateFormAp();
  1790. successful = true;
  1791. return successful;
  1792. }
  1793. }
  1794. internal static bool SetRadioButtonParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  1795. {
  1796. RadioButtonParam CurrentParam = param as RadioButtonParam;
  1797. CPDFRadioButtonWidget radioWidget = cPDFAnnotation as CPDFRadioButtonWidget;
  1798. bool successful = false;
  1799. if (radioWidget == null && !radioWidget.IsValid() && CurrentParam == null)
  1800. {
  1801. return successful;
  1802. }
  1803. else
  1804. {
  1805. if (!string.IsNullOrEmpty(CurrentParam.FieldName))
  1806. {
  1807. radioWidget.SetFieldName(CurrentParam.FieldName);
  1808. }
  1809. radioWidget.SetWidgetCheckStyle(CurrentParam.CheckStyle);
  1810. radioWidget.SetChecked(CurrentParam.IsChecked);
  1811. if (CurrentParam.HasLineColor)
  1812. {
  1813. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  1814. {
  1815. radioWidget.SetWidgetBorderRGBColor(CurrentParam.LineColor);
  1816. }
  1817. }
  1818. if (CurrentParam.HasBgColor)
  1819. {
  1820. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  1821. {
  1822. radioWidget.SetWidgetBgRGBColor(CurrentParam.BgColor);
  1823. }
  1824. }
  1825. radioWidget.SetBorderWidth((float)CurrentParam.LineWidth);
  1826. radioWidget.SetWidgetBorderStyle(CurrentParam.BorderStyle);
  1827. if (CurrentParam.FontColor != null && CurrentParam.FontColor.Length == 3)
  1828. {
  1829. CTextAttribute textAttr = radioWidget.GetTextAttribute();
  1830. textAttr.FontColor = CurrentParam.FontColor;
  1831. radioWidget.SetTextAttribute(textAttr);
  1832. }
  1833. radioWidget.SetRect(CurrentParam.ClientRect);
  1834. radioWidget.SetFlags(CurrentParam.Flags);
  1835. radioWidget.SetIsLocked(CurrentParam.Locked);
  1836. radioWidget.SetIsReadOnly(CurrentParam.IsReadOnly);
  1837. radioWidget.SetIsHidden(CurrentParam.IsHidden);
  1838. radioWidget.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  1839. radioWidget.UpdateFormAp();
  1840. successful = true;
  1841. return successful;
  1842. }
  1843. }
  1844. internal static bool SetTextBoxParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  1845. {
  1846. TextBoxParam CurrentParam = param as TextBoxParam;
  1847. CPDFTextWidget textWidget = cPDFAnnotation as CPDFTextWidget;
  1848. bool successful = false;
  1849. if (textWidget == null && !textWidget.IsValid() && CurrentParam == null)
  1850. {
  1851. return successful;
  1852. }
  1853. else
  1854. {
  1855. if (!string.IsNullOrEmpty(CurrentParam.FieldName))
  1856. {
  1857. textWidget.SetFieldName(CurrentParam.FieldName);
  1858. }
  1859. if (CurrentParam.HasLineColor)
  1860. {
  1861. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  1862. {
  1863. textWidget.SetWidgetBorderRGBColor(CurrentParam.LineColor);
  1864. }
  1865. }
  1866. if (CurrentParam.HasBgColor)
  1867. {
  1868. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  1869. {
  1870. textWidget.SetWidgetBgRGBColor(CurrentParam.BgColor);
  1871. }
  1872. }
  1873. if (!string.IsNullOrEmpty(CurrentParam.Text))
  1874. {
  1875. textWidget.SetText(CurrentParam.Text);
  1876. }
  1877. CTextAttribute textAttr = new CTextAttribute();
  1878. byte[] fontColor = new byte[3];
  1879. if (CurrentParam.FontColor != null && CurrentParam.FontColor.Length == 3)
  1880. {
  1881. fontColor = CurrentParam.FontColor;
  1882. }
  1883. textAttr.FontColor = fontColor;
  1884. textAttr.FontSize = (float)CurrentParam.FontSize;
  1885. textAttr.FontName = ObtainFontName(
  1886. GetFontType(CurrentParam.FontName),
  1887. CurrentParam.IsBold,
  1888. CurrentParam.IsItalic);
  1889. textWidget.SetTextAttribute(textAttr);
  1890. textWidget.SetJustification(CurrentParam.Alignment);
  1891. textWidget.SetBorderWidth((float)CurrentParam.LineWidth);
  1892. textWidget.SetWidgetBorderStyle(CurrentParam.BorderStyle);
  1893. textWidget.SetMultiLine(CurrentParam.IsMultiLine);
  1894. textWidget.SetRect(CurrentParam.ClientRect);
  1895. textWidget.SetFlags(CurrentParam.Flags);
  1896. textWidget.SetIsLocked(CurrentParam.Locked);
  1897. textWidget.SetIsReadOnly(CurrentParam.IsReadOnly);
  1898. textWidget.SetIsHidden(CurrentParam.IsHidden);
  1899. textWidget.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  1900. textWidget.UpdateFormAp();
  1901. successful = true;
  1902. return successful;
  1903. }
  1904. }
  1905. internal static bool SetComboBoxParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  1906. {
  1907. ComboBoxParam CurrentParam = param as ComboBoxParam;
  1908. CPDFComboBoxWidget comboboxWidget = cPDFAnnotation as CPDFComboBoxWidget;
  1909. bool successful = false;
  1910. if (comboboxWidget == null && !comboboxWidget.IsValid() && CurrentParam == null)
  1911. {
  1912. return successful;
  1913. }
  1914. else
  1915. {
  1916. if (!string.IsNullOrEmpty(CurrentParam.FieldName))
  1917. {
  1918. comboboxWidget.SetFieldName(CurrentParam.FieldName);
  1919. }
  1920. if (CurrentParam.HasLineColor)
  1921. {
  1922. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  1923. {
  1924. comboboxWidget.SetWidgetBorderRGBColor(CurrentParam.LineColor);
  1925. }
  1926. }
  1927. if (CurrentParam.HasBgColor)
  1928. {
  1929. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  1930. {
  1931. comboboxWidget.SetWidgetBgRGBColor(CurrentParam.BgColor);
  1932. }
  1933. }
  1934. comboboxWidget.SetBorderWidth((float)CurrentParam.LineWidth);
  1935. comboboxWidget.SetWidgetBorderStyle(CurrentParam.BorderStyle);
  1936. CTextAttribute textAttr = new CTextAttribute();
  1937. byte[] fontColor = new byte[3];
  1938. if (CurrentParam.FontColor != null && CurrentParam.FontColor.Length == 3)
  1939. {
  1940. fontColor = CurrentParam.FontColor;
  1941. }
  1942. textAttr.FontColor = fontColor;
  1943. textAttr.FontSize = (float)CurrentParam.FontSize;
  1944. textAttr.FontName = ObtainFontName(
  1945. GetFontType(CurrentParam.FontName),
  1946. CurrentParam.IsBold,
  1947. CurrentParam.IsItalic);
  1948. comboboxWidget.SetTextAttribute(textAttr);
  1949. if (CurrentParam.OptionItems != null && CurrentParam.OptionItems.Count > 0)
  1950. {
  1951. int addIndex = 0;
  1952. foreach (string key in CurrentParam.OptionItems.Keys)
  1953. {
  1954. comboboxWidget.AddOptionItem(addIndex, CurrentParam.OptionItems[key], key);
  1955. addIndex++;
  1956. }
  1957. }
  1958. if (CurrentParam.SelectItemsIndex != null && CurrentParam.SelectItemsIndex.Count > 0)
  1959. {
  1960. comboboxWidget.SelectItem(CurrentParam.SelectItemsIndex[0]);
  1961. }
  1962. comboboxWidget.SetRect(CurrentParam.ClientRect);
  1963. comboboxWidget.SetFlags(CurrentParam.Flags);
  1964. comboboxWidget.SetIsLocked(CurrentParam.Locked);
  1965. comboboxWidget.SetIsReadOnly(CurrentParam.IsReadOnly);
  1966. comboboxWidget.SetIsHidden(CurrentParam.IsHidden);
  1967. comboboxWidget.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  1968. comboboxWidget.UpdateFormAp();
  1969. successful = true;
  1970. return successful;
  1971. }
  1972. }
  1973. internal static bool SetListBoxParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  1974. {
  1975. ListBoxParam CurrentParam = param as ListBoxParam;
  1976. CPDFListBoxWidget listboxWidget = cPDFAnnotation as CPDFListBoxWidget;
  1977. bool successful = false;
  1978. if (listboxWidget == null && !listboxWidget.IsValid() && CurrentParam == null)
  1979. {
  1980. return successful;
  1981. }
  1982. else
  1983. {
  1984. if (!string.IsNullOrEmpty(CurrentParam.FieldName))
  1985. {
  1986. listboxWidget.SetFieldName(CurrentParam.FieldName);
  1987. }
  1988. if (CurrentParam.HasLineColor)
  1989. {
  1990. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  1991. {
  1992. listboxWidget.SetWidgetBorderRGBColor(CurrentParam.LineColor);
  1993. }
  1994. }
  1995. if (CurrentParam.HasBgColor)
  1996. {
  1997. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  1998. {
  1999. listboxWidget.SetWidgetBgRGBColor(CurrentParam.BgColor);
  2000. }
  2001. }
  2002. listboxWidget.SetBorderWidth((float)CurrentParam.LineWidth);
  2003. listboxWidget.SetWidgetBorderStyle(CurrentParam.BorderStyle);
  2004. CTextAttribute textAttr = new CTextAttribute();
  2005. byte[] fontColor = new byte[3];
  2006. if (CurrentParam.FontColor != null && CurrentParam.FontColor.Length == 3)
  2007. {
  2008. fontColor = CurrentParam.FontColor;
  2009. }
  2010. textAttr.FontColor = fontColor;
  2011. textAttr.FontSize = (float)CurrentParam.FontSize;
  2012. textAttr.FontName = ObtainFontName(
  2013. GetFontType(CurrentParam.FontName),
  2014. CurrentParam.IsBold,
  2015. CurrentParam.IsItalic);
  2016. listboxWidget.SetTextAttribute(textAttr);
  2017. if (CurrentParam.OptionItems != null && CurrentParam.OptionItems.Count > 0)
  2018. {
  2019. int addIndex = 0;
  2020. foreach (string key in CurrentParam.OptionItems.Keys)
  2021. {
  2022. listboxWidget.AddOptionItem(addIndex, CurrentParam.OptionItems[key], key);
  2023. addIndex++;
  2024. }
  2025. }
  2026. if (CurrentParam.SelectItemsIndex != null && CurrentParam.SelectItemsIndex.Count > 0)
  2027. {
  2028. listboxWidget.SelectItem(CurrentParam.SelectItemsIndex[0]);
  2029. }
  2030. listboxWidget.SetRect(CurrentParam.ClientRect);
  2031. listboxWidget.SetFlags(CurrentParam.Flags);
  2032. listboxWidget.SetIsLocked(CurrentParam.Locked);
  2033. listboxWidget.SetIsReadOnly(CurrentParam.IsReadOnly);
  2034. listboxWidget.SetIsHidden(CurrentParam.IsHidden);
  2035. listboxWidget.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2036. listboxWidget.UpdateFormAp();
  2037. successful = true;
  2038. return successful;
  2039. }
  2040. }
  2041. internal static bool SetSignatureParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2042. {
  2043. SignatureParam CurrentParam = param as SignatureParam;
  2044. CPDFSignatureWidget signWidget = cPDFAnnotation as CPDFSignatureWidget;
  2045. bool successful = false;
  2046. if (signWidget == null && !signWidget.IsValid() && CurrentParam == null)
  2047. {
  2048. return successful;
  2049. }
  2050. else
  2051. {
  2052. if (!string.IsNullOrEmpty(CurrentParam.FieldName))
  2053. {
  2054. signWidget.SetFieldName(CurrentParam.FieldName);
  2055. }
  2056. if (CurrentParam.HasLineColor)
  2057. {
  2058. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  2059. {
  2060. signWidget.SetWidgetBorderRGBColor(CurrentParam.LineColor);
  2061. }
  2062. }
  2063. if (CurrentParam.HasBgColor)
  2064. {
  2065. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  2066. {
  2067. signWidget.SetWidgetBgRGBColor(CurrentParam.BgColor);
  2068. }
  2069. }
  2070. signWidget.SetBorderWidth((float)CurrentParam.LineWidth);
  2071. signWidget.SetWidgetBorderStyle(CurrentParam.BorderStyle);
  2072. signWidget.SetRect(CurrentParam.ClientRect);
  2073. signWidget.SetFlags(CurrentParam.Flags);
  2074. signWidget.SetIsLocked(CurrentParam.Locked);
  2075. signWidget.SetIsReadOnly(CurrentParam.IsReadOnly);
  2076. signWidget.SetIsHidden(CurrentParam.IsHidden);
  2077. signWidget.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2078. signWidget.UpdateFormAp();
  2079. successful = true;
  2080. return successful;
  2081. }
  2082. }
  2083. #endregion
  2084. #region SetAnnot
  2085. internal static bool SetAnnotParamForPDFAnnot(CPDFDocument cPDFDocument, CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2086. {
  2087. bool successful = false;
  2088. if (cPDFAnnotation != null)
  2089. {
  2090. switch (cPDFAnnotation.Type)
  2091. {
  2092. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
  2093. successful = SetSquareAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2094. break;
  2095. case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
  2096. successful = SetCircleAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2097. break;
  2098. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  2099. successful = SetLineAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2100. break;
  2101. case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
  2102. successful = SetInkAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2103. break;
  2104. case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
  2105. successful = SetFreeTextAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2106. break;
  2107. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  2108. successful = SetHighlightAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2109. break;
  2110. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  2111. successful = SetUnderlineAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2112. break;
  2113. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  2114. successful = SetStrikeoutAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2115. break;
  2116. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  2117. successful = SetSquigglyAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2118. break;
  2119. case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
  2120. successful = SetTextAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2121. break;
  2122. case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
  2123. successful = SetStampAnnotParamForPDFAnnot(cPDFAnnotation, param);
  2124. break;
  2125. case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
  2126. successful = SetLinkAnnotParamForPDFAnnot(cPDFDocument, cPDFAnnotation, param);
  2127. break;
  2128. default:
  2129. break;
  2130. }
  2131. }
  2132. return successful;
  2133. }
  2134. internal static bool SetSquareAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2135. {
  2136. SquareParam CurrentParam = param as SquareParam;
  2137. CPDFSquareAnnotation squareAnnot = cPDFAnnotation as CPDFSquareAnnotation;
  2138. bool successful = false;
  2139. if (squareAnnot == null && !squareAnnot.IsValid() && CurrentParam == null)
  2140. {
  2141. return successful;
  2142. }
  2143. else
  2144. {
  2145. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  2146. {
  2147. squareAnnot.SetLineColor(CurrentParam.LineColor);
  2148. }
  2149. if (CurrentParam.HasBgColor)
  2150. {
  2151. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  2152. {
  2153. squareAnnot.SetBgColor(CurrentParam.BgColor);
  2154. }
  2155. }
  2156. squareAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2157. squareAnnot.SetLineWidth((byte)CurrentParam.LineWidth);
  2158. squareAnnot.SetRect(CurrentParam.ClientRect);
  2159. List<float> floatArray = new List<float>();
  2160. if (CurrentParam.LineDash != null)
  2161. {
  2162. foreach (float num in CurrentParam.LineDash)
  2163. {
  2164. floatArray.Add(num);
  2165. }
  2166. }
  2167. squareAnnot.SetBorderStyle(CurrentParam.BorderStyle, floatArray.ToArray());
  2168. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2169. {
  2170. squareAnnot.SetAuthor(CurrentParam.Author);
  2171. }
  2172. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2173. {
  2174. squareAnnot.SetContent(CurrentParam.Content);
  2175. }
  2176. squareAnnot.SetIsLocked(CurrentParam.Locked);
  2177. squareAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2178. squareAnnot.UpdateAp();
  2179. successful = true;
  2180. return successful;
  2181. }
  2182. }
  2183. internal static bool SetCircleAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2184. {
  2185. CircleParam CurrentParam = param as CircleParam;
  2186. CPDFCircleAnnotation circleAnnot = cPDFAnnotation as CPDFCircleAnnotation;
  2187. bool successful = false;
  2188. if (circleAnnot == null && !circleAnnot.IsValid() && CurrentParam == null)
  2189. {
  2190. return successful;
  2191. }
  2192. else
  2193. {
  2194. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  2195. {
  2196. circleAnnot.SetLineColor(CurrentParam.LineColor);
  2197. }
  2198. if (CurrentParam.HasBgColor)
  2199. {
  2200. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  2201. {
  2202. circleAnnot.SetBgColor(CurrentParam.BgColor);
  2203. }
  2204. }
  2205. circleAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2206. circleAnnot.SetLineWidth((byte)CurrentParam.LineWidth);
  2207. circleAnnot.SetRect(CurrentParam.ClientRect);
  2208. List<float> floatArray = new List<float>();
  2209. if (CurrentParam.LineDash != null)
  2210. {
  2211. foreach (float num in CurrentParam.LineDash)
  2212. {
  2213. floatArray.Add(num);
  2214. }
  2215. }
  2216. circleAnnot.SetBorderStyle(CurrentParam.BorderStyle, floatArray.ToArray());
  2217. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2218. {
  2219. circleAnnot.SetAuthor(CurrentParam.Author);
  2220. }
  2221. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2222. {
  2223. circleAnnot.SetContent(CurrentParam.Content);
  2224. }
  2225. circleAnnot.SetIsLocked(CurrentParam.Locked);
  2226. circleAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2227. circleAnnot.UpdateAp();
  2228. successful = true;
  2229. return successful;
  2230. }
  2231. }
  2232. internal static bool SetLineAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2233. {
  2234. LineParam CurrentParam = param as LineParam;
  2235. CPDFLineAnnotation lineAnnot = cPDFAnnotation as CPDFLineAnnotation;
  2236. bool successful = false;
  2237. if (lineAnnot == null && !lineAnnot.IsValid() && CurrentParam == null)
  2238. {
  2239. return successful;
  2240. }
  2241. else
  2242. {
  2243. if (CurrentParam.HeadLineType != C_LINE_TYPE.LINETYPE_NONE || CurrentParam.TailLineType != C_LINE_TYPE.LINETYPE_NONE)
  2244. {
  2245. lineAnnot.SetLineType(CurrentParam.HeadLineType, CurrentParam.TailLineType);
  2246. }
  2247. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  2248. {
  2249. lineAnnot.SetLineColor(CurrentParam.LineColor);
  2250. }
  2251. if (CurrentParam.HasBgColor)
  2252. {
  2253. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  2254. {
  2255. lineAnnot.SetBgColor(CurrentParam.BgColor);
  2256. }
  2257. }
  2258. lineAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2259. lineAnnot.SetLineWidth((byte)CurrentParam.LineWidth);
  2260. lineAnnot.SetLinePoints(CurrentParam.HeadPoint, CurrentParam.TailPoint);
  2261. lineAnnot.SetRect(CurrentParam.ClientRect);
  2262. List<float> floatArray = new List<float>();
  2263. if (CurrentParam.LineDash != null)
  2264. {
  2265. foreach (float num in CurrentParam.LineDash)
  2266. {
  2267. floatArray.Add(num);
  2268. }
  2269. }
  2270. lineAnnot.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, floatArray.ToArray());
  2271. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2272. {
  2273. lineAnnot.SetAuthor(CurrentParam.Author);
  2274. }
  2275. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2276. {
  2277. lineAnnot.SetContent(CurrentParam.Content);
  2278. }
  2279. lineAnnot.SetIsLocked(CurrentParam.Locked);
  2280. lineAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2281. lineAnnot.UpdateAp();
  2282. successful = true;
  2283. return successful;
  2284. }
  2285. }
  2286. internal static bool SetInkAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2287. {
  2288. InkParam CurrentParam = param as InkParam;
  2289. CPDFInkAnnotation inkAnnot = cPDFAnnotation as CPDFInkAnnotation;
  2290. bool successful = false;
  2291. if (inkAnnot == null && !inkAnnot.IsValid() && CurrentParam == null)
  2292. {
  2293. return successful;
  2294. }
  2295. else
  2296. {
  2297. if (CurrentParam.InkColor != null && CurrentParam.InkColor.Length == 3)
  2298. {
  2299. inkAnnot.SetInkColor(CurrentParam.InkColor);
  2300. }
  2301. inkAnnot.SetThickness((float)CurrentParam.Thickness);
  2302. inkAnnot.SetInkPath(CurrentParam.InkPath);
  2303. inkAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2304. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2305. {
  2306. inkAnnot.SetAuthor(CurrentParam.Author);
  2307. }
  2308. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2309. {
  2310. inkAnnot.SetContent(CurrentParam.Content);
  2311. }
  2312. inkAnnot.SetIsLocked(CurrentParam.Locked);
  2313. inkAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2314. inkAnnot.UpdateAp();
  2315. successful = true;
  2316. return successful;
  2317. }
  2318. }
  2319. internal static bool SetHighlightAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2320. {
  2321. HighlightParam CurrentParam = param as HighlightParam;
  2322. CPDFHighlightAnnotation highlightAnnot = cPDFAnnotation as CPDFHighlightAnnotation;
  2323. bool successful = false;
  2324. if (highlightAnnot == null && !highlightAnnot.IsValid() && CurrentParam == null)
  2325. {
  2326. return successful;
  2327. }
  2328. else
  2329. {
  2330. highlightAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2331. if (CurrentParam.QuardRects != null)
  2332. {
  2333. highlightAnnot.SetQuardRects(CurrentParam.QuardRects);
  2334. }
  2335. if (CurrentParam.HighlightColor != null && CurrentParam.HighlightColor.Length == 3)
  2336. {
  2337. highlightAnnot.SetColor(CurrentParam.HighlightColor);
  2338. }
  2339. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2340. {
  2341. highlightAnnot.SetAuthor(CurrentParam.Author);
  2342. }
  2343. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2344. {
  2345. highlightAnnot.SetContent(CurrentParam.Content);
  2346. }
  2347. highlightAnnot.SetRect(CurrentParam.ClientRect);
  2348. highlightAnnot.SetIsLocked(CurrentParam.Locked);
  2349. highlightAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2350. highlightAnnot.UpdateAp();
  2351. successful = true;
  2352. return successful;
  2353. }
  2354. }
  2355. internal static bool SetUnderlineAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2356. {
  2357. UnderlineParam CurrentParam = param as UnderlineParam;
  2358. CPDFUnderlineAnnotation underlineAnnot = cPDFAnnotation as CPDFUnderlineAnnotation;
  2359. bool successful = false;
  2360. if (underlineAnnot == null && !underlineAnnot.IsValid() && CurrentParam == null)
  2361. {
  2362. return successful;
  2363. }
  2364. else
  2365. {
  2366. underlineAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2367. underlineAnnot.SetRect(CurrentParam.ClientRect);
  2368. if (CurrentParam.QuardRects != null)
  2369. {
  2370. underlineAnnot.SetQuardRects(CurrentParam.QuardRects);
  2371. }
  2372. if (CurrentParam.UnderlineColor != null && CurrentParam.UnderlineColor.Length == 3)
  2373. {
  2374. underlineAnnot.SetColor(CurrentParam.UnderlineColor);
  2375. }
  2376. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2377. {
  2378. underlineAnnot.SetAuthor(CurrentParam.Author);
  2379. }
  2380. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2381. {
  2382. underlineAnnot.SetContent(CurrentParam.Content);
  2383. }
  2384. underlineAnnot.SetIsLocked(CurrentParam.Locked);
  2385. underlineAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2386. underlineAnnot.UpdateAp();
  2387. successful = true;
  2388. return successful;
  2389. }
  2390. }
  2391. internal static bool SetStrikeoutAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2392. {
  2393. StrikeoutParam CurrentParam = param as StrikeoutParam;
  2394. CPDFStrikeoutAnnotation strikeoutAnnot = cPDFAnnotation as CPDFStrikeoutAnnotation;
  2395. bool successful = false;
  2396. if (strikeoutAnnot == null && !strikeoutAnnot.IsValid() && CurrentParam == null)
  2397. {
  2398. return successful;
  2399. }
  2400. else
  2401. {
  2402. strikeoutAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2403. strikeoutAnnot.SetRect(CurrentParam.ClientRect);
  2404. if (CurrentParam.QuardRects != null)
  2405. {
  2406. strikeoutAnnot.SetQuardRects(CurrentParam.QuardRects);
  2407. }
  2408. if (CurrentParam.StrikeoutColor != null && CurrentParam.StrikeoutColor.Length == 3)
  2409. {
  2410. strikeoutAnnot.SetColor(CurrentParam.StrikeoutColor);
  2411. }
  2412. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2413. {
  2414. strikeoutAnnot.SetAuthor(CurrentParam.Author);
  2415. }
  2416. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2417. {
  2418. strikeoutAnnot.SetContent(CurrentParam.Content);
  2419. }
  2420. strikeoutAnnot.SetIsLocked(CurrentParam.Locked);
  2421. strikeoutAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2422. strikeoutAnnot.UpdateAp();
  2423. successful = true;
  2424. return successful;
  2425. }
  2426. }
  2427. internal static bool SetSquigglyAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2428. {
  2429. SquigglyParam CurrentParam = param as SquigglyParam;
  2430. CPDFSquigglyAnnotation squigglyAnnot = cPDFAnnotation as CPDFSquigglyAnnotation;
  2431. bool successful = false;
  2432. if (squigglyAnnot == null && !squigglyAnnot.IsValid() && CurrentParam == null)
  2433. {
  2434. return successful;
  2435. }
  2436. else
  2437. {
  2438. squigglyAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2439. squigglyAnnot.SetRect(CurrentParam.ClientRect);
  2440. if (CurrentParam.QuardRects != null)
  2441. {
  2442. squigglyAnnot.SetQuardRects(CurrentParam.QuardRects);
  2443. }
  2444. if (CurrentParam.SquigglyColor != null && CurrentParam.SquigglyColor.Length == 3)
  2445. {
  2446. squigglyAnnot.SetColor(CurrentParam.SquigglyColor);
  2447. }
  2448. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2449. {
  2450. squigglyAnnot.SetAuthor(CurrentParam.Author);
  2451. }
  2452. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2453. {
  2454. squigglyAnnot.SetContent(CurrentParam.Content);
  2455. }
  2456. squigglyAnnot.SetIsLocked(CurrentParam.Locked);
  2457. squigglyAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2458. squigglyAnnot.UpdateAp();
  2459. successful = true;
  2460. return successful;
  2461. }
  2462. }
  2463. internal static bool SetFreeTextAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2464. {
  2465. FreeTextParam CurrentParam = param as FreeTextParam;
  2466. CPDFFreeTextAnnotation textAnnot = cPDFAnnotation as CPDFFreeTextAnnotation;
  2467. bool successful = false;
  2468. if (textAnnot == null && !textAnnot.IsValid() && CurrentParam == null)
  2469. {
  2470. return successful;
  2471. }
  2472. else
  2473. {
  2474. if (CurrentParam.LineColor != null && CurrentParam.LineColor.Length == 3)
  2475. {
  2476. textAnnot.SetLineColor(CurrentParam.LineColor);
  2477. }
  2478. if (CurrentParam.HasBgColor)
  2479. {
  2480. if (CurrentParam.BgColor != null && CurrentParam.BgColor.Length == 3)
  2481. {
  2482. textAnnot.SetBgColor(CurrentParam.BgColor);
  2483. }
  2484. }
  2485. textAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2486. textAnnot.SetLineWidth((byte)CurrentParam.LineWidth);
  2487. textAnnot.SetFreetextAlignment(CurrentParam.Alignment);
  2488. CTextAttribute textAttr = new CTextAttribute();
  2489. byte[] fontColor = new byte[3];
  2490. if (CurrentParam.FontColor != null && CurrentParam.FontColor.Length == 3)
  2491. {
  2492. fontColor = CurrentParam.FontColor;
  2493. }
  2494. textAttr.FontColor = fontColor;
  2495. textAttr.FontSize = (float)CurrentParam.FontSize;
  2496. textAttr.FontName = ObtainFontName(
  2497. GetFontType(CurrentParam.FontName),
  2498. CurrentParam.IsBold,
  2499. CurrentParam.IsItalic);
  2500. textAnnot.SetFreetextDa(textAttr);
  2501. textAnnot.SetRect(CurrentParam.ClientRect);
  2502. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2503. {
  2504. textAnnot.SetAuthor(CurrentParam.Author);
  2505. }
  2506. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2507. {
  2508. textAnnot.SetContent(CurrentParam.Content);
  2509. }
  2510. textAnnot.SetIsLocked(CurrentParam.Locked);
  2511. textAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2512. textAnnot.UpdateAp();
  2513. successful = true;
  2514. return successful;
  2515. }
  2516. }
  2517. internal static bool SetStampAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2518. {
  2519. StampParam CurrentParam = param as StampParam;
  2520. CPDFStampAnnotation stampAnnot = cPDFAnnotation as CPDFStampAnnotation;
  2521. bool successful = false;
  2522. if (stampAnnot == null && !stampAnnot.IsValid() && CurrentParam == null)
  2523. {
  2524. return successful;
  2525. }
  2526. else
  2527. {
  2528. switch (CurrentParam.StampType)
  2529. {
  2530. case C_STAMP_TYPE.STANDARD_STAMP:
  2531. {
  2532. string stampText = CurrentParam.StampText;
  2533. if (stampText == null)
  2534. {
  2535. stampText = string.Empty;
  2536. }
  2537. stampAnnot.SetStandardStamp(stampText, CurrentParam.Rotation);
  2538. stampAnnot.SetRect(CurrentParam.ClientRect);
  2539. }
  2540. break;
  2541. case C_STAMP_TYPE.TEXT_STAMP:
  2542. {
  2543. string dateText = CurrentParam.DateText;
  2544. string stampText = CurrentParam.StampText;
  2545. if (dateText == null)
  2546. {
  2547. dateText = string.Empty;
  2548. }
  2549. if (stampText == null)
  2550. {
  2551. stampText = string.Empty;
  2552. }
  2553. stampAnnot.SetTextStamp(
  2554. stampText,
  2555. dateText,
  2556. CurrentParam.TextStampShape,
  2557. CurrentParam.TextStampColor,
  2558. CurrentParam.Rotation);
  2559. stampAnnot.SetRect(CurrentParam.ClientRect);
  2560. }
  2561. break;
  2562. case C_STAMP_TYPE.IMAGE_STAMP:
  2563. {
  2564. byte[] imageData = null;
  2565. int imageWidth = 0;
  2566. int imageHeight = 0;
  2567. PDFHelp.ImageStreamToByte(CurrentParam.ImageStream, ref imageData, ref imageWidth, ref imageHeight);
  2568. if (imageData != null && imageWidth > 0 && imageHeight > 0)
  2569. {
  2570. stampAnnot.SetRect(CurrentParam.ClientRect);
  2571. stampAnnot.SetImageStamp(
  2572. imageData,
  2573. imageWidth,
  2574. imageHeight,
  2575. CurrentParam.Rotation);
  2576. }
  2577. }
  2578. break;
  2579. default:
  2580. break;
  2581. }
  2582. stampAnnot.SetTransparency((byte)CurrentParam.Transparency);
  2583. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2584. {
  2585. stampAnnot.SetAuthor(CurrentParam.Author);
  2586. }
  2587. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2588. {
  2589. stampAnnot.SetContent(CurrentParam.Content);
  2590. }
  2591. stampAnnot.SetIsLocked(CurrentParam.Locked);
  2592. stampAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2593. stampAnnot.UpdateAp();
  2594. successful = true;
  2595. return successful;
  2596. }
  2597. }
  2598. internal static bool SetLinkAnnotParamForPDFAnnot(CPDFDocument cPDFDocument, CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2599. {
  2600. LinkParam CurrentParam = param as LinkParam;
  2601. CPDFLinkAnnotation linkAnnot = cPDFAnnotation as CPDFLinkAnnotation;
  2602. bool successful = false;
  2603. if (linkAnnot == null && !linkAnnot.IsValid() && CurrentParam == null)
  2604. {
  2605. return successful;
  2606. }
  2607. else
  2608. {
  2609. switch (CurrentParam.Action)
  2610. {
  2611. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  2612. {
  2613. CPDFGoToAction gotoAction = new CPDFGoToAction();
  2614. CPDFDestination destination = new CPDFDestination();
  2615. destination.Position_X = CurrentParam.DestinationPosition.x;
  2616. destination.Position_Y = CurrentParam.DestinationPosition.y;
  2617. destination.PageIndex = CurrentParam.DestinationPageIndex;
  2618. gotoAction.SetDestination(cPDFDocument, destination);
  2619. linkAnnot.SetLinkAction(gotoAction);
  2620. }
  2621. break;
  2622. case C_ACTION_TYPE.ACTION_TYPE_URI:
  2623. {
  2624. CPDFUriAction uriAction = new CPDFUriAction();
  2625. if (!string.IsNullOrEmpty(CurrentParam.Uri))
  2626. {
  2627. uriAction.SetUri(CurrentParam.Uri);
  2628. }
  2629. linkAnnot.SetLinkAction(uriAction);
  2630. }
  2631. break;
  2632. default:
  2633. break;
  2634. }
  2635. linkAnnot.SetRect(CurrentParam.ClientRect);
  2636. if (!string.IsNullOrEmpty(CurrentParam.Author))
  2637. {
  2638. linkAnnot.SetAuthor(CurrentParam.Author);
  2639. }
  2640. if (!string.IsNullOrEmpty(CurrentParam.Content))
  2641. {
  2642. linkAnnot.SetContent(CurrentParam.Content);
  2643. }
  2644. linkAnnot.SetIsLocked(CurrentParam.Locked);
  2645. linkAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2646. linkAnnot.UpdateAp();
  2647. successful = true;
  2648. return successful;
  2649. }
  2650. }
  2651. internal static bool SetTextAnnotParamForPDFAnnot(CPDFAnnotation cPDFAnnotation, AnnotParam param)
  2652. {
  2653. StickyNoteParam textAnnotParam = param as StickyNoteParam;
  2654. CPDFTextAnnotation textAnnot = cPDFAnnotation as CPDFTextAnnotation;
  2655. if (textAnnot == null && !textAnnot.IsValid() && textAnnotParam == null)
  2656. {
  2657. return false;
  2658. }
  2659. else
  2660. {
  2661. if (textAnnotParam.StickyNoteColor != null && textAnnotParam.StickyNoteColor.Length == 3)
  2662. {
  2663. textAnnot.SetColor(textAnnotParam.StickyNoteColor);
  2664. }
  2665. textAnnot.SetTransparency((byte)textAnnotParam.Transparency);
  2666. textAnnot.SetRect(textAnnotParam.ClientRect);
  2667. if (!string.IsNullOrEmpty(textAnnotParam.Author))
  2668. {
  2669. textAnnot.SetAuthor(textAnnotParam.Author);
  2670. }
  2671. if (!string.IsNullOrEmpty(textAnnotParam.Content))
  2672. {
  2673. textAnnot.SetContent(textAnnotParam.Content);
  2674. }
  2675. textAnnot.SetIsLocked(textAnnotParam.Locked);
  2676. textAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2677. textAnnot.UpdateAp();
  2678. return true;
  2679. }
  2680. }
  2681. #endregion
  2682. public static bool SetParamForPDFEdit(CPDFEditArea cPDFEditArea, PDFEditParam param)
  2683. {
  2684. bool successful = false;
  2685. if (cPDFEditArea == null && !cPDFEditArea.IsValid())
  2686. {
  2687. return successful;
  2688. }
  2689. switch (cPDFEditArea.Type)
  2690. {
  2691. case CPDFEditType.EditText:
  2692. SetParamForPDFTextEdit(cPDFEditArea, param);
  2693. break;
  2694. default:
  2695. break;
  2696. }
  2697. return successful;
  2698. }
  2699. internal static bool SetParamForPDFTextEdit(CPDFEditArea cPDFEditArea, PDFEditParam param)
  2700. {
  2701. TextEditParam CurrentParam = param as TextEditParam;
  2702. CPDFEditTextArea cPDFEditTextArea = cPDFEditArea as CPDFEditTextArea;
  2703. bool successful = false;
  2704. if (cPDFEditTextArea == null && !cPDFEditTextArea.IsValid() && CurrentParam == null)
  2705. {
  2706. return successful;
  2707. }
  2708. else
  2709. {
  2710. cPDFEditTextArea.SetCharsFontTransparency(param.Transparency);
  2711. cPDFEditTextArea.SetFrame(
  2712. DataConversionForWPF.RectConversionForCRect(
  2713. new Rect(CurrentParam.ClientRect.left, CurrentParam.ClientRect.top, CurrentParam.ClientRect.width(), CurrentParam.ClientRect.height())
  2714. ));
  2715. cPDFEditTextArea.SetCharsFontSize((float)CurrentParam.FontSize, true);
  2716. if (CurrentParam.FontColor != null && CurrentParam.FontColor.Length == 3)
  2717. {
  2718. cPDFEditTextArea.SetCharsFontColor(CurrentParam.FontColor[0], CurrentParam.FontColor[1], CurrentParam.FontColor[2]);
  2719. }
  2720. cPDFEditTextArea.SetTextAreaAlign(CurrentParam.TextAlign);
  2721. cPDFEditTextArea.SetCharsFontName(CurrentParam.FontName);
  2722. cPDFEditTextArea.SetCharsFontItalic(CurrentParam.IsItalic);
  2723. cPDFEditTextArea.SetCharsFontBold(CurrentParam.IsBold);
  2724. successful = true;
  2725. return successful;
  2726. }
  2727. }
  2728. internal static bool SetParamForPDFImageEdit(CPDFEditArea cPDFEditArea, PDFEditParam param)
  2729. {
  2730. ImageEditParam CurrentParam = param as ImageEditParam;
  2731. CPDFEditImageArea cPDFEditImageArea = cPDFEditArea as CPDFEditImageArea;
  2732. bool successful = false;
  2733. if (cPDFEditImageArea == null && !cPDFEditImageArea.IsValid() && CurrentParam == null)
  2734. {
  2735. return successful;
  2736. }
  2737. else
  2738. {
  2739. cPDFEditImageArea.SetImageTransparency(param.Transparency);
  2740. cPDFEditImageArea.SetFrame(
  2741. DataConversionForWPF.RectConversionForCRect(
  2742. new Rect(CurrentParam.ClientRect.left, CurrentParam.ClientRect.top, CurrentParam.ClientRect.width(), CurrentParam.ClientRect.height())
  2743. ))
  2744. ;
  2745. cPDFEditImageArea.CutWithRect(
  2746. DataConversionForWPF.RectConversionForCRect(
  2747. new Rect(CurrentParam.ClipRect.left, CurrentParam.ClipRect.top, CurrentParam.ClipRect.width(), CurrentParam.ClipRect.height())
  2748. ));
  2749. successful = true;
  2750. return successful;
  2751. }
  2752. }
  2753. }
  2754. }