You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2016/04/27 23:08:29 UTC

svn commit: r1741341 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java

Author: tilman
Date: Wed Apr 27 21:08:29 2016
New Revision: 1741341

URL: http://svn.apache.org/viewvc?rev=1741341&view=rev
Log:
PDFBOX-3316: allow to write a comment, as suggested by Jerrol Etheredge

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java?rev=1741341&r1=1741340&r2=1741341&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDPageContentStream.java Wed Apr 27 21:08:29 2016
@@ -2196,6 +2196,25 @@ public final class PDPageContentStream i
     }
 
     /**
+     * Write a comment line.
+     *
+     * @param comment
+     * @throws IOException If the content stream could not be written.
+     * @throws IllegalArgumentException If the comment contains a newline. This is not allowed,
+     * because the next line could be ordinary PDF content.
+     */
+    public void addComment(String comment) throws IOException
+    {
+        if (comment.indexOf('\n') >= 0 || comment.indexOf('\r') >= 0)
+        {
+            throw new IllegalArgumentException("comment should not include a newline");
+        }
+        output.write('%');
+        output.write(comment.getBytes(Charsets.US_ASCII));
+        output.write('\n');
+    }
+
+    /**
      * Writes a real real to the content stream.
      */
     private void writeOperand(float real) throws IOException