ParamConverter.cs 125 KB

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