fix: [pdf] export has both simple and square format

master
Unknown 2019-02-23 20:45:08 +01:00
parent ffbe46b139
commit f108336f34
17 changed files with 62 additions and 26 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -10,8 +10,9 @@ createsvg() {
output_pdf=$(echo "$pdf" | sed 's/...//' | sed 's/\.ai/.pdf/') output_pdf=$(echo "$pdf" | sed 's/...//' | sed 's/\.ai/.pdf/')
echo "Convert AI to SVG $output ..." echo "Convert AI to SVG $output ..."
inkscape --export-text-to-path -f "$d" -l "../$output" inkscape --export-text-to-path -f "$d" -l "../$output"
echo "Convert AI to PDF $output_pdf ..." # PDF export is handled by Illustrator export as Inkscape does not recognize the two artboards/pages in CLI mode
inkscape --export-text-to-path -f "$d" -A "../$output_pdf" # echo "Convert AI to PDF $output_pdf ..."
# inkscape --export-text-to-path -f "$d" -A "../$output_pdf"
done done
} }

View File

@ -31,14 +31,17 @@ if ( sourceFolder != null )
var fileName = sourceDoc.name; var fileName = sourceDoc.name;
var targetFileBase = fileName.split('.').slice(0, -1).join('.'); var targetFileBase = fileName.split('.').slice(0, -1).join('.');
// export all sizes as square // export all sizes as square
//hideLayer('color'); setActiveArtboardByName('square', sourceDoc); // choose the right artboard
//showLayer('background');
//alert(" Processing " + targetFileBase);
exportPNGFiles('square', sourceDoc, targetFileBase); exportPNGFiles('square', sourceDoc, targetFileBase);
// FIXME exportSVGFile('square', sourceDoc, targetFileBase);
// export all sizes as simple // export all sizes as simple
//hideLayer('background'); setActiveArtboardByName('simple', sourceDoc); // choose the right artboard
//showLayer('color');
exportPNGFiles('simple', sourceDoc, targetFileBase); exportPNGFiles('simple', sourceDoc, targetFileBase);
// FIXME exportSVGFile('simple', sourceDoc, targetFileBase);
// PDF export has each artboard in a separate page
exportPDFFile(sourceDoc, targetFileBase);
// close without saving // close without saving
sourceDoc.close(SaveOptions.DONOTSAVECHANGES); sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
} }
@ -61,18 +64,65 @@ function setActiveArtboardByName(artboardName, sourceDoc) {
function exportPNGFiles(targetType, sourceDoc, targetFileBase) { function exportPNGFiles(targetType, sourceDoc, targetFileBase) {
var targetFileExt = 'png'; var targetFileExt = 'png';
setActiveArtboardByName(targetType, sourceDoc); // choose the right artboard
for ( i = 0; i < pngSizes.length; i++) { for ( i = 0; i < pngSizes.length; i++) {
targetFileSize = pngSizes[i]; targetSize = pngSizes[i];
var targetFolder = targetBasePath + '/' + targetType + '_' + targetFileExt + '/' + targetFileSize; var targetFolder = targetBasePath + '/' + targetType + '_' + targetFileExt + '/' + targetSize;
new Folder(targetFolder).create(); new Folder(targetFolder).create();
var targetFullFilename = targetFolder + '/' + targetFileBase + '.' + targetFileExt; var targetFullFilename = targetFolder + '/' + targetFileBase + '.' + targetFileExt;
var targetFile = new File(targetFullFilename); var targetFile = new File(targetFullFilename);
sourceDoc.exportFile(targetFile, ExportType.PNG24, getPNGOptions(targetFileSize, sourceDoc)); var artboardRect = sourceDoc.artboards[sourceDoc.artboards.getActiveArtboardIndex()].artboardRect;
var artboardSize = artboardRect[2] - artboardRect[0];
var exportOpts = new ExportOptionsPNG24();
exportOpts.antiAliasing = true;
exportOpts.artBoardClipping = true;
exportOpts.saveAsHTML = false;
exportOpts.transparency = true;
exportOpts.horizontalScale = 100.0/artboardSize*targetSize;
exportOpts.verticalScale = 100.0/artboardSize*targetSize;
sourceDoc.exportFile(targetFile, ExportType.PNG24, exportOpts);
} }
} }
function exportSVGFile(targetType, sourceDoc, targetFileBase) {
// This code is not good
// See https://graphicdesign.stackexchange.com/questions/39505/illustrator-exporting-svg-viewbox-doesnt-match-artboard-size
var targetFileExt = 'svg';
var targetFolder = targetBasePath + '/' + targetType + '_' + targetFileExt;
new Folder(targetFolder).create();
var targetFullFilename = targetFolder + '/' + targetFileBase + '.' + targetFileExt;
var targetFile = new File(targetFullFilename);
var exportOpts = new ExportOptionsSVG();
exportOpts.preserveEditability = true;
exportOpts.embedAllFonts = true;
exportOpts.embedRasterImages = true;
exportOpts.fontType = SVGFontType.SVGFONT;
exportOpts.fontSubsetting = SVGFontSubsetting.GLYPHSUSED;
exportOpts.documentEncoding = SVGDocumentEncoding.UTF8;
sourceDoc.exportFile(targetFile, ExportType.SVG, exportOpts);
}
function exportPDFFile(sourceDoc, targetFileBase) {
var targetFileExt = 'pdf';
var targetFolder = targetBasePath + '/' + targetFileExt;
new Folder(targetFolder).create();
var targetFullFilename = targetFolder + '/' + targetFileBase + '.' + targetFileExt;
var targetFile = new File(targetFullFilename);
var exportOpts = new PDFSaveOptions();
exportOpts.preserveEditability = true;
exportOpts.compatibility = PDFCompatibility.ACROBAT8;
var flattenerOpts = new PrintFlattenerOptions();
flattenerOpts.clipComplexRegions = true;
flattenerOpts.convertTextToOutlines = true;
exportOpts.flattenerOptions = flattenerOpts;
sourceDoc.saveAs(targetFile, exportOpts);
}
function hideLayer(layerName, sourceDoc) { function hideLayer(layerName, sourceDoc) {
sourceDoc.layers.getByName(layerName).visible = false; sourceDoc.layers.getByName(layerName).visible = false;
} }
@ -80,18 +130,3 @@ function hideLayer(layerName, sourceDoc) {
function showLayer(layerName, sourceDoc) { function showLayer(layerName, sourceDoc) {
sourceDoc.layers.getByName(layerName).visible = true; sourceDoc.layers.getByName(layerName).visible = true;
} }
function getPNGOptions(size, sourceDoc) {
var artboardRect = sourceDoc.artboards[sourceDoc.artboards.getActiveArtboardIndex()].artboardRect;
var artboardSize = artboardRect[2] - artboardRect[0];
var pngExportOpts = new ExportOptionsPNG24();
pngExportOpts.antiAliasing = true;
pngExportOpts.artBoardClipping = true;
// pngExportOpts.matte = true;
// pngExportOpts.matteColor = 0, 0, 0;
pngExportOpts.saveAsHTML = false;
pngExportOpts.transparency = true;
pngExportOpts.horizontalScale = 100.0/artboardSize*size;
pngExportOpts.verticalScale = 100.0/artboardSize*size;
return pngExportOpts;
}