We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Migration issues aspose.pdf (IsBookmarked, DestinationType, OpenType, CompressionLevel, Conformance)

Dear Support Team,

I need help on migrating from Aspose.PDF 11.7.0.0 to 21.12.0.0.

I am having problems mapping the following previous settings to the new functionality.

Please tell me the replacements for the following functionality:

Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();

pdf.CompressionLevel = 1; /* 0-9 */
pdf.Conformance = Aspose.Pdf.Generator.PdfConformance.None;
pdf.DestinationType = Aspose.Pdf.Generator.DestinationType.Retain;
pdf.IsBookmarked = true;
pdf.OpenType = Aspose.Pdf.Generator.OpenType.Auto;

I couldn’t find any documentation how to do it now.

@eandres

The old Aspose.Pdf.Generator approach has been discontinued since long time and its documentation material was also removed gradually from official API documentation. It would take us some time to find what was the actual function these properties used to perform back then. However, we can suggest you right thing if you can explain a little more about your original requirements. Do you want to compress PDF document? Convert it to PDF/A format or working with bookmarks?

hi @asad.ali,

thx for our time.

We fully integrated the Aspose.PDF dll in our software.
The listed parameters were configurable via server settings

I’ll provide all information I have, but in some cases it’s really hard to get any hints on the effect in the generated PDF.

        Aspose.Pdf.Generator.Pdf generator = new Aspose.Pdf.Generator.Pdf();
        Aspose.Pdf.Document document = new Aspose.Pdf.Document();

property ‘CompressionLevel’

also our the documentation is very poor.

  • possible values are integer from 0-9 as a ratio
  • our default configuration was 6
  • I think, it was something in the direction of (similar to some zip tools):
    – 0 means no compression --> fast conversion
    – 9 means maximum compression --> slow conversion

Question: it there somewhere a article about PDF Compression in Common? Or Just something with ImageCompression and so on?

        generator.CompressionLevel = 0;

property ‘Conformance’

possible values are:

         public enum PdfConformance
         {
            None = 0,
            PdfA1B = 1,
            PdfA1A = 2
         }

Depending the conformance, i found this article https://docs.aspose.com/pdf/net/convert-pdf-to-pdfa/

I think this is enough for me :wink: #noHelpRequired

property ‘DestinationType’

The first page of the PDF document is opened in the variants

  • FitBox,
  • FitHeight,
  • FitPage,
  • FitWidth,
  • Retain.

to replace the code ‘generator.DestinationType = Serversettings.PDF_Destination_type’

I implemented the following functionality, but i do not know whether the implementation is correct

        // DestinationType
        int destination_type = Serversettings.PDF_Destination_type;
        Aspose.Pdf.Annotations.IAppointment open_action = null;
        switch (destination_type)
        {
            case 1: // FitPage
                open_action = new Aspose.Pdf.Annotations.FitExplicitDestination(document.Pages[1]);
                break;
            case 2: // FitWidth
                open_action = new Aspose.Pdf.Annotations.FitHExplicitDestination(document.Pages[1], 0);
                break;
            case 3: // FitHeight
                open_action = new Aspose.Pdf.Annotations.FitVExplicitDestination(document.Pages[1], 0);
                break;
            case 4: // FitBox
                open_action = new Aspose.Pdf.Annotations.FitBExplicitDestination(document.Pages[1]);
                break;
            default:
                open_action = null;
                break;
        }
        document.OpenAction = open_action;

property ‘IsBookmarked’

I think this was a global flag to disable Bookmarks in common

since there are BookmarkLevel properties on documenttypes where it is possible to have Bookmarks, we’ll remove this setting

I think this is enough for me :wink: #noHelpRequired

        generator.IsBookmarked = true;

property ‘OpenType’

In the PDF document, you can set how the plug-in that displays the PDF document should
preferably open (Auto, Bookmarks, Fullscreen, None, Thumbnails).

could it be that this is replaced with document.PageMode ?

    generator.OpenType = Aspose.Pdf.Generator.OpenType.Auto;

@eandres

Thanks for the feedback. Please try to check the below help articles in API documentation related to Compression/optimization, OpenAction and Page Properties:

Hi @asad.ali,

I need help with that code. I just find sample code how to set the OpenAction to NULL, but not how to assign a specific openaction.
The code above produces a NullReferenceExecption in the set_OpenAction property.
I already checked whether document/ page[1]/ or the assigned openaction is null, but all are not NULL.

Could you please give me a hint what i need to do to set a openaction?

and a additonal Question depending PageMode. How can I test that the setting i set in PageMode works?

I can toggle PageMode like I want and on opening the document, it’s always the same like before. I tested with chrome pdf view, microsoft edge pdf view and adobe pdf viewer.

@eandres

You can specify and set the open action using below sample code snippets:

Document doc = new Document(dataDir + "input.pdf");

GoToAction action = new GoToAction(new XYZExplicitDestination(1, 0, 0, 0));
doc.OpenAction = action;

OR if you need to execute some JavaScript on OpenAction:

Document doc = new Document(dataDir + "Sample.pdf");
doc.OpenAction = new JavascriptAction("this.print({bUI: false, bSilent: true, bShrinkToFit: true});");

Regarding the PageMode, below code snippet can be used to set it:

Document doc = new Document(dataDir + "testSample.pdf");
doc.PageMode = PageMode.UseNone;

Can you please share the sample PDF for which you are setting the PageMode and its not working? We will test it in our environment and share our feedback with you.