Set default open options for new PDF

I am creating a new pdf from a collection of existing files and setting the bookmarks on the new file using the Outlines collection on a pdf.Document object.


I want to make sure that the resulting PDF file will always open at the first page with the bookmarks list shown. I would also like the first top level bookmark to be expanded.

I can find some posts in this forum about setting up the document this way, but I wondered if there was a way to do this using the pdf.document object that I already have open ?

Thanks
Fiona Treveil

Hi Fiona,

Thanks for your inquiry. You can pass your Document object to PdfContentEditor to set viewer preference of the PDF document. Please check following code snippet and Set Viewer Preference of PDF section of documentation for the purpose. Hopefully it will help you to accomplish your requirement.

Document pdfDoc = new Document();

Page pdfPage=pdfDoc.Pages.Add();

//pass your pdfDoc to PdfContentEdiot object to set preview preference
PdfContentEditor contentEditor = new PdfContentEditor(pdfDoc);

//change Viewer Preferences
contentEditor.ChangeViewerPreference(ViewerPreference.PageModeUseOutlines);
contentEditor.ChangeViewerPreference(ViewerPreference.HideMenubar);

contentEditor.Save(myDir+"testpdf.pdf");

Please feel free to contact us for any further assistance.

Best Regards,

Thanks for this quick response. This is working well now.

Can you tell me if there is a way to set the document settings so that it will always open from page 1 ?

Thanks
Fiona
Hi Fiona,

Thanks for your inquiry. Please check following code snippet to set OpenAction of PDF document to open it on specific page. Hopefully it will help you to accomplish your requirements.


// instantiate new Document object
Document doc = new Document("input.pdf");
GoToAction action = new GoToAction();
action.Destination = new XYZExplicitDestination(doc.Pages[1], 0, 0, 0);
doc.OpenAction = action;
doc.Save("output.pdf");


Please feel free to contact us for any further assistance.

Best Regards,

Thank you for your earlier help in this. I have now been asked if, in addition to defaulting the pdf that I have created to opening with the bookmarks tab showing, I can also have all of the bookmarks expanded to at least the second level.


Is is possible to define which bookmarks are expanded ?

Thanks
Fiona
fiona.treveil:
Thank you for your earlier help in this. I have now been asked if, in addition to defaulting the pdf that I have created to opening with the bookmarks tab showing, I can also have all of the bookmarks expanded to at least the second level.

Is is possible to define which bookmarks are expanded ?
Hi Fiona,

Thanks for contacting support.

I am afraid currently Aspose.Pdf for .NET does not support the feature to specify the level to which bookmarks can be displayed. However for the sake of implementation, I have logged this requirement as PDFNEWNET-36335 in our issue tracking system. We will further look into the details of this requirement and will keep you updated on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

Sorry if I’m waking up a zombie thread… but has this been implemented in the last 4 years? Is it possible to tell a PDF it should open with bookmarks up to level x expanded now? I don’t find something directly in the API…

Thank you!

@Docbyte

Thanks for contacting support.

I am afraid that earlier logged requirement could not get implemented due to other high priority issues in the queue. However, we have recorded your concerns and escalate the ticket to next level. As soon as we have some definite updates regarding its implementation, we will let you know.

We are sorry for the inconvenience.

OK, thanks for the reply. Is there any way we could get this expedited or at least get a ballpark estimate of when it might be implemented?

Thank you! :slight_smile:

@Docbyte

Thanks for writing to us.

Since, the issue has been logged under free support model, it will be investigated and resolved on first come first serve basis. We are afraid that we cannot share any reliable ETA at the moment because of long queue of pending issues under same model. Furthermore, you may please check our paid support model where issues get resolved on urgent basis and have priority over the issues logged under free support model.

OK, many thanks for the reply. We will look into the exact requirements and raise a paid support ticket as appropriate.

@Docbyte

Sure, please take your time to extract exact requirements from your scenario and raise the ticket in paid support. Your concerns would definitely be taken care of.

I’m guessing I was talking to the PDF Library expert and not the Words Library expert! :wink:

Isn’t is as easy as (with a com.aspose.words.PDFSaveOptions)

saveOptions.getOutlineOptions().setExpandedOutlineLevels(bookmarkOpenLevel);

… if you’re converting from Word to PDF first, which is what we’re doing. Kind of surprised no-one thought to mention that…

@Docbyte

Thanks for your feedback.

Your understanding are correct.

You did not mention in your earlier posts that you were generating PDF document from Word files using Aspose.Words which was why I regret, we did not handle the inquiry with Aspose.Words perspective. However, your suggestions would definitely help others facing similar issue. In case of any assistance, please feel free to let us know.