You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ja...@apache.org on 2015/01/06 20:52:50 UTC
svn commit: r1649918 - in /pdfbox/trunk:
examples/src/main/java/org/apache/pdfbox/examples/documentmanipulation/
examples/src/main/java/org/apache/pdfbox/examples/pdfa/
examples/src/main/java/org/apache/pdfbox/examples/pdmodel/
pdfbox/src/main/java/org...
Author: jahewson
Date: Tue Jan 6 19:52:49 2015
New Revision: 1649918
URL: http://svn.apache.org/r1649918
Log:
PDFBOX-2590: Rename drawString to showText to match PDF spec.
Modified:
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/documentmanipulation/SuperimposePage.java
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdfa/CreatePDFA.java
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMessageToEachPage.java
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/Annotation.java
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateLandscapePDF.java
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFiles.java
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFonts.java
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorld.java
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1AfmPfb.java
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/UsingTextMatrix.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/edit/PDPageContentStream.java
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/TestOptionalContentGroups.java
pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestLayerUtility.java
pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/TextToPDF.java
pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestPDFText2HTML.java
Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/documentmanipulation/SuperimposePage.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/documentmanipulation/SuperimposePage.java?rev=1649918&r1=1649917&r2=1649918&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/documentmanipulation/SuperimposePage.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/documentmanipulation/SuperimposePage.java Tue Jan 6 19:52:49 2015
@@ -54,7 +54,7 @@ public class SuperimposePage {
aContent.beginText();
aContent.setFont(font, 12);
aContent.newLineAtOffset(2, 5);
- aContent.drawString("Import a pdf file:");
+ aContent.showText("Import a pdf file:");
aContent.endText();
aContent.close();
Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdfa/CreatePDFA.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdfa/CreatePDFA.java?rev=1649918&r1=1649917&r2=1649918&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdfa/CreatePDFA.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdfa/CreatePDFA.java Tue Jan 6 19:52:49 2015
@@ -86,7 +86,7 @@ public class CreatePDFA
contentStream.beginText();
contentStream.setFont( font, 12 );
contentStream.newLineAtOffset(100, 700);
- contentStream.drawString( message );
+ contentStream.showText(message);
contentStream.endText();
contentStream.saveGraphicsState();
contentStream.close();
Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMessageToEachPage.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMessageToEachPage.java?rev=1649918&r1=1649917&r2=1649918&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMessageToEachPage.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/AddMessageToEachPage.java Tue Jan 6 19:52:49 2015
@@ -90,7 +90,7 @@ public class AddMessageToEachPage
{
contentStream.setTextMatrix(Matrix.getTranslateInstance(centerX, centerY));
}
- contentStream.drawString( message );
+ contentStream.showText(message);
contentStream.endText();
contentStream.close();
}
Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/Annotation.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/Annotation.java?rev=1649918&r1=1649917&r2=1649918&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/Annotation.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/Annotation.java Tue Jan 6 19:52:49 2015
@@ -101,9 +101,9 @@ public class Annotation
contentStream.beginText();
contentStream.setFont( font, 18 );
contentStream.newLineAtOffset(inch, ph - inch - 18);
- contentStream.drawString( "PDFBox" );
+ contentStream.showText("PDFBox");
contentStream.newLineAtOffset(0, -(inch / 2));
- contentStream.drawString( "Click Here" );
+ contentStream.showText("Click Here");
contentStream.endText();
contentStream.close();
Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateLandscapePDF.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateLandscapePDF.java?rev=1649918&r1=1649917&r2=1649918&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateLandscapePDF.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreateLandscapePDF.java Tue Jan 6 19:52:49 2015
@@ -73,11 +73,11 @@ public class CreateLandscapePDF
contentStream.setFont( font, fontSize );
contentStream.beginText();
contentStream.newLineAtOffset(startX, startY);
- contentStream.drawString( message);
+ contentStream.showText(message);
contentStream.newLineAtOffset(0, 100);
- contentStream.drawString( message);
+ contentStream.showText(message);
contentStream.newLineAtOffset(100, 100);
- contentStream.drawString( message);
+ contentStream.showText(message);
contentStream.endText();
contentStream.drawLine(startX-2, startY-2, startX-2, startY+200+fontSize);
Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFiles.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFiles.java?rev=1649918&r1=1649917&r2=1649918&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFiles.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFiles.java Tue Jan 6 19:52:49 2015
@@ -74,7 +74,7 @@ public class EmbeddedFiles
contentStream.beginText();
contentStream.setFont( font, 12 );
contentStream.newLineAtOffset(100, 700);
- contentStream.drawString( "Go to Document->File Attachments to View Embedded Files" );
+ contentStream.showText("Go to Document->File Attachments to View Embedded Files");
contentStream.endText();
contentStream.close();
Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFonts.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFonts.java?rev=1649918&r1=1649917&r2=1649918&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFonts.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/EmbeddedFonts.java Tue Jan 6 19:52:49 2015
@@ -49,13 +49,13 @@ public class EmbeddedFonts
stream.setLeading(12 * 1.2);
stream.newLineAtOffset(50, 600);
- stream.drawString("PDFBox Unicode with Embedded TrueType Font");
+ stream.showText("PDFBox Unicode with Embedded TrueType Font");
stream.newLine();
- stream.drawString("Supports full Unicode text âº");
+ stream.showText("Supports full Unicode text âº");
stream.newLine();
- stream.drawString("English ÑÑÑÑкий ÑзÑк Tiếng Viá»t");
+ stream.showText("English ÑÑÑÑкий ÑзÑк Tiếng Viá»t");
stream.endText();
stream.close();
Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorld.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorld.java?rev=1649918&r1=1649917&r2=1649918&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorld.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorld.java Tue Jan 6 19:52:49 2015
@@ -68,7 +68,7 @@ public class HelloWorld
contentStream.beginText();
contentStream.setFont( font, 12 );
contentStream.newLineAtOffset(100, 700);
- contentStream.drawString( message );
+ contentStream.showText(message);
contentStream.endText();
contentStream.close();
doc.save( file );
Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java?rev=1649918&r1=1649917&r2=1649918&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldTTF.java Tue Jan 6 19:52:49 2015
@@ -63,7 +63,7 @@ public class HelloWorldTTF
contentStream.beginText();
contentStream.setFont(font, 12);
contentStream.newLineAtOffset(100, 700);
- contentStream.drawString(message);
+ contentStream.showText(message);
contentStream.endText();
contentStream.close();
doc.save(file);
Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1AfmPfb.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1AfmPfb.java?rev=1649918&r1=1649917&r2=1649918&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1AfmPfb.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/HelloWorldType1AfmPfb.java Tue Jan 6 19:52:49 2015
@@ -65,7 +65,7 @@ public class HelloWorldType1AfmPfb
contentStream.beginText();
contentStream.setFont(font, 12);
contentStream.newLineAtOffset(100, 700);
- contentStream.drawString(message);
+ contentStream.showText(message);
contentStream.endText();
contentStream.close();
doc.save(file);
Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/UsingTextMatrix.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/UsingTextMatrix.java?rev=1649918&r1=1649917&r2=1649918&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/UsingTextMatrix.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/UsingTextMatrix.java Tue Jan 6 19:52:49 2015
@@ -75,14 +75,14 @@ public class UsingTextMatrix
{
contentStream.setTextMatrix(Matrix.getRotateInstance(i * Math.PI * 0.25,
centeredXPosition, pageSize.getHeight() - centeredYPosition));
- contentStream.drawString( message + " " + i);
+ contentStream.showText(message + " " + i);
}
// clockwise rotation
for (int i=0;i<8;i++)
{
contentStream.setTextMatrix(Matrix.getRotateInstance(-i*Math.PI*0.25,
centeredXPosition, centeredYPosition));
- contentStream.drawString( message + " " + i);
+ contentStream.showText(message + " " + i);
}
contentStream.endText();
@@ -101,7 +101,7 @@ public class UsingTextMatrix
for (int i=0;i<10;i++)
{
contentStream.setTextMatrix(new Matrix(12 + (i * 6), 0, 0, 12+(i*6), 100, 100+i*50));
- contentStream.drawString( message + " " +i);
+ contentStream.showText(message + " " + i);
}
contentStream.endText();
contentStream.close();
@@ -118,16 +118,16 @@ public class UsingTextMatrix
int i = 0;
// text scaling combined with rotation
contentStream.setTextMatrix(new Matrix(12, 0, 0, 12, centeredXPosition, centeredYPosition*1.5f));
- contentStream.drawString( message + " " +i++);
+ contentStream.showText(message + " " + i++);
contentStream.setTextMatrix(new Matrix(0, 18, -18, 0, centeredXPosition, centeredYPosition*1.5f));
- contentStream.drawString( message + " " +i++);
+ contentStream.showText(message + " " + i++);
contentStream.setTextMatrix(new Matrix(-24, 0, 0, -24, centeredXPosition, centeredYPosition*1.5f));
- contentStream.drawString( message + " " +i++);
+ contentStream.showText(message + " " + i++);
contentStream.setTextMatrix(new Matrix(0, -30, 30, 0, centeredXPosition, centeredYPosition*1.5f));
- contentStream.drawString( message + " " +i++);
+ contentStream.showText(message + " " + i++);
contentStream.endText();
contentStream.close();
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/edit/PDPageContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/edit/PDPageContentStream.java?rev=1649918&r1=1649917&r2=1649918&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/edit/PDPageContentStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/edit/PDPageContentStream.java Tue Jan 6 19:52:49 2015
@@ -362,145 +362,54 @@ public class PDPageContentStream impleme
}
/**
- * Draw an image at the x,y coordinates, with the default size of the image.
- *
- * @param image The image to draw.
- * @param x The x-coordinate to draw the image.
- * @param y The y-coordinate to draw the image.
+ * This will draw a string at the current location on the screen.
*
- * @throws IOException If there is an error writing to the stream.
+ * @param text The text to draw.
+ * @throws IOException If an io exception occurs.
+ * @deprecated Use {@link #showText} instead.
*/
- public void drawImage(PDImageXObject image, float x, float y) throws IOException
+ @Deprecated
+ public void drawString(String text) throws IOException
{
- drawXObject(image, x, y, image.getWidth(), image.getHeight());
+ showText(text);
}
/**
- * Draw an xobject(form or image) at the x,y coordinates and a certain width and height.
- *
- * @param xobject The xobject to draw.
- * @param x The x-coordinate to draw the image.
- * @param y The y-coordinate to draw the image.
- * @param width The width of the image to draw.
- * @param height The height of the image to draw.
+ * Shows the given text at the location specified by the current text matrix.
*
- * @throws IOException If there is an error writing to the stream.
+ * @param text The Unicode text to show.
+ * @throws IOException If an io exception occurs.
*/
- public void drawXObject(PDXObject xobject, float x, float y, float width, float height) throws IOException
+ public void showText(String text) throws IOException
{
- AffineTransform transform = new AffineTransform(width, 0, 0, height, x, y);
- drawXObject(xobject, transform);
- }
+ if (!inTextMode)
+ {
+ throw new IllegalStateException("Must call beginText() before showText()");
+ }
- /**
- * Draw an inline image at the x,y coordinates, with the default size of the image.
- *
- * @param inlineImage The inline image to draw.
- * @param x The x-coordinate to draw the inline image.
- * @param y The y-coordinate to draw the inline image.
- *
- * @throws IOException If there is an error writing to the stream.
- */
- public void drawInlineImage(PDInlineImage inlineImage, float x, float y) throws IOException
- {
- drawInlineImage(inlineImage, x, y, inlineImage.getWidth(), inlineImage.getHeight());
- }
-
- /**
- * Draw an inline image at the x,y coordinates and a certain width and height.
- *
- * @param inlineImage The inline image to draw.
- * @param x The x-coordinate to draw the inline image.
- * @param y The y-coordinate to draw the inline image.
- * @param width The width of the inline image to draw.
- * @param height The height of the inline image to draw.
- *
- * @throws IOException If there is an error writing to the stream.
- */
- public void drawInlineImage(PDInlineImage inlineImage, float x, float y, float width, float height) throws IOException
- {
- if (inTextMode)
+ if (fontStack.isEmpty())
{
- throw new IOException("Error: drawInlineImage is not allowed within a text block.");
+ throw new IllegalStateException("Must call setFont() before showText()");
}
- saveGraphicsState();
- transform(new Matrix(width, 0, 0, height, x, y));
- appendRawCommands("BI\n");
- appendRawCommands("/W");
- appendRawCommands(SPACE);
- appendRawCommands(Integer.toString(inlineImage.getWidth()));
- appendRawCommands(SPACE);
- appendRawCommands("/H");
- appendRawCommands(SPACE);
- appendRawCommands(Integer.toString(inlineImage.getHeight()));
- appendRawCommands(SPACE);
- appendRawCommands("/CS");
- appendRawCommands(SPACE);
- appendRawCommands("/");
- appendRawCommands(inlineImage.getColorSpace().getName());
- appendRawCommands(NEWLINE);
- if (inlineImage.getDecode() != null && inlineImage.getDecode().size() > 0)
+
+ PDFont font = fontStack.peek();
+
+ // Unicode code points to keep when subsetting
+ Set<Integer> codePoints = subsetCodePoints.get(font);
+ if (codePoints != null)
{
- appendRawCommands("/D");
- appendRawCommands(SPACE);
- appendRawCommands(OPENING_BRACKET);
- appendRawCommands(SPACE);
- for (COSBase cosBase : inlineImage.getDecode())
+ for (int offset = 0; offset < text.length(); )
{
- COSInteger cosInt = (COSInteger) cosBase;
- appendRawCommands(Integer.toString(cosInt.intValue()));
- appendRawCommands(SPACE);
+ int codePoint = text.codePointAt(offset);
+ codePoints.add(codePoint);
+ offset += Character.charCount(codePoint);
}
- appendRawCommands(CLOSING_BRACKET);
- appendRawCommands("\n");
- }
- if (inlineImage.isStencil())
- {
- appendRawCommands("/IM true\n");
- }
- appendRawCommands("/BPC");
- appendRawCommands(SPACE);
- appendRawCommands(Integer.toString(inlineImage.getBitsPerComponent()));
- appendRawCommands(NEWLINE);
- appendRawCommands("ID\n");
- appendRawCommands(inlineImage.getStream().getByteArray());
- appendRawCommands(NEWLINE);
- appendRawCommands("EI\n");
- restoreGraphicsState();
- }
- /**
- * Draw an xobject(form or image) using the given {@link AffineTransform} to position
- * the xobject.
- *
- * @param xobject The xobject to draw.
- * @param transform the transformation matrix
- * @throws IOException If there is an error writing to the stream.
- */
- public void drawXObject(PDXObject xobject, AffineTransform transform) throws IOException
- {
- if (inTextMode)
- {
- throw new IOException("Error: drawXObject is not allowed within a text block.");
- }
- String xObjectPrefix = null;
- if (xobject instanceof PDImageXObject)
- {
- xObjectPrefix = "Im";
- }
- else
- {
- xObjectPrefix = "Form";
}
- COSName objMapping = resources.add(xobject, xObjectPrefix);
- saveGraphicsState();
- appendRawCommands(SPACE);
- transform(new Matrix(transform));
- appendRawCommands(SPACE);
- appendCOSName(objMapping);
+
+ COSWriter.writeString(font.encode(text), output);
appendRawCommands(SPACE);
- appendRawCommands(XOBJECT_DO);
- restoreGraphicsState();
+ appendRawCommands(SHOW_TEXT);
}
/**
@@ -665,6 +574,148 @@ public class PDPageContentStream impleme
}
/**
+ * Draw an image at the x,y coordinates, with the default size of the image.
+ *
+ * @param image The image to draw.
+ * @param x The x-coordinate to draw the image.
+ * @param y The y-coordinate to draw the image.
+ *
+ * @throws IOException If there is an error writing to the stream.
+ */
+ public void drawImage(PDImageXObject image, float x, float y) throws IOException
+ {
+ drawXObject(image, x, y, image.getWidth(), image.getHeight());
+ }
+
+ /**
+ * Draw an xobject(form or image) at the x,y coordinates and a certain width and height.
+ *
+ * @param xobject The xobject to draw.
+ * @param x The x-coordinate to draw the image.
+ * @param y The y-coordinate to draw the image.
+ * @param width The width of the image to draw.
+ * @param height The height of the image to draw.
+ *
+ * @throws IOException If there is an error writing to the stream.
+ */
+ public void drawXObject(PDXObject xobject, float x, float y, float width, float height) throws IOException
+ {
+ AffineTransform transform = new AffineTransform(width, 0, 0, height, x, y);
+ drawXObject(xobject, transform);
+ }
+
+ /**
+ * Draw an inline image at the x,y coordinates, with the default size of the image.
+ *
+ * @param inlineImage The inline image to draw.
+ * @param x The x-coordinate to draw the inline image.
+ * @param y The y-coordinate to draw the inline image.
+ *
+ * @throws IOException If there is an error writing to the stream.
+ */
+ public void drawInlineImage(PDInlineImage inlineImage, float x, float y) throws IOException
+ {
+ drawInlineImage(inlineImage, x, y, inlineImage.getWidth(), inlineImage.getHeight());
+ }
+
+ /**
+ * Draw an inline image at the x,y coordinates and a certain width and height.
+ *
+ * @param inlineImage The inline image to draw.
+ * @param x The x-coordinate to draw the inline image.
+ * @param y The y-coordinate to draw the inline image.
+ * @param width The width of the inline image to draw.
+ * @param height The height of the inline image to draw.
+ *
+ * @throws IOException If there is an error writing to the stream.
+ */
+ public void drawInlineImage(PDInlineImage inlineImage, float x, float y, float width, float height) throws IOException
+ {
+ if (inTextMode)
+ {
+ throw new IOException("Error: drawInlineImage is not allowed within a text block.");
+ }
+ saveGraphicsState();
+ transform(new Matrix(width, 0, 0, height, x, y));
+ appendRawCommands("BI\n");
+ appendRawCommands("/W");
+ appendRawCommands(SPACE);
+ appendRawCommands(Integer.toString(inlineImage.getWidth()));
+ appendRawCommands(SPACE);
+ appendRawCommands("/H");
+ appendRawCommands(SPACE);
+ appendRawCommands(Integer.toString(inlineImage.getHeight()));
+ appendRawCommands(SPACE);
+ appendRawCommands("/CS");
+ appendRawCommands(SPACE);
+ appendRawCommands("/");
+ appendRawCommands(inlineImage.getColorSpace().getName());
+ appendRawCommands(NEWLINE);
+ if (inlineImage.getDecode() != null && inlineImage.getDecode().size() > 0)
+ {
+ appendRawCommands("/D");
+ appendRawCommands(SPACE);
+ appendRawCommands(OPENING_BRACKET);
+ appendRawCommands(SPACE);
+ for (COSBase cosBase : inlineImage.getDecode())
+ {
+ COSInteger cosInt = (COSInteger) cosBase;
+ appendRawCommands(Integer.toString(cosInt.intValue()));
+ appendRawCommands(SPACE);
+ }
+ appendRawCommands(CLOSING_BRACKET);
+ appendRawCommands("\n");
+ }
+ if (inlineImage.isStencil())
+ {
+ appendRawCommands("/IM true\n");
+ }
+ appendRawCommands("/BPC");
+ appendRawCommands(SPACE);
+ appendRawCommands(Integer.toString(inlineImage.getBitsPerComponent()));
+ appendRawCommands(NEWLINE);
+ appendRawCommands("ID\n");
+ appendRawCommands(inlineImage.getStream().getByteArray());
+ appendRawCommands(NEWLINE);
+ appendRawCommands("EI\n");
+ restoreGraphicsState();
+ }
+
+ /**
+ * Draw an xobject(form or image) using the given {@link AffineTransform} to position
+ * the xobject.
+ *
+ * @param xobject The xobject to draw.
+ * @param transform the transformation matrix
+ * @throws IOException If there is an error writing to the stream.
+ */
+ public void drawXObject(PDXObject xobject, AffineTransform transform) throws IOException
+ {
+ if (inTextMode)
+ {
+ throw new IOException("Error: drawXObject is not allowed within a text block.");
+ }
+ String xObjectPrefix = null;
+ if (xobject instanceof PDImageXObject)
+ {
+ xObjectPrefix = "Im";
+ }
+ else
+ {
+ xObjectPrefix = "Form";
+ }
+ COSName objMapping = resources.add(xobject, xObjectPrefix);
+ saveGraphicsState();
+ appendRawCommands(SPACE);
+ transform(new Matrix(transform));
+ appendRawCommands(SPACE);
+ appendCOSName(objMapping);
+ appendRawCommands(SPACE);
+ appendRawCommands(XOBJECT_DO);
+ restoreGraphicsState();
+ }
+
+ /**
* The Tm operator. Sets the text matrix to the given rotation and translation values.
* A current text matrix will be replaced with the new one.
* @param angle The angle used for the counterclockwise rotation in radians.
@@ -735,44 +786,6 @@ public class PDPageContentStream impleme
}
/**
- * This will draw a string at the current location on the screen.
- *
- * @param text The text to draw.
- * @throws IOException If an io exception occurs.
- */
- public void drawString(String text) throws IOException
- {
- if (!inTextMode)
- {
- throw new IllegalStateException("Must call beginText() before drawString()");
- }
-
- if (fontStack.isEmpty())
- {
- throw new IllegalStateException("Must call setFont() before drawString()");
- }
-
- PDFont font = fontStack.peek();
-
- // Unicode code points to keep when subsetting
- Set<Integer> codePoints = subsetCodePoints.get(font);
- if (codePoints != null)
- {
- for (int offset = 0; offset < text.length(); )
- {
- int codePoint = text.codePointAt(offset);
- codePoints.add(codePoint);
- offset += Character.charCount(codePoint);
- }
-
- }
-
- COSWriter.writeString(font.encode(text), output);
- appendRawCommands(SPACE);
- appendRawCommands(SHOW_TEXT);
- }
-
- /**
* Set the stroking color space. This will add the colorspace to the PDResources
* if necessary.
*
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java?rev=1649918&r1=1649917&r2=1649918&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java Tue Jan 6 19:52:49 2015
@@ -69,7 +69,7 @@ public class TestFontEmbedding extends T
String text = "Unicode ÑÑÑÑкий ÑзÑк Tiếng Viá»t";
stream.newLineAtOffset(50, 600);
- stream.drawString(text);
+ stream.showText(text);
stream.endText();
stream.close();
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/TestOptionalContentGroups.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/TestOptionalContentGroups.java?rev=1649918&r1=1649917&r2=1649918&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/TestOptionalContentGroups.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/TestOptionalContentGroups.java Tue Jan 6 19:52:49 2015
@@ -111,13 +111,13 @@ public class TestOptionalContentGroups e
contentStream.beginText();
contentStream.setFont(font, 14);
contentStream.newLineAtOffset(80, 700);
- contentStream.drawString("PDF 1.5: Optional Content Groups");
+ contentStream.showText("PDF 1.5: Optional Content Groups");
contentStream.endText();
font = PDType1Font.HELVETICA;
contentStream.beginText();
contentStream.setFont(font, 12);
contentStream.newLineAtOffset(80, 680);
- contentStream.drawString("You should see a green textline, but no red text line.");
+ contentStream.showText("You should see a green textline, but no red text line.");
contentStream.endText();
contentStream.endMarkedContentSequence();
@@ -127,7 +127,7 @@ public class TestOptionalContentGroups e
contentStream.beginText();
contentStream.setFont(font, 12);
contentStream.newLineAtOffset(80, 600);
- contentStream.drawString(
+ contentStream.showText(
"This is from an enabled layer. If you see this, that's good.");
contentStream.endText();
contentStream.endMarkedContentSequence();
@@ -138,7 +138,7 @@ public class TestOptionalContentGroups e
contentStream.beginText();
contentStream.setFont(font, 12);
contentStream.newLineAtOffset(80, 500);
- contentStream.drawString(
+ contentStream.showText(
"This is from a disabled layer. If you see this, that's NOT good!");
contentStream.endText();
contentStream.endMarkedContentSequence();
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestLayerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestLayerUtility.java?rev=1649918&r1=1649917&r2=1649918&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestLayerUtility.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestLayerUtility.java Tue Jan 6 19:52:49 2015
@@ -144,7 +144,7 @@ public class TestLayerUtility extends Te
contentStream.beginText();
contentStream.newLineAtOffset(50, 720);
contentStream.setFont(font, 14);
- contentStream.drawString("Simple test document with text.");
+ contentStream.showText("Simple test document with text.");
contentStream.endText();
font = PDType1Font.HELVETICA;
contentStream.beginText();
@@ -154,7 +154,7 @@ public class TestLayerUtility extends Te
for (String line : text)
{
contentStream.newLineAtOffset(0, -fontSize * 1.2f);
- contentStream.drawString(line);
+ contentStream.showText(line);
}
contentStream.endText();
contentStream.close();
@@ -202,7 +202,7 @@ public class TestLayerUtility extends Te
transform.rotate(Math.toRadians(45));
transform.translate(-190 /* sw/2 */, 0);
contentStream.setTextMatrix(transform);
- contentStream.drawString(text);
+ contentStream.showText(text);
contentStream.endText();
contentStream.close();
Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/TextToPDF.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/TextToPDF.java?rev=1649918&r1=1649917&r2=1649918&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/TextToPDF.java (original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/TextToPDF.java Tue Jan 6 19:52:49 2015
@@ -160,7 +160,7 @@ public class TextToPDF
}
contentStream.newLineAtOffset(0, -height);
y -= height;
- contentStream.drawString( nextLineToDraw.toString() );
+ contentStream.showText(nextLineToDraw.toString());
}
Modified: pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestPDFText2HTML.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestPDFText2HTML.java?rev=1649918&r1=1649917&r2=1649918&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestPDFText2HTML.java (original)
+++ pdfbox/trunk/tools/src/test/java/org/apache/pdfbox/tools/TestPDFText2HTML.java Tue Jan 6 19:52:49 2015
@@ -40,7 +40,7 @@ public class TestPDFText2HTML extends Te
contentStream.beginText();
contentStream.setFont(font, 12);
contentStream.newLineAtOffset(100, 700);
- contentStream.drawString(text);
+ contentStream.showText(text);
contentStream.endText();
contentStream.close();
return doc;