Microsoft Windows Phone 8.1 support ends (13 Jul 2017)

Microsoft has ended support for Windows Phone 8.1

Questions about Android development and PDF

Unexpected behavior when calling ImportPage()

More
IP: 192.168.0.71 11 years 5 months ago #7792 by ashughes
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:
Code:
// ...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
More
IP: 192.168.0.71 11 years 5 months ago #7802 by radaee
you can use like these codes to avoid some issue:
Code:
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();
More
IP: 192.168.0.71 11 years 5 months ago #7803 by ashughes
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
More
IP: 192.168.0.71 11 years 5 months ago - 11 years 5 months ago #7804 by radaee
yes, you are right, but seems no better ideas.
all resources that page used, shall be deplicated.
Last edit: 11 years 5 months ago by .
More
IP: 192.168.0.71 11 years 5 months ago #7805 by ashughes
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
More
IP: 192.168.0.71 11 years 5 months ago #7816 by ashughes
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:
Code:
ImportStart( Document src, boolean importResources )

or
Code:
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:
Code:
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
Time to create page: 0.513 seconds
Powered by Kunena Forum