1
1

PhotoForm.frm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. VERSION 5.00
  2. Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} PhotoForm
  3. Caption = "Batch Convert Or Export JPEG PDF"
  4. ClientHeight = 2265
  5. ClientLeft = 45
  6. ClientTop = 375
  7. ClientWidth = 3855
  8. OleObjectBlob = "PhotoForm.frx":0000
  9. ShowModal = 0 'False
  10. StartUpPosition = 1 'CenterOwner
  11. End
  12. Attribute VB_Name = "PhotoForm"
  13. Attribute VB_GlobalNameSpace = False
  14. Attribute VB_Creatable = False
  15. Attribute VB_PredeclaredId = True
  16. Attribute VB_Exposed = False
  17. Private Sub UserForm_Initialize()
  18. On Error Resume Next
  19. ComboBox1.AddItem "灰度"
  20. ComboBox1.AddItem "CMYK颜色"
  21. ComboBox1.AddItem "RGB颜色"
  22. ComboBox1.AddItem "黑白"
  23. ComboBox2.AddItem "300", 0
  24. ComboBox2.AddItem "450", 1
  25. ComboBox2.AddItem "600", 2
  26. ComboBox2.AddItem "150", 3
  27. TextBox1.text = Left(ActiveDocument.fileName, InStrRev(ActiveDocument.fileName, ".") - 1)
  28. End Sub
  29. Private Sub CovPhotos_Click()
  30. On Error Resume Next
  31. ActiveDocument.BeginCommandGroup
  32. Dim Color As String
  33. Dim a, b As Boolean
  34. Dim i, dpi As Integer
  35. a = True: b = True
  36. If ABox1.value = False Then a = False
  37. If BBox2.value = False Then b = False
  38. dpi = CInt(ComboBox2.text)
  39. Select Case ComboBox1.text
  40. Case Is = "灰度"
  41. Color = cdrGrayscaleImage
  42. Case Is = "CMYK颜色"
  43. Color = cdrCMYKColorImage
  44. Case Is = "RGB颜色"
  45. Color = cdrRGBColorImage
  46. Case Is = "黑白"
  47. Color = cdrBlackAndWhiteImage
  48. End Select
  49. Dim s As Shapes
  50. Set s = ActiveSelection.Shapes
  51. If s Is Nothing Then
  52. MsgBox "请先选中一个形状!"
  53. Exit Sub
  54. Else
  55. For i = 1 To s.count
  56. Set s(i) = ActiveShape.ConvertToBitmapEx(Color, False, a, dpi, cdrNormalAntiAliasing, True, False, 95)
  57. Next i
  58. End If
  59. ActiveDocument.EndCommandGroup
  60. End Sub
  61. '// 批量导出JPEG
  62. Private Sub Export_JPEG_Click()
  63. On Error GoTo ErrorHandler
  64. Dim d As Document
  65. Set d = ActiveDocument
  66. Dim sh As Shape, shs As Shapes
  67. Dim Color As String
  68. Set shs = ActiveSelection.Shapes
  69. dpi = CInt(ComboBox2.text)
  70. Select Case ComboBox1.text
  71. Case Is = "灰度"
  72. Color = cdrGrayscaleImage
  73. Case Is = "CMYK颜色"
  74. Color = cdrCMYKColorImage
  75. Case Is = "RGB颜色"
  76. Color = cdrRGBColorImage
  77. Case Is = "黑白"
  78. Color = cdrBlackAndWhiteImage
  79. End Select
  80. '// 导出图片精度设置,设置颜色模式
  81. Dim opt As New StructExportOptions
  82. opt.ResolutionX = dpi
  83. opt.ResolutionY = dpi
  84. opt.ImageType = Color
  85. Dim path$: path = CorelScriptTools.GetFolder(d.FilePath)
  86. '// 批处理导出图片
  87. For Each sh In shs
  88. ActiveDocument.ClearSelection
  89. sh.CreateSelection
  90. ' 导出图片 JPEG格式
  91. f = path & "\" & TextBox1.text & "_ID" & sh.StaticID & ".jpg"
  92. d.Export f, cdrJPEG, cdrSelection, opt
  93. Next sh
  94. ErrorHandler:
  95. End Sub
  96. '// 批量导出 PDF
  97. Private Sub Export_PDF_Click()
  98. On Error GoTo ErrorHandler
  99. Dim d As Document
  100. Set d = ActiveDocument
  101. With d.PDFSettings
  102. .PublishRange = 2 ' CdrPDFVBA.pdfSelection
  103. .BitmapCompression = 1 ' CdrPDFVBA.pdfLZW
  104. .JPEGQualityFactor = 2
  105. .SubsetPct = 80
  106. .Encoding = 1 ' CdrPDFVBA.pdfBinary
  107. .ColorResolution = 300
  108. .MonoResolution = 1200
  109. .GrayResolution = 300
  110. .Startup = 0 ' CdrPDFVBA.pdfPageOnly
  111. .Overprints = True
  112. .Halftones = True
  113. .FountainSteps = 256
  114. .pdfVersion = 6 ' CdrPDFVBA.pdfVersion15
  115. .ColorMode = 3 ' CdrPDFVBA.pdfNative
  116. .ColorProfile = 1 ' CdrPDFVBA.pdfSeparationProfile
  117. .JP2QualityFactor = 2
  118. .EncryptType = 1 ' CdrPDFVBA.pdfEncryptTypeStandard
  119. .TextAsCurves = True ' 文字转曲
  120. End With
  121. '// 选择物件,按群组批量导出PDF
  122. Dim path$: path = CorelScriptTools.GetFolder(d.FilePath)
  123. Dim sr As ShapeRange, sh As Shape
  124. Set sr = ActiveSelectionRange
  125. For Each sh In sr
  126. ActiveDocument.ClearSelection
  127. sh.CreateSelection
  128. f = path & "\" & TextBox1.text & "_ID" & sh.StaticID & ".pdf"
  129. d.PublishToPDF f
  130. Next sh
  131. ErrorHandler:
  132. End Sub