<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
- <list default="true" id="f146bc67-2578-4de3-9db2-94d2d43e9e83" name="Default" comment="wip #643" />
+ <list default="true" id="f146bc67-2578-4de3-9db2-94d2d43e9e83" name="Default" comment="wip #643">
+ <change beforePath="$PROJECT_DIR$/../../../src/PDFTools.php" beforeDir="false" afterPath="$PROJECT_DIR$/../../../src/PDFTools.php" afterDir="false" />
+ </list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
- "Application.filter texts.executor": "Run",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"WebServerToolWindowFactoryState": "true",
"git-widget-placeholder": "master",
"ignore.virus.scanning.warn.message": "true",
"kotlin-language-version-configured": "true",
- "last_opened_file_path": "D:/Works/cubist_pdf/resources/tools/fwstk/lib/pdfbox-2.0.30.jar",
+ "last_opened_file_path": "D:/Works/cubist_pdf/resources/tools/fwstk",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
- "project.structure.last.edited": "Modules",
+ "project.structure.last.edited": "SDKs",
"project.structure.proportion": "0.15",
"project.structure.side.proportion": "0.2",
"ruby.rails.projectView.checked": "true",
<recent name="H:\Works\cubeExtranet\fluidbook\tools\fwstk\out\artifacts\fwstk_jar" />
</key>
<key name="MoveFile.RECENT_KEYS">
- <recent name="D:\Works\cubist_pdf\resources\tools\fwstk\lib" />
<recent name="H:\Works\cubeExtranet\fluidbook\tools\fwstk\out\artifacts\fwstk_jar" />
<recent name="H:\Works\cubeExtranet\fluidbook\tools\fwstk" />
</key>
</component>
- <component name="RunManager" selected="Application.filter texts">
+ <component name="RunManager" selected="Application.extract layout">
<configuration default="true" type="AndroidRunConfigurationType" factoryName="Android App">
<option name="DEPLOY" value="true" />
<option name="DEPLOY_APK_FROM_BUNDLE" value="false" />
<option name="Make" enabled="true" />
</method>
</configuration>
- <configuration name="filter texts" type="Application" factoryName="Application">
- <option name="MAIN_CLASS_NAME" value="com.fluidbook.fwstk.Main" />
- <module name="fwstk" />
- <option name="PROGRAM_PARAMETERS" value="--input C:\Users\vince\Desktop\p1.pdf --filterTexts --output C:\Users\vince\Desktop\p1-filter.pdf" />
- <method v="2">
- <option name="Make" enabled="true" />
- </method>
- </configuration>
<configuration default="true" type="JUnit" factoryName="JUnit">
<option name="TEST_OBJECT" value="class" />
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
<item itemvalue="Application.extract links" />
<item itemvalue="Application.extract texts" />
<item itemvalue="Application.extract layout" />
- <item itemvalue="Application.filter texts" />
</list>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<workItem from="1697543960076" duration="2149000" />
<workItem from="1698075842281" duration="1718000" />
<workItem from="1703087993201" duration="98000" />
- <workItem from="1710873866183" duration="11834000" />
</task>
<task id="LOCAL-00001" summary="wip #1111 @0.5">
<created>1487172253077</created>
<MESSAGE value="wip #5410" />
<option name="LAST_COMMIT_MESSAGE" value="wip #5410" />
</component>
- <component name="XDebuggerManager">
- <breakpoint-manager>
- <breakpoints>
- <breakpoint enabled="true" type="java-exception">
- <properties class="java.io.FileNotFoundException" package="java.io" />
- <option name="timeStamp" value="1" />
- </breakpoint>
- </breakpoints>
- </breakpoint-manager>
- </component>
<component name="antWorkspaceConfiguration">
<option name="IS_AUTOSCROLL_TO_SOURCE" value="false" />
<option name="FILTER_TARGETS" value="false" />
import com.fluidbook.fwstk.layout.LayoutStripper;
import com.fluidbook.fwstk.layout.Page;
-import java.io.*;
-import java.lang.reflect.InvocationTargetException;
-import java.util.*;
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
import org.apache.commons.text.StringEscapeUtils;
-import org.apache.pdfbox.contentstream.operator.Operator;
-import org.apache.pdfbox.cos.COSBase;
-import org.apache.pdfbox.cos.COSDictionary;
-import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.pdfparser.PDFStreamParser;
-import org.apache.pdfbox.pdfwriter.ContentStreamWriter;
+import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.PDPageNode;
import org.apache.pdfbox.pdmodel.common.PDPageLabelRange;
import org.apache.pdfbox.pdmodel.common.PDPageLabels;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
-import org.apache.pdfbox.pdmodel.interactive.action.PDAction;
-import org.apache.pdfbox.pdmodel.interactive.action.PDActionGoTo;
-import org.apache.pdfbox.pdmodel.interactive.action.PDActionRemoteGoTo;
-import org.apache.pdfbox.pdmodel.interactive.action.PDActionURI;
+import org.apache.pdfbox.pdmodel.interactive.action.type.PDAction;
+import org.apache.pdfbox.pdmodel.interactive.action.type.PDActionGoTo;
+import org.apache.pdfbox.pdmodel.interactive.action.type.PDActionRemoteGoTo;
+import org.apache.pdfbox.pdmodel.interactive.action.type.PDActionURI;
import org.apache.pdfbox.pdmodel.interactive.annotation.*;
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination;
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination;
import cube.files.FileIO;
import cube.util.Array;
+import java.io.File;
+import java.util.Iterator;
+
import org.apache.pdfbox.pdmodel.*;
import org.apache.pdfbox.pdmodel.common.*;
import org.apache.pdfbox.pdmodel.interactive.action.PDAnnotationAdditionalActions;
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDNamedDestination;
-
+import org.apache.pdfbox.util.PDFImageWriter;
public class Main {
static Float linkOffsetX = 0.0f;
static Float linkOffsetY = 0.0f;
- public static void main(String[] args) throws IOException, ClassNotFoundException, NullPointerException, InterruptedException, InvocationTargetException, NoSuchMethodException, IllegalAccessException {
+ public static void main(String[] args) throws IOException, COSVisitorException, ClassNotFoundException, NullPointerException, InterruptedException {
if (args.length < 0) {
printUsage();
boolean robust = false;
PDDocument doc = null;
Integer[] pages = null;
- boolean filterTexts = false;
try {
for (int i = 0; i < args.length; i++) {
} else if (args[i].trim().compareTo("--layout") == 0) {
i++;
layoutOutput = args[i].trim();
+ } else if (args[i].trim().compareTo("--image") == 0) {
+ i++;
+ imageOutput = args[i].trim();
} else if (args[i].trim().compareTo("--ignoreSeparators") == 0) {
i++;
ignoredSeparators = args[i].trim().replace("{SPACE}", " ");
} else if (args[i].trim().compareTo("--mode") == 0) {
i++;
robust = args[i].trim().equals("robust");
- } else if (args[i].trim().compareTo("--filterTexts") == 0) {
- filterTexts = true;
}
}
pages = Array.parseRange("1-" + doc.getNumberOfPages());
}
- if (filterTexts) {
- if (doc == null) {
- doc = openDocument(input);
- }
- filterPDFTexts(doc, output);
- return;
- }
-
if (infos) {
if (doc == null) {
doc = openDocument(input);
Main m = new Main();
m.extractLayout(doc, layoutOutput, robust, ignoredSeparators);
}
+ if (imageOutput.compareTo("") != 0) {
+ if (doc == null) {
+ doc = openDocument(input);
+ }
+ Main m = new Main();
+ m.makeImages(doc, imageOutput);
+ }
} finally {
if (doc != null) {
}
- private void extractLayout(PDDocument doc, String layoutOutput, boolean robust, String ignoredSeparators) throws IOException, InvocationTargetException, NoSuchMethodException, IllegalAccessException {
+ private void makeImages(PDDocument doc, String imageOutput) throws IOException {
+ PDFImageWriter writer = new PDFImageWriter();
+
+ for (int i = 0; i < doc.getNumberOfPages(); i++) {
+ PDPage p = (PDPage) doc.getDocumentCatalog().getAllPages().get(i);
+ p.setCropBox(p.findMediaBox());
+ p.setTrimBox(p.findMediaBox());
+ p.setBleedBox(p.findMediaBox());
+ p.setArtBox(p.findMediaBox());
+ }
+
+ writer.writeImage(doc, "png", "", 1, doc.getNumberOfPages(), imageOutput);
+ }
+
+ private void extractLayout(PDDocument doc, String layoutOutput, boolean robust, String ignoredSeparators) throws IOException {
LayoutStripper stripper = null;
- int n = doc.getNumberOfPages();
- for (int i = 0; i < n; i++) {
- PDPage page = doc.getPage(i);
+ List pages = doc.getDocumentCatalog().getAllPages();
+ Iterator<COSObjectable> pagesIter = pages.listIterator();
+
+ int i = 0;
+
+ while (pagesIter.hasNext()) {
stripper = new LayoutStripper();
stripper.setSplitAllChars(robust);
stripper.setIgnoredSeparators(ignoredSeparators);
+ PDPage nextPage = (PDPage) pagesIter.next();
+ i++;
// For each page, one stripper, otherwise, there is bug with chars widths
- stripper.process(page, i);
+ stripper.process(nextPage, i);
Page layout = stripper.getLayout();
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(layoutOutput.replace("%d", "" + i)), "UTF-8"));
out.write(layout.asJSON());
}
}
- private static Boolean getInfos(PDDocument doc) throws IOException {
+ private static Boolean getInfos(PDDocument doc) throws IOException, COSVisitorException {
ArrayList<String> res = new ArrayList<>();
// General informations
String[] fields = {"Author", "Title", "CreationDate", "Creator", "Keywords", "ModificationDate", "Producer", "Subject", "Trapped", "Version"};
}
// Number of pages
-
- int pages = doc.getNumberOfPages();
+ List<PDPage> list = doc.getDocumentCatalog().getAllPages();
+ int pages = list.size();
res.add("Pages:\t\t\t" + pages);
Boolean changes = false;
- for (int numero = 1; numero <= pages; numero++) {
- PDPage page = doc.getPage(numero);
+ for (int i = 0; i < pages; i++) {
+ PDPage page = list.get(i);
+ int numero = i + 1;
// Get boxes
- PDRectangle mediaBox = page.getMediaBox();
- PDRectangle cropBox = page.getCropBox();
+ PDRectangle mediaBox = page.findMediaBox();
+ PDRectangle cropBox = page.findCropBox();
if (cropBox == null) {
cropBox = mediaBox;
}
// Size
- if ((page.getRotation() == 90 || page.getRotation() == 270)) {
+ if (page.getRotation() != null && (page.getRotation() == 90 || page.getRotation() == 270)) {
res.add("Page " + numero + " size:\t\t" + Math.abs(cropBox.getHeight()) + " pts x " + Math.abs(cropBox.getWidth()) + " pts");
// Boxes
res.add("Page " + numero + " CropBox:\t" + cropBox.getLowerLeftY() + "\t" + cropBox.getUpperRightX() + "\t" + cropBox.getUpperRightY() + "\t" + cropBox.getLowerLeftX() + "\t");
return changes;
}
- private static void filterPDFTexts(PDDocument doc, String output) throws IOException {
- int n = doc.getNumberOfPages();
- for (int i = 0; i < n; i++) {
- PDPage page = doc.getPage(i);
- filterPDFTextsPage(doc, page);
- }
- doc.save(output);
- }
-
- private static void filterPDFTextsPage(PDDocument doc, PDPage page) throws IOException {
- COSDictionary newDictionary = new COSDictionary(page.getCOSObject());
-
- PDFStreamParser parser = new PDFStreamParser(page);
- parser.parse();
- List<Object> tokens = parser.getTokens();
- parser.close();
- ArrayList<Object> newTokens = new ArrayList<Object>();
-
- String[] filteredOperators = {"Do", "BI", "EI", "ID"};
- String[] ignoredOperators = {"b", "B", "b*", "B*", "c", "cm", "d", "f", "F", "f*", "G", "g", "h", "i", "j", "J", "K", "l", "m", "M", "n", "re", "RG", "s", "S", "v", "w", "W", "W*", "y"};
-
- for (Object token : tokens) {
- if (token instanceof Operator) {
- Operator op = (Operator) token;
- System.out.println(op.getName());
- if (Arrays.asList(ignoredOperators).contains(op.getName())) {
- continue;
- }
-
- if (Arrays.asList(filteredOperators).contains(op.getName())) {
- System.out.println(op);
- //remove the one argument to this operator
- // added
- COSName name = (COSName) newTokens.remove(newTokens.size() - 1);
- System.out.println(name);
- // added
- deleteObject(newDictionary, name);
- continue;
- }
- }
- newTokens.add(token);
- }
- PDStream newContents = new PDStream(doc);
- ContentStreamWriter writer = new ContentStreamWriter(newContents.createOutputStream());
- writer.writeTokens(newTokens);
-
- page.setContents(newContents);
-
-
- // added
- PDResources newResources = new PDResources(newDictionary);
- page.setResources(newResources);
- }
-
- private static void moveRectangle(PDRectangle re, float x, float y) {
- re.setLowerLeftX(re.getLowerLeftX() + x);
- re.setLowerLeftY(re.getLowerLeftY() + y);
- re.setUpperRightX(re.getUpperRightX() + x);
- re.setUpperRightY(re.getUpperRightY() + y);
- }
-
- private static boolean deleteObject(COSDictionary d, COSName name) {
- for (COSName key : d.keySet()) {
- if (name.equals(key)) {
- d.removeItem(key);
- return true;
- }
- COSBase object = d.getDictionaryObject(key);
- if (object instanceof COSDictionary) {
- if (deleteObject((COSDictionary) object, name)) {
- return true;
- }
- }
- }
- return false;
- }
-
private static void addLabels(ArrayList<String> res, PDPageLabels labels, int pages) {
// Get the raw list
}
}
- private static void cutDocument(PDDocument doc, String input, String output, String cutmode) throws IOException {
+ private static void cutDocument(PDDocument doc, String input, String output, String cutmode) throws COSVisitorException, IOException {
System.out.println("Cut document of " + doc.getNumberOfPages() + " with mode " + cutmode);
- PDDocument finalDoc = new PDDocument();
- ArrayList<PDDocument> copies = duplicatePages(doc, input, cutmode, finalDoc);
+ ArrayList<PDDocument> copies = duplicatePages(doc, input, cutmode);
cutPages(doc, cutmode);
- finalDoc.save(output);
+ doc.save(output);
for (PDDocument d : copies) {
d.close();
if (cutmode.startsWith("L")) {
cutBy = Integer.parseInt(cutmode.substring(1));
}
- int n = doc.getNumberOfPages();
- for (int page = 1; page <= n; page++) {
- PDPage pdfPage = doc.getPage(page);
+ List<PDPage> pageList = doc.getDocumentCatalog().getAllPages();
+ int page;
+ for (int i = 0; i < pageList.size(); i++) {
+ PDPage pdfPage = pageList.get(i);
+ page = i + 1;
if (page == 1 && !cutFirst) {
System.out.println("Skip page " + page);
continue;
}
- if (page == n && !cutLast) {
+ if (page == pageList.size() && !cutLast) {
System.out.println("Skip page " + page);
continue;
}
int decalageCrans = page % cutBy;
float decalage = ((float) decalageCrans) * w;
- moveRectangle(newbox, decalage, 0f);
+ newbox.move(decalage, 0f);
System.out.println("Set cropbox of page " + page + " from " + pdfPage.getCropBox() + " to " + newbox + " (offset : " + decalage + ")");
}
}
- private static ArrayList<PDDocument> duplicatePages(PDDocument doc, String input, String cutmode, PDDocument finalDoc) throws IOException {
+ private static ArrayList<PDDocument> duplicatePages(PDDocument doc, String input, String cutmode) throws IOException {
- int originalSize = doc.getNumberOfPages();
+ List<PDPage> pageList = doc.getDocumentCatalog().getAllPages();
+ int originalSize = pageList.size();
Boolean duplicateFirst = true;
Boolean duplicateLast = true;
}
ArrayList<PDDocument> copies = new ArrayList<>();
- for (int i = 0; i <= duplicateTime; i++) {
- copies.add(i, openDocument(input));
+ for (int i = 0; i < duplicateTime; i++) {
+ copies.add(i, PDDocument.load(input));
}
+ int page;
int cursor = 0;
+ PDPageNode rootPages;
PDPage currentPage;
- for (int page = 1; page <= originalSize; page++) {
- currentPage = doc.getPage(page);
+ for (int i = 0; i < originalSize; i++) {
+ page = i + 1;
+
+ currentPage = pageList.get(i);
+ rootPages = currentPage.getParent();
+ cursor = rootPages.getKids().indexOf(currentPage) + 1;
// Skip some pages
- if ((page == 1 && !duplicateFirst) || (page == originalSize && !duplicateLast)) {
+ if (page == 1 && !duplicateFirst) {
System.out.println("Skip page " + page);
- duplicateTime = 0;
+ continue;
+ }
+ if (page == pageList.size() && !duplicateLast) {
+ System.out.println("Skip page " + page);
+ continue;
}
-
System.out.println("Duplicate page " + page + " :: cursor is at " + cursor);
// Duplicate page
- for (int j = 0; j <= duplicateTime; j++) {
- PDPage newpage = copies.get(j).getPage(page);
- finalDoc.addPage(newpage);
+ for (int j = 0; j < duplicateTime; j++) {
+ List<PDPage> l = copies.get(j).getDocumentCatalog().getAllPages();
+ PDPage newpage = l.get(i);
+ rootPages.getKids().add(cursor, newpage);
+ newpage.setParent(rootPages);
+ rootPages.updateCount();
+ cursor++;
}
}
}
public static PDDocument openDocument(String input) throws IOException {
- return PDDocument.load(new File(input));
+ return PDDocument.load(input, true);
}
System.out.println("Extraction des textes with " + method + " : " + ((Calendar.getInstance().getTimeInMillis() - s) / 1000) + "s");
}
- public static void updateCropBox(PDDocument doc, String output, String refbox, Integer[] pages, String defined) throws IOException {
+ public static void updateCropBox(PDDocument doc, String output, String refbox, Integer[] pages, String defined) throws IOException, COSVisitorException {
System.out.println("updateCropBox");
if (!"".equals(defined)) {
updateCropBoxDefined(doc, defined);
return;
}
- private static void updateCropBoxDefined(PDDocument doc, String defined) throws IOException {
- String[] e = defined.split("\\*");
+ private static void updateCropBoxDefined(PDDocument doc, String defined) throws IOException, COSVisitorException {
+ String[] e = defined.split("*");
for (int i = 0; i < e.length; i++) {
String[] e1 = e[i].split(",");
Integer[] pages = new Integer[1];
}
}
- private static void updateCropBoxRange(PDDocument doc, Integer[] pages, String refbox) throws IOException {
+ private static void updateCropBoxRange(PDDocument doc, Integer[] pages, String refbox) throws IOException, COSVisitorException {
System.out.println("updateCropBoxRange " + refbox);
refbox = refbox.trim();
+ List<PDPage> pageList = doc.getDocumentCatalog().getAllPages();
+
for (Integer page : pages) {
- PDPage p = doc.getPage(page);
+ PDPage p = pageList.get(page - 1);
if (refbox.compareTo("TrimBox") == 0) {
p.setCropBox(p.getTrimBox());
} else if (refbox.compareTo("MediaBox") == 0) {
float h = mediaBox.getHeight() - left - right;
PDRectangle box = new PDRectangle(w, h);
- moveRectangle(box, left, top);
+ box.move(left, top);
return box;
}
public static void extractLinks(PDDocument doc, String linksOutput, Integer[] pages) throws IOException {
+
+ List<PDPage> pageList = doc.getDocumentCatalog().getAllPages();
+
Boolean separate = linksOutput.contains("%d");
ArrayList<Link> listLinks = new ArrayList<>();
- int n = doc.getNumberOfPages();
- for (int page = 0; page < n; page++) {
- PDPage p = doc.getPage(page);
+ for (Integer page : pages) {
+ PDPage p = pageList.get(page - 1);
if (separate) {
extractLinksOfPage(doc, page, p, linksOutput);
} else {
Link myLink;
List<PDAnnotation> links = p.getAnnotations();
- PDRectangle cropbox = p.getCropBox();
- PDRectangle mediabox = p.getMediaBox();
+ PDRectangle cropbox = p.findCropBox();
+ PDRectangle mediabox = p.findMediaBox();
System.out.println("Found " + links.size() + " annotations");
for (PDAnnotation link : links) {
System.out.println("--extractLinks file\t:\tExtract links to file");
System.out.println("--extractTexts file\t:\tExtract texts to file");
System.out.println("--infos\t:\tget infos and return them to standard output");
- System.out.println("--infos\t:\tgenerate a pdf file that contains only the texts of input");
}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
+import java.util.regex.Pattern;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
-import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
+import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDFontDescriptor;
+import org.apache.pdfbox.pdmodel.graphics.PDGraphicsState;
import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
-import org.apache.pdfbox.pdmodel.graphics.state.PDGraphicsState;
-import org.apache.pdfbox.pdmodel.graphics.state.PDTextState;
-import org.apache.pdfbox.pdmodel.graphics.state.RenderingMode;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColorState;
+import org.apache.pdfbox.pdmodel.text.PDTextState;
import org.apache.pdfbox.util.Matrix;
-import org.apache.pdfbox.text.TextPosition;
+import org.apache.pdfbox.util.ResourceLoader;
+import org.apache.pdfbox.util.TextPosition;
/**
* @author Cube
public Page(PDPage page, int pageNumber, boolean splitAllChars, String ignoredSeparators) {
this.page = page;
- this.cropbox = page.getCropBox();
+ this.cropbox = page.findCropBox();
this.ignoredSeparators = ignoredSeparators;
this.splitAllChars = splitAllChars;
public void addText(PDGraphicsState gs, Matrix textLineMatrix, Matrix textMatrix, TextPosition textPosition, String text, boolean splitLigatures) throws IOException {
PDTextState ts = gs.getTextState();
float rotation = new CubeMatrix(textLineMatrix).getRotation();
- float size = textPosition.getFontSize() * textMatrix.getScaleX();
- float y = round(cropbox.getUpperRightY() - textPosition.getY() - cropbox.getLowerLeftY());
- float x = textPosition.getX();
+ float size = textPosition.getFontSize() * textMatrix.getXScale();
+ float y = round(cropbox.getUpperRightY() - textPosition.getTextPos().getYPosition() - cropbox.getLowerLeftY());
+ float x = textPosition.getTextPos().getXPosition();
float width = textPosition.getWidth();
float height = textPosition.getHeight();
if (width == 0.0f) {
// Determine l'espace normal dans cette font
float spaceWidth = textPosition.getWidthOfSpace();
- float lineScaleX = textLineMatrix.getScaleX();
- float lineScaleY = textLineMatrix.getScaleY();
+ float lineScaleX = textLineMatrix.getXScale();
+ float lineScaleY = textLineMatrix.getYScale();
// On normalise les échelles
float minScale = Math.abs(lineScaleX);
lineScaleY /= minScale;
Line line = getLine(y, rotation, lineScaleX, lineScaleY);
- if (splitLigatures && text.length() > 1) {
+ if ( splitLigatures && text.length() > 1) {
if (isRtl(text)) {
for (int i = 0; i < text.length(); i++) {
- line.addText(size, x, y, width, height, text.substring(i, i + 1), spaceWidth);
+ line.addText(size, x, y, width, height, text.substring(i, i+1), spaceWidth);
}
} else {
for (int i = 0; i < text.length(); i++) {
protected String parseColor(PDTextState ts, PDGraphicsState gs)
throws IOException {
- PDColor pcs;
+ PDColorState pcs;
- if (ts.getRenderingMode() == RenderingMode.FILL) {
+ if (ts.getRenderingMode() == PDTextState.RENDERING_MODE_FILL_TEXT) {
pcs = gs.getNonStrokingColor();
- } else if (ts.getRenderingMode() == RenderingMode.STROKE) {
+ } else if (ts.getRenderingMode() == PDTextState.RENDERING_MODE_STROKE_TEXT) {
pcs = gs.getStrokingColor();
- } else if (ts.getRenderingMode() == RenderingMode.NEITHER) {
+ } else if (ts.getRenderingMode() == PDTextState.RENDERING_MODE_NEITHER_FILL_NOR_STROKE_TEXT) {
pcs = gs.getStrokingColor();
} else {
pcs = gs.getStrokingColor();
}
- PDColorSpace cs = pcs.getColorSpace();
+ ColorSpace cs = getColorSpace(pcs.getColorSpace());
- float[] components = pcs.getComponents();
+ float[] components = pcs.getJavaColor().getColorComponents(null);
float[] componentsRGB = cs.toRGB(components);
Color c = new Color(0, 0, 0);
return color;
}
+ protected ColorSpace _loadColorSpace(String path) throws IOException {
+ if (!_cs.containsKey(path)) {
+ _cs.put(path,
+ new ICC_ColorSpace(ICC_Profile.getInstance(ResourceLoader.loadResource(path))));
+ }
+
+ return _cs.get(path);
+
+ }
+
+ protected ColorSpace getColorSpace(PDColorSpace pdfCS) throws IOException {
+ ColorSpace cs = pdfCS.getJavaColorSpace();
+ if (pdfCS.getName().equals("DeviceCMYK")) {
+ cs = _loadColorSpace("com/adobe/icc/cmyk/USWebCoatedSWOP.icc");
+ }
+
+ return cs;
+
+ }
}