Revision: 6748
http://skim-app.svn.sourceforge.net/skim-app/?rev=6748&view=rev
Author: hofman
Date: 2010-08-29 22:16:27 +0000 (Sun, 29 Aug 2010)
Log Message:
-----------
Add skimconvert command line tool target. CLT to manipulate PDF files with
attached notes: embed or unembed Skim notes, merge PDFs, or extract pages with
notes.
Modified Paths:
--------------
trunk/SkimNotes/SkimNotes.rtf
trunk/SkimNotes/SkimNotes.xcodeproj/project.pbxproj
Added Paths:
-----------
trunk/SkimNotes/Configurations/SkimConvert-Tool.xcconfig
trunk/SkimNotes/SkimConvert_Tool_Prefix.pch
trunk/SkimNotes/skimconvert.m
Added: trunk/SkimNotes/Configurations/SkimConvert-Tool.xcconfig
===================================================================
--- trunk/SkimNotes/Configurations/SkimConvert-Tool.xcconfig
(rev 0)
+++ trunk/SkimNotes/Configurations/SkimConvert-Tool.xcconfig 2010-08-29
22:16:27 UTC (rev 6748)
@@ -0,0 +1,10 @@
+// Tool only
+
+INSTALL_PATH = /usr/local/bin
+PRODUCT_NAME = skimconvert
+
+GCC_PRECOMPILE_PREFIX_HEADER = YES
+GCC_PREFIX_HEADER = SkimConvert_Tool_Prefix.pch
+
+// the code for the tool is not GC safe, this should not be relevant anyway
+GCC_ENABLE_OBJC_GC = unsupported
Added: trunk/SkimNotes/SkimConvert_Tool_Prefix.pch
===================================================================
--- trunk/SkimNotes/SkimConvert_Tool_Prefix.pch (rev 0)
+++ trunk/SkimNotes/SkimConvert_Tool_Prefix.pch 2010-08-29 22:16:27 UTC (rev
6748)
@@ -0,0 +1,15 @@
+//
+// Prefix header for all source files of the 'skimconvert' target in the
'SkimNotes' project.
+//
+
+#ifdef __OBJC__
+ #import <Foundation/Foundation.h>
+ #import <AppKit/AppKit.h>
+ #import <Quartz/Quartz.h>
+
+ #if !defined(MAC_OS_X_VERSION_10_5) || MAC_OS_X_VERSION_MAX_ALLOWED <
MAC_OS_X_VERSION_10_5
+ #import "SKNCompatibility.h"
+ #endif
+
+ #define SKNLocalizedString(key, comment) key
+#endif
Modified: trunk/SkimNotes/SkimNotes.rtf
===================================================================
--- trunk/SkimNotes/SkimNotes.rtf 2010-08-27 22:27:19 UTC (rev 6747)
+++ trunk/SkimNotes/SkimNotes.rtf 2010-08-29 22:16:27 UTC (rev 6748)
@@ -1,4 +1,4 @@
-{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf110
+{\rtf1\ansi\ansicpg65001\cocoartf1038\cocoasubrtf320
{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fmodern\fcharset0
Courier;\f2\fnil\fcharset0 Menlo-Regular;
}
{\colortbl;\red255\green255\blue255;\red170\green13\blue145;\red92\green38\blue153;\red28\green0\blue207;
@@ -105,6 +105,18 @@
\
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural
+\b\fs36 \cf0 Skimconvert Command Line Tool
+\fs24 \
+\
+\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural
+
+\b0 \cf0 The skimconvert tool provides a command line utility to manipulate
PDF files and associated Skim notes, such as embedding or unembedding Skim
notes in the PDF, or to merge and extract pages from PDF files with attached
Skim notes. Use
+\f1 skimconvert help
+\f0 to get more help on using the tool.\
+\
+\
+\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural
+
\b\fs36 \cf0 Notes on Building the Framework
\fs24 \
\
Modified: trunk/SkimNotes/SkimNotes.xcodeproj/project.pbxproj
===================================================================
--- trunk/SkimNotes/SkimNotes.xcodeproj/project.pbxproj 2010-08-27 22:27:19 UTC
(rev 6747)
+++ trunk/SkimNotes/SkimNotes.xcodeproj/project.pbxproj 2010-08-29 22:16:27 UTC
(rev 6748)
@@ -28,6 +28,7 @@
CEBA2EA60E0673D40000B2E6 /* PBXTargetDependency
*/,
CEEE7B620E7BD90F00B7B208 /* PBXTargetDependency
*/,
CEBA2EAC0E067F420000B2E6 /* PBXTargetDependency
*/,
+ CE1414351229B8F800C9EBA0 /* PBXTargetDependency
*/,
CEA5F6090E2D270500F65088 /* PBXTargetDependency
*/,
);
name = Archive;
@@ -37,6 +38,17 @@
/* Begin PBXBuildFile section */
8DC2EF570486A6940098B216 /* Cocoa.framework in Frameworks */ =
{isa = PBXBuildFile; fileRef = 1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */;
};
+ CE1412881229B73100C9EBA0 /* AppKit.framework in Frameworks */ =
{isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */;
};
+ CE1412891229B73100C9EBA0 /* Foundation.framework in Frameworks
*/ = {isa = PBXBuildFile; fileRef = 0867D69BFE84028FC02AAC07 /*
Foundation.framework */; };
+ CE1413C11229B74800C9EBA0 /* Quartz.framework in Frameworks */ =
{isa = PBXBuildFile; fileRef = CE1F649B0E34FAC300E07E76 /* Quartz.framework */;
};
+ CE1414151229B74F00C9EBA0 /* libbz2.dylib in Frameworks */ =
{isa = PBXBuildFile; fileRef = CEBA2D1A0E05A61F0000B2E6 /* libbz2.dylib */; };
+ CE1414231229B80300C9EBA0 /* skimconvert.m in Sources */ = {isa
= PBXBuildFile; fileRef = CE1414221229B80300C9EBA0 /* skimconvert.m */; };
+ CE1414261229B8AD00C9EBA0 /* SKNExtendedAttributeManager.m in
Sources */ = {isa = PBXBuildFile; fileRef = CEBA2B640E05675E0000B2E6 /*
SKNExtendedAttributeManager.m */; };
+ CE1414271229B8AE00C9EBA0 /* SKNUtilities.m in Sources */ = {isa
= PBXBuildFile; fileRef = CE37768B0E2FC26100261604 /* SKNUtilities.m */; };
+ CE1414281229B8B200C9EBA0 /* NSFileManager_SKNExtensions.m in
Sources */ = {isa = PBXBuildFile; fileRef = CEBA2BD40E05826D0000B2E6 /*
NSFileManager_SKNExtensions.m */; };
+ CE1414291229B8B300C9EBA0 /* PDFAnnotation_SKNExtensions.m in
Sources */ = {isa = PBXBuildFile; fileRef = CEBA2B700E0568430000B2E6 /*
PDFAnnotation_SKNExtensions.m */; };
+ CE14142A1229B8B400C9EBA0 /* PDFDocument_SKNExtensions.m in
Sources */ = {isa = PBXBuildFile; fileRef = CEBA2BE10E0587EB0000B2E6 /*
PDFDocument_SKNExtensions.m */; };
+ CE14142B1229B8B500C9EBA0 /* SKNPDFAnnotationNote.m in Sources
*/ = {isa = PBXBuildFile; fileRef = CEBA2B8C0E0569010000B2E6 /*
SKNPDFAnnotationNote.m */; };
CE1F649C0E34FAC300E07E76 /* Quartz.framework in Frameworks */ =
{isa = PBXBuildFile; fileRef = CE1F649B0E34FAC300E07E76 /* Quartz.framework */;
};
CE1F64E20E34FF7F00E07E76 /* Foundation.framework in Frameworks
*/ = {isa = PBXBuildFile; fileRef = 0867D69BFE84028FC02AAC07 /*
Foundation.framework */; };
CE1F64E30E34FF8000E07E76 /* AppKit.framework in Frameworks */ =
{isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */;
};
@@ -83,6 +95,13 @@
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
+ CE1414341229B8F800C9EBA0 /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 0867D690FE84028FC02AAC07 /* Project
object */;
+ proxyType = 1;
+ remoteGlobalIDString = CE14113E1229B64D00C9EBA0;
+ remoteInfo = "SkimConvert Tool";
+ };
CEA5F6080E2D270500F65088 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 0867D690FE84028FC02AAC07 /* Project
object */;
@@ -147,6 +166,10 @@
32DBCF5E0370ADEE00C91783 /* SkimNotes_Prefix.pch */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
SkimNotes_Prefix.pch; sourceTree = "<group>"; };
8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path =
Info.plist; sourceTree = "<group>"; };
8DC2EF5B0486A6940098B216 /* SkimNotes.framework */ = {isa =
PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0;
path = SkimNotes.framework; sourceTree = BUILT_PRODUCTS_DIR; };
+ CE14113F1229B64D00C9EBA0 /* skimconvert */ = {isa =
PBXFileReference; explicitFileType = "compiled.mach-o.executable";
includeInIndex = 0; path = skimconvert; sourceTree = BUILT_PRODUCTS_DIR; };
+ CE1414161229B7A000C9EBA0 /* SkimConvert-Tool.xcconfig */ = {isa
= PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path =
"SkimConvert-Tool.xcconfig"; sourceTree = "<group>"; };
+ CE1414221229B80300C9EBA0 /* skimconvert.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= skimconvert.m; sourceTree = "<group>"; };
+ CE1414251229B86500C9EBA0 /* SkimConvert_Tool_Prefix.pch */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h;
path = SkimConvert_Tool_Prefix.pch; sourceTree = "<group>"; };
CE17EF840E250E8A00DE06EA /* SkimNotes-Debug.xcconfig */ = {isa
= PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path =
"SkimNotes-Debug.xcconfig"; sourceTree = "<group>"; };
CE17EF850E250E8A00DE06EA /* SkimNotes-Framework.xcconfig */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig;
path = "SkimNotes-Framework.xcconfig"; sourceTree = "<group>"; };
CE17EF880E250E8A00DE06EA /* SkimNotes-Release.xcconfig */ =
{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig;
path = "SkimNotes-Release.xcconfig"; sourceTree = "<group>"; };
@@ -217,6 +240,17 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
+ CE14113D1229B64D00C9EBA0 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ CE1412891229B73100C9EBA0 /*
Foundation.framework in Frameworks */,
+ CE1412881229B73100C9EBA0 /* AppKit.framework in
Frameworks */,
+ CE1413C11229B74800C9EBA0 /* Quartz.framework in
Frameworks */,
+ CE1414151229B74F00C9EBA0 /* libbz2.dylib in
Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
CEA5F53B0E2CED0E00F65088 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
@@ -255,6 +289,7 @@
CEA5F53D0E2CED0E00F65088 /*
SkimNotesBase.framework */,
CEBA2B550E0566B00000B2E6 /* skimnotes */,
CEDB9AE90E2E9F090057FD09 /* SkimNotesTest.app
*/,
+ CE14113F1229B64D00C9EBA0 /* skimconvert */,
);
name = Products;
sourceTree = "<group>";
@@ -340,6 +375,7 @@
32DBCF5E0370ADEE00C91783 /*
SkimNotes_Prefix.pch */,
CEA5F54C0E2CEDC400F65088 /*
SkimNotesBase_Prefix.pch */,
CE17F1BB0E25861700DE06EA /*
SkimNotes_Tool_Prefix.pch */,
+ CE1414251229B86500C9EBA0 /*
SkimConvert_Tool_Prefix.pch */,
CEA5F5870E2CF63000F65088 /* SKNCompatibility.h
*/,
CEA5F5E40E2D0FDB00F65088 /* SkimNotes.hdoc */,
);
@@ -355,6 +391,7 @@
CEBA2B5A0E0566DF0000B2E6 /* SKNAgentListener.h
*/,
CEBA2B5B0E0566DF0000B2E6 /* SKNAgentListener.m
*/,
CEBA2B5C0E0566DF0000B2E6 /*
SKNAgentListenerProtocol.h */,
+ CE1414221229B80300C9EBA0 /* skimconvert.m */,
);
name = "Tool Classes";
sourceTree = "<group>";
@@ -378,6 +415,7 @@
CE17EF880E250E8A00DE06EA /*
SkimNotes-Release.xcconfig */,
CE17EF850E250E8A00DE06EA /*
SkimNotes-Framework.xcconfig */,
CE17EF890E250E8A00DE06EA /*
SkimNotes-Tool.xcconfig */,
+ CE1414161229B7A000C9EBA0 /*
SkimConvert-Tool.xcconfig */,
CEDB9B0D0E2EA1380057FD09 /*
SkimNotes-App.xcconfig */,
CE5280B60E41C20A000F9CAC /*
SkimNotesBase-Framework.xcconfig */,
);
@@ -456,6 +494,22 @@
productReference = 8DC2EF5B0486A6940098B216 /*
SkimNotes.framework */;
productType = "com.apple.product-type.framework";
};
+ CE14113E1229B64D00C9EBA0 /* SkimConvert Tool */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = CE1411461229B66F00C9EBA0 /*
Build configuration list for PBXNativeTarget "SkimConvert Tool" */;
+ buildPhases = (
+ CE14113C1229B64D00C9EBA0 /* Sources */,
+ CE14113D1229B64D00C9EBA0 /* Frameworks */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = "SkimConvert Tool";
+ productName = "SkimConvert Tool";
+ productReference = CE14113F1229B64D00C9EBA0 /*
skimconvert */;
+ productType = "com.apple.product-type.tool";
+ };
CEA5F53C0E2CED0E00F65088 /* SkimNotesBase */ = {
isa = PBXNativeTarget;
buildConfigurationList = CEA5F5470E2CED1200F65088 /*
Build configuration list for PBXNativeTarget "SkimNotesBase" */;
@@ -539,6 +593,7 @@
8DC2EF4F0486A6940098B216 /* SkimNotes */,
CEA5F53C0E2CED0E00F65088 /* SkimNotesBase */,
CEBA2B540E0566B00000B2E6 /* SkimNotes Tool */,
+ CE14113E1229B64D00C9EBA0 /* SkimConvert Tool */,
CE665A840E1C086D00D0704D /* HeaderDocs */,
CEBA2EA20E0673B60000B2E6 /* Archive */,
CEDB9AE80E2E9F090057FD09 /* SkimNotesTest */,
@@ -607,7 +662,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
- shellScript = "tmpdir=`/usr/bin/mktemp -d
/tmp/net.sourceforge.skim-app.skimnotes.XXXX`\nbasedir=\"SkimNotes\"\nsourcedir=\"${basedir}/Source\"\ncd
\"${tmpdir}\"\n/bin/mkdir \"${basedir}\"\n/bin/mkdir \"${sourcedir}\"\n/bin/cp
-Rf \"${SOURCE_ROOT}\"/* \"${sourcedir}\"\n/bin/cp -Rf
\"${BUILT_PRODUCTS_DIR}\"/{skimnotes,SkimNotes.framework,SkimNotesBase.framework,SkimNotes\\
Documentation} \"${basedir}\"\n/bin/cp -f
\"${SOURCE_ROOT}\"/{License.txt,SkimNotes.rtf,ReleaseNotes.rtf}
\"${basedir}\"\n/usr/bin/find \"${basedir}\" -type f \\( -name \".DS_Store\"
-or -name \"*.pbxuser\" -or -name \"*.mode*\" \\) -delete\n/usr/bin/find
\"${basedir}\" -type d -name \".svn\" -delete\n/usr/bin/tar czf
\"${HOME}/Desktop/SkimNotes.tgz\" \"${basedir}\"\n/bin/rm -rf
\"${tmpdir}\"\nexit 0";
+ shellScript = "tmpdir=`/usr/bin/mktemp -d
/tmp/net.sourceforge.skim-app.skimnotes.XXXX`\nbasedir=\"SkimNotes\"\nsourcedir=\"${basedir}/Source\"\ncd
\"${tmpdir}\"\n/bin/mkdir \"${basedir}\"\n/bin/mkdir \"${sourcedir}\"\n/bin/cp
-Rf \"${SOURCE_ROOT}\"/* \"${sourcedir}\"\n/bin/cp -Rf
\"${BUILT_PRODUCTS_DIR}\"/{skimnotes,skimconvert,SkimNotes.framework,SkimNotesBase.framework,SkimNotes\\
Documentation} \"${basedir}\"\n/bin/cp -f
\"${SOURCE_ROOT}\"/{License.txt,SkimNotes.rtf,ReleaseNotes.rtf}
\"${basedir}\"\n/usr/bin/find \"${basedir}\" -type f \\( -name \".DS_Store\"
-or -name \"*.pbxuser\" -or -name \"*.mode*\" \\) -delete\n/usr/bin/find
\"${basedir}\" -type d -name \".svn\" -delete\n/usr/bin/tar czf
\"${HOME}/Desktop/SkimNotes.tgz\" \"${basedir}\"\n/bin/rm -rf
\"${tmpdir}\"\nexit 0";
};
/* End PBXShellScriptBuildPhase section */
@@ -625,6 +680,20 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
+ CE14113C1229B64D00C9EBA0 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ CE1414231229B80300C9EBA0 /* skimconvert.m in
Sources */,
+ CE1414261229B8AD00C9EBA0 /*
SKNExtendedAttributeManager.m in Sources */,
+ CE1414271229B8AE00C9EBA0 /* SKNUtilities.m in
Sources */,
+ CE1414281229B8B200C9EBA0 /*
NSFileManager_SKNExtensions.m in Sources */,
+ CE1414291229B8B300C9EBA0 /*
PDFAnnotation_SKNExtensions.m in Sources */,
+ CE14142A1229B8B400C9EBA0 /*
PDFDocument_SKNExtensions.m in Sources */,
+ CE14142B1229B8B500C9EBA0 /*
SKNPDFAnnotationNote.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
CEA5F53A0E2CED0E00F65088 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
@@ -660,6 +729,11 @@
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
+ CE1414351229B8F800C9EBA0 /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = CE14113E1229B64D00C9EBA0 /* SkimConvert Tool
*/;
+ targetProxy = CE1414341229B8F800C9EBA0 /*
PBXContainerItemProxy */;
+ };
CEA5F6090E2D270500F65088 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = CE665A840E1C086D00D0704D /* HeaderDocs */;
@@ -756,6 +830,20 @@
};
name = Release;
};
+ CE1411411229B64D00C9EBA0 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ baseConfigurationReference = CE1414161229B7A000C9EBA0
/* SkimConvert-Tool.xcconfig */;
+ buildSettings = {
+ };
+ name = Debug;
+ };
+ CE1411421229B64D00C9EBA0 /* Release */ = {
+ isa = XCBuildConfiguration;
+ baseConfigurationReference = CE1414161229B7A000C9EBA0
/* SkimConvert-Tool.xcconfig */;
+ buildSettings = {
+ };
+ name = Release;
+ };
CE665A860E1C086F00D0704D /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
@@ -847,6 +935,15 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
+ CE1411461229B66F00C9EBA0 /* Build configuration list for
PBXNativeTarget "SkimConvert Tool" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ CE1411411229B64D00C9EBA0 /* Debug */,
+ CE1411421229B64D00C9EBA0 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
CE665A880E1C089700D0704D /* Build configuration list for
PBXAggregateTarget "HeaderDocs" */ = {
isa = XCConfigurationList;
buildConfigurations = (
Added: trunk/SkimNotes/skimconvert.m
===================================================================
--- trunk/SkimNotes/skimconvert.m (rev 0)
+++ trunk/SkimNotes/skimconvert.m 2010-08-29 22:16:27 UTC (rev 6748)
@@ -0,0 +1,412 @@
+//
+// skimconvert.m
+// SkimNotes
+//
+// Created by Christiaan Hofman on 08/28/10.
+/*
+ This software is Copyright (c) 2010
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Foundation/Foundation.h>
+#import <Quartz/Quartz.h>
+#import "NSFileManager_SKNExtensions.h"
+#import "PDFDocument_SKNExtensions.h"
+#import "PDFAnnotation_SKNExtensions.h"
+#import "SKNPDFAnnotationNote.h"
+
+static char *usageStr = "Usage:\n skimconvert embed IN_PDF_FILE
[OUT_PDF_FILE]\n skimconvert unembed IN_PDF_FILE [OUT_PDF_FILE]\n skimconvert
merge IN_PDF_FILE_1 IN_PDF_FILE_2 [OUT_PDF_FILE]\n skimconvert extract
IN_PDF_FILE [OUT_PDF_FILE] [-range START LENGTH | -page PAGE1...]\n skimnotes
help [VERB]\n skimnotes version";
+static char *versionStr = "SkimConvert command-line client, version 1.0";
+
+static char *embedHelpStr = "skimconvert embed: embed Skim notes in a
PDF\nUsage: skimconvert embed IN_PDF_FILE [OUT_PDF_FILE]\n\nWrites PDF with
Skim notes from IN_PDF_FILE to PDF with annotations embedded in the PDF to
OUT_PDF_FILE.\nWrites to IN_PDF_FILE when OUT_PDF_FILE is not provided.";
+static char *unembedHelpStr = "skimconvert unembed: converts annotations
embedded in a PDF to Skim notes\nUsage: skimconvert unembed IN_PDF_FILE
[OUT_PDF_FILE]\n\nConverts annotations embedded in IN_PDF_FILE to Skim notes
and writes the PDF data with notes removed to OUT_PDF_FILE with the Skim notes
written to the extended attributes.\nWrites to IN_PDF_FILE when OUT_PDF_FILE is
not provided.";
+static char *mergeHelpStr = "skimconvert merge: Merges two PDF files with
attached Skim notes\nUsage: skimconvert merge IN_PDF_FILE_1 IN_PDF_FILE_2
[OUT_PDF_FILE]\n\nMerges IN_PDF_FILE_1 and IN_PDF_FILE_2 and Skim notes from
their extended attributes and writes to OUT_PDF_FILE.\nWrites to IN_PDF_FILE_1
when OUT_PDF_FILE is not provided.";
+static char *extractHelpStr = "skimconvert extract: Extracts part of a PDF
with attached Skim notes\nUsage: skimconvert extract IN_PDF_FILE [OUT_PDF_FILE]
[-range START LENGTH | -page PAGE1...]\n\nExtracts pages from IN_PDF_FILE and
attached Skim notes in the pages, given either as a page range or a series of
pages, and writes them to OUT_PDF_FILE.\nWrites to IN_PDF_FILE when
OUT_PDF_FILE is not provided.";
+static char *helpHelpStr = "skimconvert help: get help on the skimconvert
tool\nUsage: skimconvert help [VERB]\n\nGet help on the verb VERB.";
+static char *versionHelpStr = "skimconvert version: get version of the
skimconvert tool\nUsage: skimconvert version\n\nGet the version of the tool and
exit.";
+
+#define ACTION_EMBED_STRING @"embed"
+#define ACTION_UNEMBED_STRING @"unembed"
+#define ACTION_MERGE_STRING @"merge"
+#define ACTION_EXTRACT_STRING @"extract"
+#define ACTION_VERSION_STRING @"version"
+#define ACTION_HELP_STRING @"help"
+
+#define RANGE_OPTION_STRING @"-range"
+#define PAGE_OPTION_STRING @"-page"
+
+#define WRITE_OUT(msg) fprintf(stdout, "%s\n", msg)
+#define WRITE_OUT_VERSION(msg) fprintf(stdout, "%s\n%s\n", msg, versionStr)
+#define WRITE_ERROR fprintf(stderr, "%s\n%s\n", usageStr,
versionStr)
+
+enum {
+ SKNActionUnknown,
+ SKNActionEmbed,
+ SKNActionUnembed,
+ SKNActionMerge,
+ SKNActionExtract,
+ SKNActionVersion,
+ SKNActionHelp
+};
+
+static NSInteger SKNActionForName(NSString *actionString) {
+ if ([actionString caseInsensitiveCompare:ACTION_EMBED_STRING] ==
NSOrderedSame)
+ return SKNActionEmbed;
+ else if ([actionString caseInsensitiveCompare:ACTION_UNEMBED_STRING] ==
NSOrderedSame)
+ return SKNActionUnembed;
+ else if ([actionString caseInsensitiveCompare:ACTION_MERGE_STRING] ==
NSOrderedSame)
+ return SKNActionMerge;
+ else if ([actionString caseInsensitiveCompare:ACTION_EXTRACT_STRING] ==
NSOrderedSame)
+ return SKNActionExtract;
+ else if ([actionString caseInsensitiveCompare:ACTION_VERSION_STRING] ==
NSOrderedSame)
+ return SKNActionVersion;
+ else if ([actionString caseInsensitiveCompare:ACTION_HELP_STRING] ==
NSOrderedSame)
+ return SKNActionHelp;
+ else
+ return SKNActionUnknown;
+}
+
+static inline NSString *SKNNormalizedPath(NSString *path) {
+ if ([path isAbsolutePath] == NO) {
+ NSString *basePath = [[NSFileManager defaultManager]
currentDirectoryPath];
+ if (basePath)
+ path = [basePath stringByAppendingPathComponent:path];
+ }
+ path = [path stringByStandardizingPath];
+ return path;
+}
+
+int main (int argc, const char * argv[]) {
+ NSAutoreleasePool *pool = [NSAutoreleasePool new];
+
+ NSArray *args = [[NSProcessInfo processInfo] arguments];
+
+ if (argc < 2) {
+ WRITE_ERROR;
+ [pool release];
+ exit(EXIT_FAILURE);
+ }
+
+ NSInteger action = SKNActionForName([args objectAtIndex:1]);
+
+ BOOL success = NO;
+
+ if (action == SKNActionUnknown) {
+
+ WRITE_ERROR;
+ [pool release];
+ exit(EXIT_FAILURE);
+
+ } else if (action == SKNActionHelp) {
+
+ NSInteger helpAction = SKNActionForName([args count] > 2 ? [args
objectAtIndex:2] : @"");
+
+ switch (helpAction) {
+ case SKNActionUnknown:
+ WRITE_OUT_VERSION(usageStr);
+ break;
+ case SKNActionEmbed:
+ WRITE_OUT(embedHelpStr);
+ break;
+ case SKNActionUnembed:
+ WRITE_OUT(unembedHelpStr);
+ break;
+ case SKNActionMerge:
+ WRITE_OUT(mergeHelpStr);
+ break;
+ case SKNActionExtract:
+ WRITE_OUT(extractHelpStr);
+ break;
+ case SKNActionVersion:
+ WRITE_OUT(versionHelpStr);
+ break;
+ case SKNActionHelp:
+ WRITE_OUT(helpHelpStr);
+ break;
+ }
+ success = YES;
+
+ } else if (action == SKNActionVersion) {
+
+ WRITE_OUT(versionStr);
+
+ } else {
+
+ int offset = (action == SKNActionMerge ? 1 : 0);
+
+ if (argc < 3 + offset) {
+ WRITE_ERROR;
+ [pool release];
+ exit(EXIT_FAILURE);
+ }
+
+ NSString *inPath = SKNNormalizedPath([args objectAtIndex:2]);
+ NSString *inPath2 = action == SKNActionMerge ? SKNNormalizedPath([args
objectAtIndex:3]) : nil;
+ NSString *outPath = argc < offset + 4 ? inPath :
SKNNormalizedPath([args objectAtIndex:offset + 3]);
+ NSURL *inURL = [NSURL fileURLWithPath:inPath];
+ NSURL *inURL2 = inPath2 ? [NSURL fileURLWithPath:inPath2] : nil;
+ NSURL *outURL = [NSURL fileURLWithPath:outPath];
+ NSFileManager *fm = [NSFileManager defaultManager];
+ NSError *error = nil;
+
+ if ([fm fileExistsAtPath:inPath] == NO || (inPath2 && [fm
fileExistsAtPath:inPath2] == NO)) {
+
+ error = [NSError errorWithDomain:NSPOSIXErrorDomain code:ENOENT
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"PDF file does not exist",
NSLocalizedDescriptionKey, nil]];
+
+ } else if (action == SKNActionEmbed) {
+
+ PDFDocument *pdfDoc = [[[PDFDocument alloc] initWithURL:inURL
readSkimNotes:NULL] autorelease];
+
+ if (pdfDoc == nil || [pdfDoc isLocked]) {
+
+ error = [NSError errorWithDomain:NSPOSIXErrorDomain
code:ENOENT userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Cannot create
PDF document", NSLocalizedDescriptionKey, nil]];
+
+ } else {
+
+ BOOL didExist = [fm fileExistsAtPath:outPath];
+
+ success = [pdfDoc writeToURL:outURL];
+
+ if (success == NO) {
+ error = [NSError errorWithDomain:NSPOSIXErrorDomain
code:ENOENT userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Cannot write
PDF document", NSLocalizedDescriptionKey, nil]];
+ } else if (didExist) {
+ [fm writeSkimNotes:nil toExtendedAttributesAtURL:outURL
error:NULL];
+ }
+
+ }
+
+ } else if (action == SKNActionUnembed) {
+
+ PDFDocument *pdfDoc = [[[PDFDocument alloc] initWithURL:inURL]
autorelease];
+
+ if (pdfDoc == nil || [pdfDoc isLocked]) {
+
+ error = [NSError errorWithDomain:NSPOSIXErrorDomain
code:ENOENT userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Cannot create
PDF document", NSLocalizedDescriptionKey, nil]];
+
+ } else {
+
+ NSArray *inNotes = [fm
readSkimNotesFromExtendedAttributesAtURL:inURL error:NULL];
+ NSMutableArray *notes = [[NSMutableArray alloc]
initWithArray:inNotes];
+ NSUInteger i, iMax = [pdfDoc pageCount];
+ NSSet *convertibleTypes = [NSSet
setWithObjects:SKNFreeTextString, SKNTextString, SKNNoteString,
SKNCircleString, SKNSquareString, SKNMarkUpString, SKNHighlightString,
SKNUnderlineString, SKNStrikeOutString, SKNLineString, SKNInkString, nil];
+
+ for (i = 0; i < iMax; i++) {
+ PDFPage *page = [pdfDoc pageAtIndex:i];
+ NSEnumerator *e = [[[[page annotations] copy] autorelease]
objectEnumerator];
+ PDFAnnotation *annotation;
+
+ while (annotation = [e nextObject]) {
+ if ([convertibleTypes containsObject:[annotation
type]]) {
+ NSDictionary *note = [annotation
SkimNoteProperties];
+ if ([[annotation type]
isEqualToString:SKNTextString]) {
+ NSMutableDictionary *mutableNote = [[note
mutableCopy] autorelease];
+ NSRect bounds = NSRectFromString([note
objectForKey:SKNPDFAnnotationBoundsKey]);
+ NSString *contents = [note
objectForKey:SKNPDFAnnotationContentsKey];
+ [mutableNote setObject:SKNNoteString
forKey:SKNPDFAnnotationTypeKey];
+ bounds.origin.y = NSMaxY(bounds) -
SKNPDFAnnotationNoteSize.height;
+ bounds.size = SKNPDFAnnotationNoteSize;
+ [mutableNote
setObject:NSStringFromRect(bounds) forKey:SKNPDFAnnotationBoundsKey];
+ if (contents) {
+ NSRange r = [contents rangeOfString:@" "];
+ if (NSMaxRange(r) < [contents length]) {
+ NSAttributedString *attrString =
[[[NSAttributedString alloc] initWithString:[contents
substringFromIndex:NSMaxRange(r)]] autorelease];
+ [mutableNote setObject:attrString
forKey:SKNPDFAnnotationTextKey];
+ [mutableNote setObject:[contents
substringToIndex:r.location] forKey:SKNPDFAnnotationContentsKey];
+ }
+ }
+ note = mutableNote;
+ }
+ [notes addObject:note];
+ [page removeAnnotation:annotation];
+ }
+ }
+ }
+
+ if ([notes count] > [inNotes count]) {
+
+ success = [pdfDoc writeToURL:outURL];
+
+ if (success == NO) {
+ error = [NSError errorWithDomain:NSPOSIXErrorDomain
code:ENOENT userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Cannot write
PDF document", NSLocalizedDescriptionKey, nil]];
+ } else {
+ success = [fm writeSkimNotes:notes
toExtendedAttributesAtURL:outURL error:&error];
+ }
+
+ } else if ([outPath caseInsensitiveCompare:inPath] !=
NSOrderedSame) {
+
+#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
+ success = [fm copyItemAtPath:inPath toPath:outPath
error:NULL];
+#else
+ success = [fm copyPath:inPath toPath:outPath handler:nil];
+#endif
+ if (success == NO) {
+ error = [NSError errorWithDomain:NSPOSIXErrorDomain
code:ENOENT userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Cannot write
PDF document", NSLocalizedDescriptionKey, nil]];
+ } else {
+ NSString *textNotes = [fm
readSkimTextNotesFromExtendedAttributesAtURL:inURL error:NULL];
+ NSData *rtfNotesData = [fm
readSkimRTFNotesFromExtendedAttributesAtURL:inURL error:NULL];
+ success = [fm writeSkimNotes:notes textNotes:textNotes
richTextNotes:rtfNotesData toExtendedAttributesAtURL:outURL error:&error];
+ }
+
+ }
+
+ }
+
+ } else if (action == SKNActionMerge) {
+
+ PDFDocument *pdfDoc1 = [[[PDFDocument alloc] initWithURL:inURL]
autorelease];
+ PDFDocument *pdfDoc2 = [[[PDFDocument alloc] initWithURL:inURL2]
autorelease];
+
+ if (pdfDoc1 == nil || pdfDoc2 == nil || [pdfDoc1 isLocked] ||
[pdfDoc2 isLocked]) {
+
+ error = [NSError errorWithDomain:NSPOSIXErrorDomain
code:ENOENT userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Cannot create
PDF document", NSLocalizedDescriptionKey, nil]];
+
+ } else {
+
+ NSUInteger i, count1 = [pdfDoc1 pageCount], count2 = [pdfDoc2
pageCount];
+ for (i = 0; i < count2; i++)
+ [pdfDoc1 insertPage:[pdfDoc2 pageAtIndex:i] atIndex:i +
count1];
+
+ NSArray *notes1 = [fm
readSkimNotesFromExtendedAttributesAtURL:inURL error:NULL];
+ NSArray *notes2 = [fm
readSkimNotesFromExtendedAttributesAtURL:inURL2 error:NULL];
+ NSMutableArray *notes = [NSMutableArray arrayWithArray:notes1];
+ NSEnumerator *e = [notes2 objectEnumerator];
+ NSDictionary *note;
+
+ while (note = [e nextObject]) {
+ NSMutableDictionary *mutableNote = [note mutableCopy];
+ NSUInteger pageIndex = [[note
objectForKey:SKNPDFAnnotationPageIndexKey] unsignedIntValue] + count1;
+ [mutableNote setObject:[NSNumber
numberWithUnsignedInt:pageIndex] forKey:SKNPDFAnnotationPageIndexKey];
+ [notes addObject:mutableNote];
+ [mutableNote release];
+ }
+
+ success = [pdfDoc1 writeToURL:outURL];
+
+ if (success == NO) {
+ error = [NSError errorWithDomain:NSPOSIXErrorDomain
code:ENOENT userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Cannot write
PDF document", NSLocalizedDescriptionKey, nil]];
+ } else {
+ success = [fm writeSkimNotes:notes
toExtendedAttributesAtURL:outURL error:&error];
+ }
+
+ }
+
+ } else if (action == SKNActionExtract) {
+
+ if ([outPath caseInsensitiveCompare:RANGE_OPTION_STRING] ==
NSOrderedSame || [outPath caseInsensitiveCompare:PAGE_OPTION_STRING] ==
NSOrderedSame) {
+ offset = 0;
+ outPath = inPath;
+ outURL = inURL;
+ } else {
+ offset = 1;
+ }
+
+ if (argc < 5 + offset) {
+ WRITE_ERROR;
+ [pool release];
+ exit(EXIT_FAILURE);
+ }
+
+ PDFDocument *pdfDoc = [[[PDFDocument alloc] initWithURL:inURL]
autorelease];
+
+ NSString *option = [args objectAtIndex:offset + 3];
+ NSMutableIndexSet *indexes = [NSMutableIndexSet indexSet];
+
+ if ([option caseInsensitiveCompare:RANGE_OPTION_STRING] ==
NSOrderedSame) {
+ NSInteger start = [[args objectAtIndex:offset + 4] intValue];
+ NSInteger length = argc < 6 + offset ? (NSInteger)[pdfDoc
pageCount] - start + 1 : [[args objectAtIndex:offset + 5] intValue];
+ if (start > 0 && length > 0)
+ [indexes addIndexesInRange:NSMakeRange(start - 1, length)];
+ } else if ([option caseInsensitiveCompare:PAGE_OPTION_STRING] ==
NSOrderedSame) {
+ NSInteger i;
+ for (i = offset + 4; i < argc; i++) {
+ NSUInteger page = [[args objectAtIndex:i] intValue];
+ if (page > 0)
+ [indexes addIndex:page - 1];
+ }
+ }
+
+ if (pdfDoc == nil || [pdfDoc isLocked]) {
+
+ error = [NSError errorWithDomain:NSPOSIXErrorDomain
code:ENOENT userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Cannot create
PDF document", NSLocalizedDescriptionKey, nil]];
+
+ } else if ([indexes count] == 0 || [indexes lastIndex] > [pdfDoc
pageCount]) {
+
+ error = [NSError errorWithDomain:NSPOSIXErrorDomain
code:ENOENT userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Invalid page
range", NSLocalizedDescriptionKey, nil]];
+
+ } else {
+
+ NSUInteger i = [pdfDoc pageCount];
+ while (i-- > 0) {
+ if ([indexes containsIndex:i] == NO)
+ [pdfDoc removePageAtIndex:i];
+ }
+
+ NSArray *inNotes = [fm
readSkimNotesFromExtendedAttributesAtURL:inURL error:NULL];
+ NSMutableArray *notes = [NSMutableArray array];
+ NSEnumerator *e = [inNotes objectEnumerator];
+ NSDictionary *note;
+
+ while (note = [e nextObject]) {
+ NSUInteger pageIndex = [[note
objectForKey:SKNPDFAnnotationPageIndexKey] unsignedIntValue];
+ if ([indexes containsIndex:pageIndex]) {
+ NSUInteger newPageIndex = [indexes
countOfIndexesInRange:NSMakeRange(0, pageIndex)];
+ if (newPageIndex != pageIndex) {
+ NSMutableDictionary *mutableNote = [note
mutableCopy];
+ [mutableNote setObject:[NSNumber
numberWithUnsignedInt:newPageIndex] forKey:SKNPDFAnnotationPageIndexKey];
+ [notes addObject:mutableNote];
+ [mutableNote release];
+ } else {
+ [notes addObject:note];
+ }
+ }
+ }
+
+ success = [pdfDoc writeToURL:outURL];
+
+ if (success == NO) {
+ error = [NSError errorWithDomain:NSPOSIXErrorDomain
code:ENOENT userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Cannot write
PDF document", NSLocalizedDescriptionKey, nil]];
+ } else {
+ success = [fm writeSkimNotes:notes
toExtendedAttributesAtURL:outURL error:&error];
+ }
+
+ }
+
+ }
+
+ if (success == NO && error)
+ [(NSFileHandle *)[NSFileHandle fileHandleWithStandardError]
writeData:[[[error localizedDescription] stringByAppendingString:@"\n"]
dataUsingEncoding:NSUTF8StringEncoding]];
+
+ }
+
+ [pool release];
+
+ return success ? EXIT_SUCCESS : EXIT_FAILURE;
+}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit