Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Android development and PDF
  • Page:
  • 1
  • 2

TOPIC:

Unexpected behavior when calling ImportPage() 9 years 5 months ago #7792

  • ashughes
  • ashughes's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 37
  • Thank you received: 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

Please Log in or Create an account to join the conversation.

Unexpected behavior when calling ImportPage() 9 years 5 months ago #7802

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
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();

Please Log in or Create an account to join the conversation.

Unexpected behavior when calling ImportPage() 9 years 5 months ago #7803

  • ashughes
  • ashughes's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 37
  • Thank you received: 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

Please Log in or Create an account to join the conversation.

Unexpected behavior when calling ImportPage() 9 years 5 months ago #7804

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
yes, you are right, but seems no better ideas.
all resources that page used, shall be deplicated.

Please Log in or Create an account to join the conversation.

Last edit: by .

Unexpected behavior when calling ImportPage() 9 years 5 months ago #7805

  • ashughes
  • ashughes's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 37
  • Thank you received: 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

Please Log in or Create an account to join the conversation.

Unexpected behavior when calling ImportPage() 9 years 5 months ago #7816

  • ashughes
  • ashughes's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 37
  • Thank you received: 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

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Powered by Kunena Forum