ParamConverter.cs 127 KB

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