Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when adding svg image to pdf: RangeError (length): Invalid value: Not in inclusive range 0..11399: 11403 #1807

Open
JKazimiers opened this issue Jan 15, 2025 · 0 comments
Labels
needs triage support Asking for help writing an application

Comments

@JKazimiers
Copy link

Hi, in my app I am trying to print an SVG. But when I build the page with my SVG I get the error: RangeError (length): Invalid value: Not in inclusive range 0..11399: 11403. I can't find another way to print the svg.

Smaller SVGs work, so I guess there is a size limit for the SVG in SvgImage or in the page renderer. Why is that there, and is it possible to change this limit?

import 'package:printing/printing.dart';
import 'package:pdf/widgets.dart' as pw;

printSvg(String svgString, double width, double height) async {
    try {
      final svgImage = pw.SvgImage(
        svg: svgTestString, //svgString,
      );
      final pdf = pw.Document();
      pdf.addPage(pw.Page(
        build: (context) {
          return pw.SvgImage(svg: svgString);
        },
      ));
      Printing.layoutPdf(
        onLayout: (format) {
          return pdf.save();
        },
      );
    } catch (e) {
      print("Error while printing SVG: $e");
    }
  }

  String svgTestString =
      '<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'
      '<svg width="210mm" height="297mm" viewBox="0 0 210 297" style="background-color: #ffffffff;" xmlns="http://www.w3.org/2000/svg">'
      '<text x="126" y="215" style="fill: #000000ff; font-size: 12px; font-weight: 400;">Event Layout</text>'
      '<text x="51" y="52" style="fill: #000000ff; font-size: 12px; font-weight: 400;">Test</text>'
      '<text x="5" y="53" style="fill: #000000ff; font-size: 12px; font-weight: 400;">Event:</text>'
      '<text x="51" y="33" style="fill: #000000ff; font-size: 12px; font-weight: 400;">Test</text>'
      '<text x="6" y="34" style="fill: #000000ff; font-size: 12px; font-weight: 400;">Serie:</text>'
      '<image href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEsAQMAAABDsxw2AAAABlBMVEX///8AAABVwtN+AAABiklEQVR42uyZPXKsMBCER0VAyBF0FB2NPZqOwhEUEqiYV/MDb/Ea2yC85aA7YUv6Igl6emYJgiAI+tPq2VQoMD8olr4S+RoDa8aqPmLpmGnMsVC3EGdZC8BuwAIzy7beAg3MgkXmCuxOTJTYbwHYzVi3KMYzEbAbMfcQUmeeBsMOrQbYOWytgPJuP9I0zPLjuFACO4X9l1h0mr5NcsB+AROrsfyhT7m9xb4N9R5gjZi885I/JDw/dNu+g/m1SQF2GiMvkMUcRqzGLKbfWw2wBmyti0nOfyFgt2Kjx7wxkxZKuRUPKMDaMGtOJu1NONPA9bOYB+wapoc9bi22D4gcB9aKrR4yVA8Ya6vd73pAYNcwm2bmaIeeprVrKT0vBKwV21v1th157oC1Y7vhvOQ3H29qTAb2LmybI+1iXvyQQ4BdxZ6moBbz/FZeOnFgDZhOQbf8EV8MH1gTZocueLBC+cWoH9jPsecZfvaKmQ7/ngZ2Dttm+LKq0+NglbAGYM0YBEEQ9Fb9CwAA///7IOAPsOGt9gAAAABJRU5ErkJggg==" x="146" y="233" width="50" height="50" />'
      '<text x="52" y="93" style="fill: #000000ff; font-size: 12px; font-weight: 400;">Test</text>'
      '<text x="5" y="92" style="fill: #000000ff; font-size: 12px; font-weight: 400;">Preis:</text>'
      '<text x="52" y="73" style="fill: #000000ff; font-size: 12px; font-weight: 400;">Test</text>'
      '<text x="5" y="73" style="fill: #000000ff; font-size: 12px; font-weight: 400;">Section:</text>'
      '<text x="6" y="138" style="fill: #000000ff; font-size: 12px; font-weight: 400;">Test</text>'
      '</svg>';
@JKazimiers JKazimiers added needs triage support Asking for help writing an application labels Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage support Asking for help writing an application
Projects
None yet
Development

No branches or pull requests

1 participant