Ver código fonte

compdfkit(win) - VB Samples - 注释导入导出

liuaoran 1 ano atrás
pai
commit
f491d3f743

+ 4 - 4
Demo/Examples/Samples/AnnotationImportExportTest/CS/AnnotationImportExportTest.cs

@@ -6,8 +6,8 @@ namespace AnnotationImportExportTest
 {
     internal class AnnotationImportExportTest
     {
-        private static string outputPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()))) + "\\Output\\AnnotationImportExportTest";
-        private static string tempPath = outputPath + "\\temp";
+        private static string outputPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()))) + @"\Output\CS";
+        private static string tempPath = outputPath + @"\temp";
 
         static void Main(string[] args)
         {
@@ -74,7 +74,7 @@ namespace AnnotationImportExportTest
         /// <returns></returns>
         static private bool ExportAnnotaiton(CPDFDocument document)
         {
-            var path = outputPath + "\\ExportAnnotationTest.xfdf";
+            var path = outputPath + @"\ExportAnnotationTest.xfdf";
             if (!document.ExportAnnotationToXFDFPath(path, tempPath))
             {
                 return false;
@@ -94,7 +94,7 @@ namespace AnnotationImportExportTest
         /// <returns></returns>
         static private bool ImportAnnotaiton(CPDFDocument document)
         {
-            var path = outputPath + "//ImportAnnotationTest.pdf";
+            var path = outputPath + @"\ImportAnnotationTest.pdf";
 
             if (!document.ImportAnnotationFromXFDFPath("Annotations.xfdf", tempPath))
             {

+ 67 - 2
Demo/Examples/Samples/AnnotationImportExportTest/VB/AnnotationImportExport.vb

@@ -1,10 +1,75 @@
-Module AnnotationImportExport
+Imports ComPDFKit.PDFDocument
+Imports System
+Imports System.IO
 
+
+Module AnnotationImportExport
+    Private parentPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())))
+    Private outputPath As String = Path.Combine(parentPath, "Output", "VB")
+    Private tempPath As String = outputPath & "\temp"
     Sub Main()
         Dim result As Boolean = SDKLicenseHelper.LicenseVerify()
-        Console.WriteLine(result.ToString())
+        Console.WriteLine("Running header and footer test sample…" & vbCrLf)
+
+        ' Preparation work
+        SDKLicenseHelper.LicenseVerify()
+
+        If Not Directory.Exists(outputPath) Then
+            Directory.CreateDirectory(outputPath)
+        End If
+        If Not Directory.Exists(tempPath) Then
+            Directory.CreateDirectory(tempPath)
+        End If
+
+        ' Sample 1: Export Annotation
+        Dim annotationsDocument As CPDFDocument = CPDFDocument.InitWithFilePath("Annotations.pdf")
+
+        If ExportAnnotation(annotationsDocument) Then
+            Console.WriteLine("Export annotation done.")
+        Else
+            Console.WriteLine("Export annotation failed.")
+        End If
+
+        Console.WriteLine("--------------------")
+
+        ' Sample 2: Import Annotations
+        Dim document As CPDFDocument = CPDFDocument.InitWithFilePath("CommonFivePage.pdf")
+
+        If ImportAnnotation(document) Then
+            Console.WriteLine("Import annotation done.")
+        Else
+            Console.WriteLine("Import annotation failed.")
+        End If
+
+        Console.WriteLine("--------------------")
+
+        Console.WriteLine("Done")
+        Console.WriteLine("--------------------")
         Console.ReadLine()
     End Sub
 
+    ' Export the annotations in the document to XFDF format
+    Private Function ExportAnnotation(document As CPDFDocument) As Boolean
+        Dim path As String = outputPath & "\ExportAnnotationTest.xfdf"
+        If Not document.ExportAnnotationToXFDFPath(path, tempPath) Then
+            Return False
+        End If
+        Console.WriteLine("Xfdf file in " & path)
+        Return True
+    End Function
+
+    ' Importing XFDF into the document
+    Private Function ImportAnnotation(document As CPDFDocument) As Boolean
+        Dim path As String = outputPath & "\ImportAnnotationTest.pdf"
+
+        If Not document.ImportAnnotationFromXFDFPath("Annotations.xfdf", tempPath) Then
+            Return False
+        End If
+        If Not document.WriteToFilePath(path) Then
+            Return False
+        End If
+        Console.WriteLine("Browse the changed file in " & path)
+        Return True
+    End Function
 
 End Module

+ 15 - 0
Demo/Examples/Samples/AnnotationImportExportTest/VB/AnnotationImportExportTest.vbproj

@@ -106,6 +106,18 @@
     </EmbeddedResource>
   </ItemGroup>
   <ItemGroup>
+    <None Include="..\..\..\TestFile\Annotations.pdf">
+      <Link>Annotations.pdf</Link>
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="..\..\..\TestFile\Annotations.xfdf">
+      <Link>Annotations.xfdf</Link>
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="..\..\..\TestFile\CommonFivePage.pdf">
+      <Link>CommonFivePage.pdf</Link>
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
     <None Include="My Project\Application.myapp">
       <Generator>MyApplicationCodeGenerator</Generator>
       <LastGenOutput>Application.Designer.vb</LastGenOutput>
@@ -124,6 +136,9 @@
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
   </ItemGroup>
+  <ItemGroup>
+    <Content Include="ComPDFKit_Logo.ico" />
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
   <Import Project="..\..\..\packages\ComPDFKit.NetFramework.1.10.0\build\ComPDFKit.NetFramework.targets" Condition="Exists('..\..\..\packages\ComPDFKit.NetFramework.1.10.0\build\ComPDFKit.NetFramework.targets')" />
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

BIN
Demo/Examples/Samples/AnnotationImportExportTest/VB/ComPDFKit_Logo.ico