Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Feb 02, 2021 7:44 am

Dear support
I want to crate a pdf with PdfConformanceLevel.Pdf_A_1_A. in the pdf I've a text and a PdfTextBoxField in which I want to set a value:
Code: Select all
   private static PdfFont font = new PdfFont(PdfFontFamily.Times_Roman, 12f, EnumSet.of(PdfFontStyle.Regular));
   private static PdfSolidBrush brush = new PdfSolidBrush(new PdfRGBColor(Color.black));
   
   public static void main(String[] args) {
      pdfDocument = new PdfDocument();
      pdfDocument = new PdfDocument(PdfConformanceLevel.Pdf_A_1_A);
      pdfDocument.getFileInfo().setVersion(PdfVersion.Version_1_7);

      page = pdfDocument.getPages().add();

      baseX = 100;
      baseY = 40;
      cellXPos = baseX;
      cellYPos = baseY;

      page.getCanvas().drawString("TEXT_BOX", font, brush, new Point2D.Float(0, baseY));
      
      Rectangle2D.Float tbxBounds = new Rectangle2D.Float(baseX, baseY , 150, 30);
      PdfTextBoxField textBox;
      try {
         textBox = new PdfTextBoxField(page, "textbox");
         textBox.setBounds(tbxBounds);
         textBox.setReadOnly(true);
         textBox.setText("Hello World");
         textBox.setMultiline(false);
         textBox.setTextAlignment(PdfTextAlignment.Center);
         textBox.setFont(font);
         pdfDocument.getForm().getFields().add(textBox);
         
      } catch (Exception e) {
         System.err.println(e.getMessage());
      }
      String pdfFilePath = "d:\\test.pdf";
      pdfDocument.saveToFile(pdfFilePath);   
   }

I use spire.pdf-3.8.2.jar.

If I enable the next line, i got a NullPointerException

Code: Select all
textBox.setText("Hello World");


Code: Select all
java.lang.NullPointerException
   at com.spire.pdf.graphics.PdfCanvas.spr  (Unknown Source)
   at com.spire.pdf.graphics.PdfCanvas.spr  (Unknown Source)
   at com.spire.pdf.graphics.PdfCanvas.spr  (Unknown Source)
   at com.spire.pdf.graphics.PdfCanvas.spr  (Unknown Source)
   at com.spire.pdf.graphics.PdfCanvas.drawString(Unknown Source)
   at com.spire.pdf.graphics.PdfCanvas.drawString(Unknown Source)
   at com.spire.pdf.packages.sprpjb.spr  (Unknown Source)
   at com.spire.pdf.fields.PdfTextBoxField.spr  (Unknown Source)
   at com.spire.pdf.fields.PdfAppearanceField.spr  (Unknown Source)
   at com.spire.pdf.fields.PdfAppearanceField.spr  (Unknown Source)
   at com.spire.pdf.packages.sprUKb.spr  (Unknown Source)
   at com.spire.pdf.packages.sprRNb.spr  (Unknown Source)
   at com.spire.pdf.packages.sprZNb.spr  (Unknown Source)
   at com.spire.pdf.packages.sprZNb.spr (Unknown Source)
   at com.spire.pdf.annotations.PdfAnnotation.spr  (Unknown Source)
   at com.spire.pdf.annotations.PdfAnnotation.spr  (Unknown Source)
   at com.spire.pdf.packages.sprVmb.spr  (Unknown Source)
   at com.spire.pdf.packages.sprKga.spr  (Unknown Source)
   at com.spire.pdf.packages.sprjHa.spr  (Unknown Source)
   at com.spire.pdf.packages.sprjHa.spr  (Unknown Source)
   at com.spire.pdf.packages.sprjHa.spr  (Unknown Source)
   at com.spire.pdf.packages.sprSja.spr  (Unknown Source)
   at com.spire.pdf.packages.sprPka.spr (Unknown Source)
   at com.spire.pdf.packages.sprPka.spr  (Unknown Source)
   at com.spire.pdf.packages.sprPka.spr (Unknown Source)
   at com.spire.pdf.packages.sprPka.spr  (Unknown Source)
   at com.spire.pdf.PdfNewDocument.spr   (Unknown Source)
   at com.spire.pdf.PdfDocumentBase.save(Unknown Source)
   at com.spire.pdf.PdfDocument.saveToFile(Unknown Source)
   at PcmTest.main(PcmTest.java:69)


When I set PdfConformanceLevel.Pdf_A_2_A or PdfConformanceLevel.Pdf_A_3_A I don't get the NullPointerException.

with PdfConformanceLevel.Pdf_A_1_A I got the a notice in Pdfreader:
2021-02-02_08-14-07.png

If I want to change the content in PdfTextBoxField, I must enable the editing-mode.

With PdfConformanceLevel.Pdf_A_2_A or PdfConformanceLevel.Pdf_A_3_A I don't get this notice, the pdf is always editable.

I tried than the same with spire.pdf-3.11.6.jar and the lastest jar...
If I set PdfConformanceLevel.Pdf_A_1_A and create the pdf, I don't get the notice above. Editing is than automatically enabled whith this. The same for PdfConformanceLevel.Pdf_A_2_A or PdfConformanceLevel.Pdf_A_3_A.

I need now to create a pdf with PdfConformanceLevel.Pdf_A_3_A, which had text in textField and no NullPointerException has been fired during creation of PDF. The notice above must be showd, as soon the user open the document.

Can you please investigate this issues?

Best Regards

EP

ep_pfa_12
 
Posts: 6
Joined: Thu Nov 12, 2020 9:49 am

Tue Feb 02, 2021 10:09 am

Hello,

Thanks for your inquiry.

Regarding creating PDF/A files, our Spire.PDF provides a new API(PdfStandardsConverter) to convert normal PDF to PDF/A files, which has better performance than the old method. Below is the corresping code. Please download the latest Spire.PDF for Java Version:4.1.2 to test it.
Code: Select all
    private static PdfFont font = new PdfFont(PdfFontFamily.Times_Roman, 12f, EnumSet.of(PdfFontStyle.Regular));
    private static PdfSolidBrush brush = new PdfSolidBrush(new PdfRGBColor(Color.black));

    public static void main(String[] args) {
        PdfDocument pdfDocument = new PdfDocument();
        pdfDocument.getFileInfo().setVersion(PdfVersion.Version_1_7);
        PdfPageBase page = pdfDocument.getPages().add();
        page.getCanvas().drawString("TEXT_BOX", font, brush, new Point2D.Float(0, 50));
        Rectangle2D.Float tbxBounds = new Rectangle2D.Float(50, 50 , 150, 30);
        PdfTextBoxField textBox;
        try {
            textBox = new PdfTextBoxField(page, "textbox");
            textBox.setBounds(tbxBounds);
            textBox.setReadOnly(true);
            textBox.setText("Hello World");
            textBox.setMultiline(false);
            textBox.setTextAlignment(PdfTextAlignment.Center);
            textBox.setFont(font);
            pdfDocument.getForm().getFields().add(textBox);

        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
        String pdfFilePath = "PDF.pdf";
        pdfDocument.saveToFile(pdfFilePath);
        PdfStandardsConverter pdfStandardsConverter = new PdfStandardsConverter(pdfFilePath);
        pdfStandardsConverter.toPdfA3A("PDFA3A.pdf");
    }

If there are any questions, just feel free to contact us.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Sun Feb 07, 2021 8:44 am

Hello,

Greetings from E-iceblue!
Did the code we provided work for you? Any feedback will be greatly appreciated.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.PDF