Skip to content

PDF: pixelDensity(2) throws off scaling when creating PDFs using beginRecord() and createGraphics(PDF) #6216

@rapatski

Description

@rapatski

Description

With pixelDensity(2) enabled, PDF exports using offscreen buffers like beginRecord() and createGraphics(PDF) need to be scaled by 0.5 (1 / float(pixelDensity)) to have the expected result.

Steps to Reproduce

import processing.pdf.*;

void settings()
{
  pixelDensity(2);
  size(500, 500);
}

void setup()
{
  beginRecord(PDF, "test.pdf");

  //scale(1 / float(pixelDensity)); // uncomment to get expected pdf output
  background(0, 255, 0);
  rect(0, 0, width, height, 100, 100, 100, 100);

  endRecord();
}

void draw() {}

void exportUsingPGraphics()
{
  PGraphics pdf = createGraphics(width, height, PDF, "test_usingpgraphics.pdf");
  pdf.beginDraw();
  pdf.background(0, 0, 255);
  //pdf.scale(1 / float(pixelDensity)); // uncomment to get expected pdf output
  pdf.fill(255, 0, 0);
  pdf.rect(0, 0, width, height, 100, 100, 100, 100);
  pdf.dispose();
  pdf.endDraw();
}

void keyReleased()
{
  exportUsingPGraphics();
}

Your Environment

  • Processing version: 3.5.4
  • Operating System and OS version: macOS Mojave 11.4 (20F71)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions