Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Hyperlink missing when export to PDF with JavaScript

New Here ,
Oct 07, 2021 Oct 07, 2021

Hi, I have a InDesign file which contains hyperlinks. I'm using InDesign CC server with JavaScript to convert this indd file to pdf file:

app.pdfExportPreferences.includeHyperlinks = true;
var myPDFexportPreset = app.pdfExportPresets.item("[Press Quality]");
// myPDFexportPreset.includeHyperlinks = true;
app.documents.item(0).exportFile(ExportFormat.pdfType, myFile, myPDFexportPreset);

this gives me a pdf without hyperlinks. If I add "myPDFexportPreset.includeHyperlinks = true" it gives an error "Error number: 35852" and will not generate the pdf.

Could anyone please to take a look?

TOPICS
Import and export , Print , Scripting , SDK
687
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 07, 2021 Oct 07, 2021

Yes, it would copy those prefs over. And yes it would be slower. If you don't want to copy the prefs, just hardcode them into the export preferences instead of the for loop, like Mike suggested. Using hyperlinks goes against certain PDF export standards which is probably why you were getting the error in the first place. 

Translate
Community Expert ,
Oct 07, 2021 Oct 07, 2021

Could you try exporting as interactive pdf? It uses a different preference object. Here's an example showing most of the properties:

function setInteractivePDFExportPreferences () {
    with (app.interactivePDFExportPreferences) {
        exportAsSinglePages = false;
        exportLayers = false;
        exportReaderSpreads = false;
        flipPages = false;
        generateThumbnails = false;
        includeStructure = false;
        interactivePDFInteractiveElementsOption = InteractivePDFInteractiveElementsOptions.INCLUDE_ALL_MEDIA;
        openInFullScreen = false;
        pageRange = PageRange.ALL_PAGES;
        pageTransitionOverride = PageTransitionOverrideOptions.NONE;
        pdfDisplayTitle = PdfDisplayTitleOptions.DISPLAY_FILE_NAME;
        pdfJPEGQuality = Populator.settings.pdfExportSettings.quality;
        pdfMagnification = PdfMagnificationOptions.FIT_PAGE;
        pdfPageLayout = PageLayoutOptions.SINGLE_PAGE;
        pdfRasterCompression = PDFRasterCompressionOptions.JPEG_COMPRESSION;
        rasterResolution = Populator.settings.pdfExportSettings.dpi;
        viewPDF = false;
    }
}

 See InteractivePDFExportPreference.

- Mark

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 07, 2021 Oct 07, 2021

You need to copy the preset preferences to the pdf preferences, add add hyperlink, then print without preset. Or just make and load your own correct preset, not Press Quality, and call that. 

 

On mobile but the algorithm is essentially: 

for p in preset

try { exportPrefs[p] = preset[p] } 

catch(e) {}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 07, 2021 Oct 07, 2021

Thanks! How should I copy the preset preferences to the pdf preferences?

Can I use provided preset like [Smallest File Size]? I am using this preset for now,  and hope to continue using it so the resolution is not changed. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 07, 2021 Oct 07, 2021

Sure yeah. Like I said, 

for (var p in preset) {

       try { prefs[p] = preset[p] }

       catch(e) {}

 

Then just don't call a preset on export. And add your hyperlink line. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 07, 2021 Oct 07, 2021

It worked with this:

        var myPDFexportPreset = app.pdfExportPresets.item("[Smallest File Size]");
        for (var p in myPDFexportPreset) {
                try {app.pdfExportPreferences[p] = myPDFexportPreset[p];}
                catch(e) {}
        }
        app.pdfExportPreferences.includeHyperlinks = true;
        app.documents.item(0).exportFile(ExportFormat.pdfType, myFile);

Does it mean the output still has the same settings/resolutions as before with "[Smallest File Size]"?

This script seems to be slower than before after I added this forloop. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 07, 2021 Oct 07, 2021
LATEST

Yes, it would copy those prefs over. And yes it would be slower. If you don't want to copy the prefs, just hardcode them into the export preferences instead of the for loop, like Mike suggested. Using hyperlinks goes against certain PDF export standards which is probably why you were getting the error in the first place. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines