ParamConverter.cs 125 KB

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