title: Mustang Library: Converting invalid PDFA3 to valid PDFA3 for building Factur-x
body: <p>I'm trying to create a facturX using Mustang Library in a webservice. This web service accept a xml string and a base64 PDF.</p>
  <p>My issue is that i have no &quot;knowledge&quot; about PDF format that is sent to me. In my service layer class, I build my facturx using ZUGFeRDExporterFromA1.</p>
  <pre><code>@Override
  public FacturxDto createFacturX(FacturxDto facturxDto) {
      context.setContext(facturxDto);
      if (facturxDto.getVersion() == null) {
          facturxDto.setVersion(2);
      }
      if(facturxDto.getPdfDocument() == null) {
          throw new AppServiceException(&quot;Pdf is required in the payload&quot;);
      }
      if(facturxDto.getXml() == null) {
          throw new AppServiceException(&quot;Xml is required in the payload&quot;);
      }
      if ((facturxDto.getVersion() &lt; 1) || (facturxDto.getVersion() &gt; 2)) {
          throw new AppServiceException(&quot;invalid version&quot;);
      }
      try {
          Utils.facturxValidator(facturxDto);
      } catch (SAXException | IOException e) {
          throw new AppServiceException(e.getMessage());
      }
  
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      log.debug(&quot;Converting to PDF/A-3u&quot;);
  
      PDFAConformanceLevel pdfaConformanceLevel = Utils.setPdfaConformanceLevel(facturxDto);
      // System.out.println(Arrays.toString(facturxDto.getPdfDocument().getBytes(StandardCharsets.UTF_8)));
      byte[] xmlData = facturxDto.getXml().getBytes(StandardCharsets.UTF_8);
      byte[] pdfData = Base64.getDecoder().decode(facturxDto.getPdfDocument().getBytes(StandardCharsets.UTF_8));
      try {
          ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1()
                  .setProducer(&quot;Mustang LIB&quot;)
                  .setCreator(&quot;ME&quot;)
                  .setProfile(facturxDto.getFxLevel())
                  .setZUGFeRDVersion(facturxDto.getVersion())
                  .setConformanceLevel(pdfaConformanceLevel)
                  .ignorePDFAErrors()
                  .load(pdfData);
  
          ze.attachFile(&quot;factur-x.xml&quot;, xmlData, &quot;text/xml&quot;, &quot;Data&quot;);
          
          ze.setXML(xmlData);
          log.debug(&quot;Attaching ZUGFeRD-Data&quot;);
          ze.disableAutoClose(true);
          ze.export(output);
          byte[] bytes = output.toByteArray();
          InputStream inputStream = new ByteArrayInputStream(bytes);
  
          byte[] pdfBytes = IOUtils.toByteArray(inputStream);
  
          String encoded = Base64.getEncoder().encodeToString(pdfBytes);
          // persist data in db and generate id
          ModelMapper modelMapper = new ModelMapper();
          modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
          FacturxEntity facturxEntity = modelMapper.map(facturxDto, FacturxEntity.class);
          facturxEntity.setStatus(RequestOperationStatus.SUCCESS.name());
          facturxEntity.setCreatedAt(new Date());
          facturxEntity.setFacturxId(Utils.generateId());
  
          FacturxEntity storedFacturx = facturxRepository.save(facturxEntity);
          FacturxDto returnValue = modelMapper.map(storedFacturx, FacturxDto.class);
          returnValue.setPdfDocument(encoded);
          return returnValue;
      } catch (IOException e) {
          e.printStackTrace();
          throw new AppServiceException(e.getMessage());
      }
  }
  </code></pre>
  <p>My issue is here :</p>
  <pre><code>ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1()
          .setProducer(&quot;Mustang LIB&quot;)
          .setCreator(&quot;ME&quot;)
          .setProfile(facturxDto.getFxLevel())
          .setZUGFeRDVersion(facturxDto.getVersion())
          .setConformanceLevel(pdfaConformanceLevel)
          .ignorePDFAErrors()
          .load(pdfData);
  </code></pre>
  <p>If i don't use ignorePDFAErrors() I do have an exception thrown.
  If i use it, my pdf is not PDFA compliant. And it's an issue.</p>
  <p>Is there a way to convert on the fly an invalid PDFA to a valid one. Thanks</p>