RadaeePDF.com :: Topic: Unexpected behavior when calling ImportPage() (1/2)
Welcome, Guest
Username: Password: Remember me

Signin/Signup with:

Questions about Android development and PDF
  • Page:
  • 1
  • 2

TOPIC: Unexpected behavior when calling ImportPage()

Unexpected behavior when calling ImportPage() 3 years 1 day ago #7792

  • ashughes
  • ashughes's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 31
  • Karma: 1
I'm getting unexpected behavior when calling ImportPage() multiple times with the same source page to different destination pages.

For example, when doing the following:
// ...open originalPdf and create newPdf...

ImportContext context = newPdf.ImportStart(originalPdf);
newPdf.ImportPage(context, 0, 0);
newPdf.ImportPage(context, 0, 1);
newPdf.ImportPage(context, 0, 2);

Page page = newPdf.GetPage(0);
// ...add content to page...
page.Close();

context.Destroy();
newPdf.Save();
newPdf.Close();
originalPdf.Close();

The resulting PDF has the content that was added just to page 0 on pages 1 and 2 as well.

I understand that this might be intended behavior for some (to have multiple pages in a PDF reference the same backing data), however I want to import this page multiple times and then have each of these pages be individual pages with separate content after they've been imported.

One option is to add a boolean flag to ImportPage() where you can specify if you want the page to be duplicated or not (e.g. ImportPage( ImportContext ctx, int srcno, int dstno, boolean duplicate )).

Other ideas?

Thanks,
Andrew
The administrator has disabled public write access.

Unexpected behavior when calling ImportPage() 2 years 11 months ago #7802

  • radaee
  • radaee's Avatar
  • OFFLINE
  • Moderator
  • Posts: 825
  • Thank you received: 10
  • Karma: 43
you can use like these codes to avoid some issue:
ImportContext context = newPdf.ImportStart(originalPdf);
newPdf.ImportPage(context, 0, 0);
context.Destroy();
ImportContext context = newPdf.ImportStart(originalPdf);
newPdf.ImportPage(context, 0, 1);
context.Destroy();
ImportContext context = newPdf.ImportStart(originalPdf);
newPdf.ImportPage(context, 0, 2);
context.Destroy();
The administrator has disabled public write access.

Unexpected behavior when calling ImportPage() 2 years 11 months ago #7803

  • ashughes
  • ashughes's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 31
  • Karma: 1
Actually I have tried that, but I ran into a different issue:

The resulting PDF (newPdf) becomes very large. It seems to be that the "context" of the original PDF is added to newPdf multiple times (each time ImportStart() is called). I'm guessing this includes things like embedded fonts, but I'm not sure what else.

Thanks,
Andrew
The administrator has disabled public write access.

Unexpected behavior when calling ImportPage() 2 years 11 months ago #7804

  • radaee
  • radaee's Avatar
  • OFFLINE
  • Moderator
  • Posts: 825
  • Thank you received: 10
  • Karma: 43
yes, you are right, but seems no better ideas.
all resources that page used, shall be deplicated.
Last Edit: 2 years 11 months ago by .
The administrator has disabled public write access.

Unexpected behavior when calling ImportPage() 2 years 11 months ago #7805

  • ashughes
  • ashughes's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 31
  • Karma: 1
Can the behavior of ImportStart() be fixed so that it can detect if the resources for the imported page have already been added to the PDF that's being imported into, and not add them? Or in some way not duplicate the resources?

Thanks,
Andrew
The administrator has disabled public write access.

Unexpected behavior when calling ImportPage() 2 years 11 months ago #7816

  • ashughes
  • ashughes's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 31
  • Karma: 1
Or even if you added a boolean parameter to ImportStart() or ImportPage() (I'm not sure which one would be the most appropriate) that specifies whether or not the resources should be included, then the caller can just keep track if the note has already been imported from. For example:
ImportStart( Document src, boolean importResources )

or
ImportPage( ImportContext ctx, int srcno, int dstno, boolean importResources )

If true is passed in, the behavior would be the same as the current behavior. If false is passed in, then the resources would not be copied to the destination PDF. Ideally, it could just be detected if the resources already have been imported/copied and the boolean parameter would not be needed.


Alternatively, ImportPage() could take a boolean parameter to specify if the page should be referenced or copied. For example:
ImportPage( ImportContext ctx, int srcno, int dstno, boolean copyPage )

If false is passed in, the behavior would be the same as the current behavior. If true is passed in, then in the event that the page has already been imported into the destination PDF, a copy of the imported page would be made in the destination PDF rather than only a reference to the same page.

Thanks,
Andrew
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Powered by Kunena Forum