saveGraphicsState(); transform(new Matrix(transform));
private void contentStreamSaveState() throws IOException { saveCounter++; contentStream.saveGraphicsState(); }
contents.saveGraphicsState(); Matrix matrix = Matrix.getScaleInstance(0.5f, 0.5f); contents.transform(matrix); contents.saveGraphicsState(); matrix.rotate(1.8 * Math.PI); // radians contents.transform(matrix);
contentStream.saveGraphicsState(); contentStream.transform(new Matrix(transform)); contentStream.drawForm(form);
public void saveGraphics() { try { saveGraphicsCounter++; cs.saveGraphicsState(); } catch (IOException e) { logAndThrow("saveGraphics", e); } }
contentStream.saveGraphicsState();
public void saveGraphics() { try { saveGraphicsCounter++; cs.saveGraphicsState(); } catch (IOException e) { logAndThrow("saveGraphics", e); } }
cs.saveGraphicsState(); cs.transform(Matrix.getScaleInstance(0.25f, 0.25f)); PDImageXObject img = PDImageXObject.createFromFileByExtension(imageFile, doc);
public void placeXForm(float x, float y, PDFormXObject xFormObject) { try { cs.saveGraphicsState(); cs.transform(new Matrix(AffineTransform.getTranslateInstance(x, y))); cs.drawForm(xFormObject); cs.restoreGraphicsState(); } catch (IOException e) { logAndThrow("placeXForm", e); } } }
public void placeXForm(float x, float y, PDFormXObject xFormObject) { try { cs.saveGraphicsState(); cs.transform(new Matrix(AffineTransform.getTranslateInstance(x, y))); cs.drawForm(xFormObject); cs.restoreGraphicsState(); } catch (IOException e) { logAndThrow("placeXForm", e); } } }
PDPage pdPage = doc.getPage(page); InputStream oldContentStream = pdPage.getContents(); byte[] ba = IOUtils.toByteArray(oldContentStream); oldContentStream.close(); // brings a warning because a content stream already exists PDPageContentStream newContentStream = new PDPageContentStream(doc, pdPage, false, true); // createFromFile is the easiest way with an image file // if you already have the image in a BufferedImage, // call LosslessFactory.createFromImage() instead PDImageXObject pdImage = PDImageXObject.createFromFile(imagePath, doc); newContentStream.saveGraphicsState(); newContentStream.drawImage(pdImage, 0, 0); newContentStream.restoreGraphicsState(); newContentStream.close(); // append the saved existing content stream PDPageContentStream newContentStream2 = new PDPageContentStream(doc, pdPage, true, true); newContentStream2.appendRawCommands(ba); // deprecated... needs to be rediscussed among devs newContentStream2.close();
/** * Draw an image at the x,y coordinates, with the given size. * * @param image The image to draw. * @param x The x-coordinate to draw the image. * @param y The y-coordinate to draw the image. * @param width The width to draw the image. * @param height The height to draw the image. * * @throws IOException If there is an error writing to the stream. * @throws IllegalStateException If the method was called within a text block. */ public void drawImage(PDImageXObject image, float x, float y, float width, float height) throws IOException { if (inTextMode) { throw new IllegalStateException("Error: drawImage is not allowed within a text block."); } saveGraphicsState(); AffineTransform transform = new AffineTransform(width, 0, 0, height, x, y); transform(new Matrix(transform)); writeOperand(resources.add(image)); writeOperator("Do"); restoreGraphicsState(); }
saveGraphicsState(); transform(new Matrix(transform));
saveGraphicsState(); transform(new Matrix(width, 0, 0, height, x, y));
/** * Draw an image at the origin with the given transformation matrix. * * @param image The image to draw. * @param matrix The transformation matrix to apply to the image. * * @throws IOException If there is an error writing to the stream. * @throws IllegalStateException If the method was called within a text block. */ public void drawImage(PDImageXObject image, Matrix matrix) throws IOException { if (inTextMode) { throw new IllegalStateException("Error: drawImage is not allowed within a text block."); } saveGraphicsState(); AffineTransform transform = matrix.createAffineTransform(); transform(new Matrix(transform)); writeOperand(resources.add(image)); writeOperator("Do"); restoreGraphicsState(); }
saveGraphicsState(); transform(new Matrix(transform));
... PDPageContentStream contentStream = new PDPageContentStream( document, page, true, true, true); contentStream.saveGraphicsState(); contentStream.beginText(); // set font and font size contentStream.setFont(pdfFont, fontSize); // set text color to red contentStream.setNonStrokingColor(240, 240, 240); if (rotate) { // rotate the text according to the page rotation contentStream.setTextRotation(degree, x, y); } else { contentStream.setTextTranslation(centeredXPosition, centeredYPosition); } contentStream.drawString(text); contentStream.endText(); contentStream.restoreGraphicsState(); contentStream.close(); ...
contents.saveGraphicsState(); Matrix matrix = Matrix.getScaleInstance(0.5f, 0.5f); contents.transform(matrix); contents.saveGraphicsState(); matrix.rotate(1.8 * Math.PI); // radians contents.transform(matrix);
contentStream.saveGraphicsState(); contentStream.transform(new Matrix(transform)); contentStream.drawForm(form);
targetDoc, targetPage, AppendMode.APPEND, !DEBUG); contentStream.beginMarkedContent(COSName.OC, layer); contentStream.saveGraphicsState(); contentStream.transform(new Matrix(transform)); contentStream.drawForm(form);