{"record":{"id":"a03e75da54c4b2c6","repo":"zxing/zxing","slug":"can-only-encode-pdf-417-but-got-format","errorCode":null,"errorMessage":"Can only encode PDF_417, but got {format}","messagePattern":"Can only encode PDF_417, but got (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/com/google/zxing/pdf417/PDF417Writer.java","lineNumber":54,"sourceCode":"\n  /**\n   * default white space (margin) around the code\n   */\n  private static final int WHITE_SPACE = 30;\n\n  /**\n   * default error correction level\n   */\n  private static final int DEFAULT_ERROR_CORRECTION_LEVEL = 2;\n\n  @Override\n  public BitMatrix encode(String contents,\n                          BarcodeFormat format,\n                          int width,\n                          int height,\n                          Map<EncodeHintType,?> hints) throws WriterException {\n    if (format != BarcodeFormat.PDF_417) {\n      throw new IllegalArgumentException(\"Can only encode PDF_417, but got \" + format);\n    }\n\n    PDF417 encoder = new PDF417();\n    int margin = WHITE_SPACE;\n    int errorCorrectionLevel = DEFAULT_ERROR_CORRECTION_LEVEL;\n    boolean autoECI = false;\n\n    if (hints != null) {\n      if (hints.containsKey(EncodeHintType.PDF417_COMPACT)) {\n        encoder.setCompact(Boolean.parseBoolean(hints.get(EncodeHintType.PDF417_COMPACT).toString()));\n      }\n      if (hints.containsKey(EncodeHintType.PDF417_COMPACTION)) {\n        encoder.setCompaction(Compaction.valueOf(hints.get(EncodeHintType.PDF417_COMPACTION).toString()));\n      }\n      if (hints.containsKey(EncodeHintType.PDF417_DIMENSIONS)) {\n        Dimensions dimensions = (Dimensions) hints.get(EncodeHintType.PDF417_DIMENSIONS);\n        encoder.setDimensions(dimensions.getMaxCols(),\n                              dimensions.getMinCols(),","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/zxing/zxing/blob/19aa2d8254410e161f04dc3c928e68d5e90233c2/core/src/main/java/com/google/zxing/pdf417/PDF417Writer.java#L36-L72","documentation":"Error \"Can only encode PDF_417, but got {format}\" thrown in zxing/zxing.","triggerScenarios":"Thrown at core/src/main/java/com/google/zxing/pdf417/PDF417Writer.java:54 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call encode() with BarcodeFormat.PDF_417.","Use a different Writer implementation for the requested barcode format."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"19aa2d8254410e161f04dc3c928e68d5e90233c2","analyzedAt":"2026-08-14T03:07:53.428Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}