Пример #1
0
 private VGCore.Document newDocument(VGCore.Application application)
 {
     VGCore.Document document = application.CreateDocument();
     document.Name = ++counter + "_" + Guid.NewGuid().ToString();
     document.Activate();
     document.Unit = VGCore.cdrUnit.cdrMillimeter;
     document.ActivePage.SetSize(210, 297);
     document.Rulers.VUnits = document.Rulers.HUnits = VGCore.cdrUnit.cdrMillimeter;
     createGuideLines(document);
     return(document);
 }
Пример #2
0
        private void createGuideLines(VGCore.Document document)
        {
            //Horizontal Guides
            double y = PageHeight - MarginTop;

            document.ActiveLayer.CreateGuide(0, y, PageWidth, y);
            for (int i = 0; i < 7; i++)
            {
                y -= MaxHeight / 2;
                document.ActiveLayer.CreateGuide(0, y, PageWidth, y);
            }
            //Vertical Guides
            double x = MarginLeft;

            for (int i = 0; i < 6; i++)
            {
                document.ActiveLayer.CreateGuide(x, 0, x, PageHeight);
                x += MaxWidth;
                document.ActiveLayer.CreateGuide(x, 0, x, PageHeight);
                x += MarginRight;
            }
        }
Пример #3
0
        private void generate(IProgress <object> progress)
        {
            VGCore.Application application;
            try
            {
                application = new VGCore.Application();
            }
            catch (Exception ex)
            {
                throw new Exception("CorelDRAW is not started or its version is not compatible with the software, please start CorelDRAW if not started or install compatible version");
            }
            VGCore.Document document          = null;
            double          positionX         = 0;
            double          positionY         = 0;
            List <string>   processedZipFiles = new List <string>();

            string[] zipFiles = getZipFiles(ZipsFolderPathTxt.Text);
            int      zipCount = 1;

            foreach (string zipFilePath in zipFiles)
            {
                if ((zipCount - 1) % 3 == 0)
                {
                    if (document != null)
                    {
                        saveCloseDocument(document);
                        moveZipFiles(processedZipFiles);
                    }
                    document  = newDocument(application);
                    positionX = MarginLeft;
                    //positionY = PageHeight + MaxHeight;
                    positionY = PageHeight - MarginTop + MaxHeight;
                }
                VGCore.Layer  layer      = document.ActiveLayer;
                List <string> imageFiles = getImagesFromZip(zipFilePath);

                bool isFirstImage = true;
                foreach (string imageFilePath in imageFiles)
                {
                    VGCore.Shape image;
                    try
                    {
                        image = loadResizedImage(layer, imageFilePath);
                    }
                    catch (Exception ex)
                    {
                        string message = "Failed to load file '" + Path.GetFileName(imageFilePath) + "' from zip file '" + Path.GetFileName(zipFilePath);
                        progress.Report(message + "' for template file '" + document.Name + ".cdr'" + Environment.NewLine);
                        //image = layer.CreateArtisticText(0, 0, message);
                        //image.SizeWidth = MaxWidth;
                        //image.SizeHeight = MaxHeight;
                        //image.WrapText = VGCore.cdrWrapStyle.cdrWrapSquareAboveBelow;
                        continue;
                    }
                    double x = 0;
                    double y = 0;
                    if (isFirstImage)
                    {
                        positionX = MarginLeft;
                        //positionY -= MaxHeight + MarginTop;
                        positionY -= MaxHeight;
                        if (image != null)
                        {
                            x = positionX + ((MaxWidth - image.SizeWidth) / 2);
                            y = positionY - (MaxHeight - image.SizeHeight) / 2;
                        }
                        isFirstImage = false;

                        // insert order id from zip file name into the row
                        layer.CreateArtisticText(-150, positionY - 15, Path.GetFileNameWithoutExtension(zipFilePath).Split('_')[0]
                                                 , VGCore.cdrTextLanguage.cdrLanguageNone, VGCore.cdrTextCharSet.cdrCharSetMixed
                                                 , "Arial", 30);
                    }
                    else
                    {
                        //positionX = PageWidth - MarginRight - image.SizeWidth;
                        positionX += MaxWidth + MarginRight;
                        if (image != null)
                        {
                            x = positionX + ((MaxWidth - image.SizeWidth) / 2);
                            y = positionY - (MaxHeight - image.SizeHeight) / 2;
                        }
                    }
                    if (image != null)
                    {
                        image.SetPosition(x, y);
                    }
                    // Insert text from xml file
                    Dictionary <string, string> textData;
                    bool hasValue = inputTexts.TryGetValue(Path.GetFileNameWithoutExtension(imageFilePath), out textData);
                    if (hasValue && textData != null && textData["text"] != null && textData["text"].Length > 0)
                    {
                        VGCore.Shape text = layer.CreateArtisticText(positionX, positionY - 25, textData["text"]
                                                                     , VGCore.cdrTextLanguage.cdrLanguageNone, VGCore.cdrTextCharSet.cdrCharSetMixed
                                                                     , textData["family"], 25);
                        String color = textData["color"];
                        if (color != null && color != "")
                        {
                            //.FromArgb(Convert.ToInt32(color.Replace("#", ""), 16))
                            VGCore.Color c = layer.Color;
                            c.HexValue = color;
                            text.Fill.ApplyUniformFill(c);
                        }
                    }
                }
                progress.Report(((100 - 10) / zipFiles.Length) * zipCount);
                zipCount++;
                processedZipFiles.Add(zipFilePath);
            }
            saveCloseDocument(document);
            moveZipFiles(processedZipFiles);
            application.Refresh();
            //emptyTempDirectory();
            progress.Report(100);
        }
Пример #4
0
 private void saveCloseDocument(VGCore.Document document)
 {
     document.SaveAs(CDRFilesLocationTxt.Text + "\\" + document.Name + ".cdr");
     document.Close();
 }