No announcement yet.

Render XFA document with barcode and dynamic number of pages

  • Filter
  • Time
  • Show
Clear All
new posts

  • Render XFA document with barcode and dynamic number of pages


    We are thinking about using Foxit PDF SDK for rendering pdf documents in our project. Everything is looking fine except few problems with barcodes and shifted form fields in documents with dynamic number of pages.

    I have used following code for rendering images:

    using (var doc = new PDFDoc(sourcePath))
      if (doc.Load(null) != ErrorCode.e_ErrSuccess)
        throw new Exception();
      var image = new foxit.common.Image();
      using (var xfaDoc = new XFADoc(doc))
        xfaDoc.ProcessEvent(XFADoc.EventType.e_EventTypePr ePrint);
        // Get page count
        var pageCount = xfaDoc.GetPageCount();
        for (var i = 0; i < pageCount; i++)
          using (var page = xfaDoc.GetPage(i))
            var width = (int) page.GetWidth() / 72 * 300;
            var height = (int) page.GetHeight() / 72 * 300;
            var matrix = page.GetDisplayMatrix(0, 0, width, height, 0);
            // Prepare a bitmap for rendering.
            var bitmap = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb );
            using (var draw = Graphics.FromImage(bitmap))
              // Render page
              var render = new Renderer(bitmap, true);
              render.StartRenderXFAPage(page, matrix, true, null);
    Both documents are created by us and are using XFA under the hood.

    1) Missing barcode

    Attachement Barcode_source.pdf is source file.
    Attachement Barcode_states.docx - Actual state displays state for when I print given source file from Adobe Acrobat via virtual printer.
    Attachement Barcode_states.docx - Target state displays state for when I print given source with Foxit SDK via code above. Everything is looking fine except missing barcode in left lower corner.

    2) Shifted form fields

    Attachements are same as problem above, but instead of "Barcode" they start with "Multipage".
    Problem here is that first page seems to be rendered fine, but second page has shifted fields up. This problem persists for when there are more than 2 pages.

    Is there any way to render both documents as their "Target state" alternatives?

    Attached Files

  • #2
    Thanks for your post.For SDK related questions,please help to write your query to [email protected] or submit a ticket from our online support ticket submit system below:

    And then our SDK department technical support will get in touch with you.