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 Nov 17, 2020 9:25 am

I want add multiple PdfTextBoxFields and PdfPopupAnnotation into one row, but as soon i append the PdfPopupAnnotation-elements into the page, all PdfTextBoxFields are disaperd.
This is what I want:
2020-11-17_10-09-14.png

But what I get is this:
2020-11-17_10-26-34.png

Can you please explain me, what I'm dooing wrong?
Here is my complete code.
Code: Select all
import java.awt.Dimension;
import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfPageBase;
import com.spire.pdf.PdfPageOrientation;
import com.spire.pdf.PdfPageSettings;
import com.spire.pdf.PdfPageSize;
import com.spire.pdf.PdfVersion;
import com.spire.pdf.annotations.PdfAnnotationFlags;
import com.spire.pdf.annotations.PdfPopupAnnotation;
import com.spire.pdf.annotations.PdfPopupIcon;
import com.spire.pdf.fields.PdfBorderStyle;
import com.spire.pdf.fields.PdfHighlightMode;
import com.spire.pdf.fields.PdfTextBoxField;
import com.spire.pdf.graphics.PdfFont;
import com.spire.pdf.graphics.PdfFontBase;
import com.spire.pdf.graphics.PdfFontFamily;
import com.spire.pdf.graphics.PdfFontStyle;
import com.spire.pdf.graphics.PdfMargins;
import com.spire.pdf.graphics.PdfRGBColor;
import com.spire.pdf.graphics.PdfTextAlignment;


public class MyPdfTest {

   private PdfPageBase page;
   private PdfDocument pdfDocument;
   private PdfFontBase font = new PdfFont(PdfFontFamily.Times_Roman, 12, PdfFontStyle.Bold);
   

   public void test() {
      pdfDocument = new PdfDocument();
      pdfDocument.getFileInfo().setVersion(PdfVersion.Version_1_7);
      Dimension2D pageSize = new Dimension((int)PdfPageSize.A4.getHeight(), (int)PdfPageSize.A4.getWidth());   
      PdfPageSettings pageSettings = new PdfPageSettings(pageSize, PdfPageOrientation.Landscape);

      pdfDocument.setPageSettings(pageSettings);
      PdfMargins pageMargins = new PdfMargins();
      pageMargins.setLeft(20);
      pageMargins.setTop(40);
      pageMargins.setRight(20);
      pageMargins.setBottom(0);
      
      page = pdfDocument.getPages().add(pageSize, pageMargins);
      
      int rows = 3;
      int cellYPos = 0;
      for (int row = 0; row < rows; row++) {
         
         createTextField(40, cellYPos, "key#" + row + "#0", "Field#" + row + "#1");
         createTextAnnotation(140, cellYPos, "key#" + row + "#1", "Text#" + row + "#1");
         createInofAnnotation(200, cellYPos, "key#" + row + "#2", "Info#" + row + "#2");
         cellYPos += 60;
      }

      pdfDocument.saveToFile("d:\\test.pdf");
   }
   
   private void createTextField(int cellXPos, int cellYPos, String key, String content) {
      PdfTextBoxField pdfTextBoxField;
      try {
         pdfTextBoxField = new PdfTextBoxField(page, key);
         Rectangle2D rectangle = new Rectangle2D.Float();
         rectangle.setFrame(cellXPos, cellYPos, 100, 40);
         PdfRGBColor color = new PdfRGBColor(255,0,0);   
         pdfTextBoxField.setBounds(rectangle);
         pdfTextBoxField.setBorderWidth(0.0f);
         pdfTextBoxField.setBorderColor(color);
         pdfTextBoxField.setFont(font);
         pdfTextBoxField.setText(content);
         pdfTextBoxField.setMultiline(false);
         pdfTextBoxField.setInsertSpaces(false);
         pdfTextBoxField.setHighlightMode(PdfHighlightMode.Push);
         pdfTextBoxField.setTextAlignment(PdfTextAlignment.Center);
         pdfTextBoxField.setBorderStyle(PdfBorderStyle.Solid);
         pdfDocument.getForm().getFields().add(pdfTextBoxField);   
      } catch (Exception e) {
         System.err.println(e.getMessage());
      }
   }
   
   private void createTextAnnotation(int cellXPos, int cellYPos, String key, String content) {
      try {   
         PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation();
         popupAnnotation.setIcon(PdfPopupIcon.Note);
         Point2D point = new Point2D.Float();
         point.setLocation(cellXPos, cellYPos+2);
         popupAnnotation.setLocation(point);
         popupAnnotation.setName(key);
         popupAnnotation.setText(content);
         popupAnnotation.setFlags(PdfAnnotationFlags.Locked);
         page.getAnnotationsWidget().add(popupAnnotation);         
      } catch (Exception e) {
         System.err.println(e.getMessage());
      }
   }
   
   private void createInofAnnotation(int cellXPos, int cellYPos, String key, String content) {
      try {   
         PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation();
         popupAnnotation.setIcon(PdfPopupIcon.Comment);
         Point2D point = new Point2D.Float();
         point.setLocation(cellXPos, cellYPos+2);
         popupAnnotation.setLocation(point);
         popupAnnotation.setName(key);
         popupAnnotation.setText(content);
         popupAnnotation.setFlags(PdfAnnotationFlags.Locked);
         page.getAnnotationsWidget().add(popupAnnotation);         
      } catch (Exception e) {
         System.err.println(e.getMessage());
      }
   }
}

Thank you four your help.

rgds
ep

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

Tue Nov 17, 2020 11:07 am

Hello,

Thanks for your inquiry.
I did an initial test and did reproduce your issue. I have posted this issue to our Dev team with the ticket SPIREPDF-3785. If there is any update, we will let you know.

Sincerely,
Brian
E-iceblue support team
User avatar

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

Wed Nov 18, 2020 3:00 am

Hello,

This is to inform you the update about the issue SPIREPDF-3875.
After further investigation by our Dev team, it is found that you should use the following code to add the PDF annotation. Please modify your code accordingly. If you have further questions, just feel free to contact us.
Code: Select all
            //...
            //page.getAnnotationsWidget().add(popupAnnotation);
            ((PdfNewPage) page).getAnnotations().add(popupAnnotation);
            //...


Sincerely,
Brian
E-iceblue support team
User avatar

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

Thu Nov 19, 2020 10:10 am

Thank you for your investigation. The Soulution which you wrote works godd. Thank you very much.

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

Fri Nov 20, 2020 3:56 am

You are welcome.
If you encounter any issues related to our products in the future, please feel free to contact us.
Wish you all the best!

Sincerely,
Brian
E-iceblue support team
User avatar

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

Return to Spire.PDF