Photoshop: get slices via SDK and copy content - api

I want to copy the content of the current seleced slice in my photoshop cs3 document to a new document using an own written script/plugin.
Currently, I do this manually: I select the slice, press ctrl+c (copy), create a new document and then I press ctrl+v (paste).
What I have so far is the automation plugin example 'MakeNew' that creates a new document:
static SPErr MakeNewDocument (void)
{
SPErr error = kSPNoError;
PIActionDescriptor descriptor = NULL;
error = sPSActionDescriptor->Make (&descriptor);
...
}
Any Idea how I can access the current selected slice and copy the content to the new document?
Thanks for hints.

Looks like there is no way to get the slices even via SDK in CS3.

Related

Adobe breaks stamped PDF when saving as new file / what is difference in Adobe 'save as' vs. Foxit Reader 'save as' feature

I'm reaching out to larger community of developers in seek of help to understand the real cause and possibly finding a fix. I have asked questions from Aspose, and they have also tracked the issue (PDFNET-42880) in their system. I think they are not going to investigate this anytime soon as it is very specific case. And now I am posting this here to ask more details about:
What is difference in Adobe 'save as' vs. Foxit Reader 'save as' vs. Windows Reader 'save as' feature?
Issues with Adobe product that are not so obvious to figure out. I don't even know what to ask :D
Link to their (Aspose) old forum: https://www.aspose.com/community/forums/thread/845549/removing-stamps-fails-after-saving-stamped-file-from-adobe-acrobat.aspx
Case:
Created PDF with forms using OpenOffice (version 3.4.0), stamped with Aspose PDF, opened with Adobe Reader DC (or Adobe Acrobat XI), filled, saved as new file. Now this new file is fine, but when I try to remove stamps using Aspose (and replace with new stamp later), this is where things get interesting.
Files that I've tested with: https://1drv.ms/f/s!Auvpijam7a73iDzOqc6wZPuY9l81
Stamp_Location.png
OoPdfFormExample_WithStamp.pdf
OoPdfFormExample_WithStamp_StampRemoved.pdf
OoPdfFormExample_WithStamp_SavedFromFoxit.pdf
OoPdfFormExample_WithStamp_SavedFromFoxit_StampRemoved.pdf
OoPdfFormExample_WithStamp_SavedFromWindowsReader.pdf
OoPdfFormExample_WithStamp_SavedFromWindowsReader_StampRemoved.pdf
OoPdfFormExample_WithStamp_SavedFromAdobeReader.pdf
OoPdfFormExample_WithStamp_SavedFromAcrobat_StampRemoved.pdf
C# code that is used to remove the stamp(s):
/// <summary>
/// Removes stamps from PDF file.
/// </summary>
/// <param name="pdfFile"></param>
private static void RemoveStamps( string pdfFile )
{
// Create PDF content editor.
Aspose.Pdf.Facades.PdfContentEditor contentEditor = new Aspose.Pdf.Facades.PdfContentEditor();
// Open the temp file.
contentEditor.BindPdf( pdfFile );
// Process all pages.
foreach ( Page page in contentEditor.Document.Pages )
{
// Get the stamp infos.
Aspose.Pdf.Facades.StampInfo[] stampInfos = contentEditor.GetStamps( page.Number );
//Process all stamp infos
foreach ( Aspose.Pdf.Facades.StampInfo stampInfo in stampInfos )
{
// Use try catch so we can output possible error w/out break point.
try
{
contentEditor.DeleteStampById( stampInfo.StampId );
}
catch ( Exception e )
{
Console.WriteLine( e );
}
}
}
// Save changes to the temp file.
contentEditor.Save( StampRemovedPdfFile );
}
Using Adobe: The process of removing stamp works fine, but trying to open the file will end up having an issue with the file.
"An error exists on this Page. Acrobat may not display the page correctly. Please contact the person who created the PDF document to correct the problem."
EDIT: After testing more, and just opening file to Aspose, and saving it without modifications, that didn't break the file, only once the stamp was removed with Aspose method it was broken.
Using Foxit: Only difference in the process is that opening the file to Foxit Reader and save form there. The stamp is removed and file is fine, works with any PDF reader.
Using Windows (10) Reader: Only difference in the process is that opening the file to Windows Reader and save from there. The stamp is removed and file is fine, works with any PDF reader.
Ok - The thing you are referring to is not a stamp annotation. It's an XObject that gets drawn into the page content. Why Aspose refers to it as a Stamp is... well... a mystery. When you remove the "stamp" (not a stamp) Aspose seems to be removing the XObject but not the instructions to draw it from the page Contents stream... that's why you're getting the error in Acrobat. The other applications are more permissive with bad PDF and my guess is when they write out the file, they are removing references to non-existent objects. You can make Acrobat attempt to fix problems like this by selecting Save As Optimized PDF. However, you are far better off removing the drawing instruction in addition to the XObject.
Because of the way you've created the file and added the "stamp", your page content stream is an array of streams. Remove the last item in the array, which is the instruction to draw the XObject, and you file will work without errors in all the viewers. Note: It won't always be the case that the last item in the content array will be your stamp. It's just that your stamp is the last thing to get drawn so it goes at the end.
If your intention is to "replace" the "stamp", you'll want to do so by removing the XObject as you are doing now, then remove the instruction, then add the new "stamp".

Automatic download of created file in Sencha Touch 2

My Sencha Touch 2 application has an 'Export' button, which creates an Excel file with the data of the selected offer.
After the user clicks the button, i want the (server side) export process to be started, and, once completed, the user to be prompted to select a filename and location, OR that the file is automatically downloaded. How do i do that? Does anyone have an example?
For Excel specifically I'm not 100% sure, but this might help you get started or if a CSV is acceptable...
I'm sure you could pass the file reference to a var instead of the string but I have yet to try it.
If you paste the js below into the console you can see how this works. Pretty basic. Maybe try the returned value from the server to see if that works then if it does you can build a function around it to happen when needed.
csvHeading = 'HA, HB, HC, HD \n';
csvData = 'r3a, r3b, r3c, r3d \n' +
'r2a, r2b, r2c, r2d';
CSVFile = csvHeading + csvData;
window.location = 'data:text/csv;charset=utf8,' + encodeURIComponent(CSVFile);

Creating a custom map with MapBox and TileMill from SQL 2005

I have a requirement to build a web application with geo-mapping that will display pins on a map and the data comes from my sql 2005 database. This intranet application will be hosted on our secure server and will not have access to any outside resources and cannot use any external api's.
After searching on the internet, I found that I can use leaflet.js and mapbox to handle this although I have to move all of the files locally. I also need to create a custom map with TileMill and then copy the tiles to my applications. I tried to create my custom map but I cannot create any layers because it is asking for a datasource to a csv file or sqllite and I need to pass the data from my sql 2005 database. Is it possible to create a custom map with tilemill and provide my own datasource? Am I going about this the right way? Is there a better way to create a geo-mapping application that has to be accessed locally?
Thanks
Rob, I am sure there is a better way to do this but this is the way I implemented it.
The solution I am about to give you should allow you to add markers to a Mapbox map (search "omnivore mapbox" for web application CSV import equivalent of TileMill add data source feature) that can be accessed through your web application and that gets its data from a CSV file generated from a GridView connected to a MS SQL database.
I had at the same problem, data is in SQL 2008 and I need to use it to create a map.
Mapbox required CSV or POSTGRESQL to display pins but I did not have a POSTGRESQL server setup anywhere.
Here is what I did:
(note that I am using C# and creating a ASP NET web application)
Create an empty ASPX page, let's call it DataGridView.aspx
Add a GridView
Link that GridView to your SQL data source
Create a button, call it "Refresh CSV"
Double click on it to automatically create an event for that button.
In the code for the event for that button, use this piece of code:
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.AllowPaging = false;
GridView1.DataBind();
StringBuilder sb = new StringBuilder();
for (int k = 0; k < GridView1.Columns.Count; k++)
{
if(k==0) // little trick to avoid comma at the end of the line
{
sb.Append(GridView1.Columns[k].HeaderText);
continue;
}
//add separator
sb.Append(',' + GridView1.Columns[k].HeaderText);
}
//append new line
sb.Append("\r\n");
for (int i = 0; i < GridView1.Rows.Count; i++)
{
for (int k = 0; k < GridView1.Columns.Count ; k++)
{
if (k == 0) // little trick to avoid comma at the end of the line
{
sb.Append(GridView1.Rows[i].Cells[k].Text);
continue;
}
//add separator
sb.Append(','+GridView1.Rows[i].Cells[k].Text );
}
//append new line
sb.Append("\r\n");
}
string a= string.Empty;
StreamWriter yourStream = File.CreateText(Server.MapPath("~/CSVExport.csv"));
a = sb.ToString()+"\r\n"; //formatting text based on poeition
yourStream.Write(a);
yourStream.Close();
}
Don't forget to have these at the beginning of your DataGridView.aspx.cs file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;
On the root of your web application, create an empty file, name it "CSVExport.csv".
This is going to hold your GridView Data formatted as a CSV.
Now every time you click that button, it should update your CSVExport.csv file.
To check if everything displays correctly, launch TileMill and run (debug run locally) your website.
Go to [localhost:whateverthatportnumberis]/DataGridView.aspx
Click on the button.
Open CSVExport.csv to check if your file has been updated (you should see your data in CSV file format.)
Now, without stopping your local website test, go ahead and use the link to the CSV file in TileMill
[localhost:whateverthatportnumberis]/CSVExport.csv
If your CSVExport.csv file is formatted correctly, you should see the markers being displayed.
This should answer your question on how to get your data from SQL to a CSV format that can be used by Mapbox.
Your question becomes ambiguous here when you say: " Is there a better way to create a geo-mapping application that has to be accessed locally?". So I am going to stop here.
Again, the solution I just gave you should allow you to add markers to a Mapbox map (search "omnivore mapbox" for web application CSV import equivalent of TileMill add data source feature) that can be accessed through your web application and that gets its data from a CSV file generated from a GridView connected to a MS SQL database.
One way is to create your custom map in TileMill, without the data in your SQL 2005 database, and to export it as a mbtiles file which you can afterwards host on mapbox.
Use this map as the baselayer in leaflet.js, and add your markers dynamically loaded via AJAX from a REST API accessing your SQL database.

File download control - delete file without validation?

Hello XPages programmers.
I work on a simple XPages File Library.
To achieve that i use FileUpload control with FileDownload control.
When i create a new file, i enter its name, and select a file.
I set that uploading a file won't activate a validation, so i can attach a file without a specified name. Additionally i set it to do fullrefresh, so uploading a file takes place in an instant and a file is visible in FileDownload control.
Problem occurs, when i want to delete that attachment using garbage icon of FileDownload - i can't set it to run without walidation.
Is there any workaround avaiable?
Any help will be appreciated.
I used the workaround Mark Leusink suggested - created a simmilar button (used image from filedownload control) and then set it for full refresh with process data without validation property.
Code in JSSS
function deleteAttachments()
{
var attList = dDocument.getAttachmentList("Document_Attachment");
for(var i=0; i<attList.size(); i++)
{
var att:String = attList[i];
dDocument.removeAttachment("Document_Attachment", att.getName() );
}
}
Surely it can be used for delete a specific attachment by getting attachment name from rowdata in a repeater and use DATASOURCE.removeAttachment method.
Thanks for your support!

How to link a PDF Document to a Record using Visual Studio LightSwitch 2011?

I'm Stuck the following problem: How can I link a PDF Document to a Record in a Data Grid using Visual Studio LightSwitch 2011 and Visual Basic?
Any help would be awesome, thanks!
Here's the simplest way to do this: add a custom command to the Command Bar of the Data Grid Row for your Data Grid. In this example I'm calling the command Open PDF File. Then add this code to Execute code for the command:
partial void OpenPDFFile_Execute()
{
const string LOCAL_SERVER_PDF_DIR = #"\\MyServer\PDFs\";
const string WEB_SERVER_PDF_DIR = "http://myweb.server/PDFs/";
const string PDF_SUFFIX = ".pdf"; //assumes you do not include the extension in the db field value
if (AutomationFactory.IsAvailable)
{
//if the AutomationFactory is available, this is a desktop deployment
//use the shell to open a PDF file from the local network
dynamic shell = AutomationFactory.CreateObject("Shell.Application");
string filePath = LOCAL_SERVER_PDF_DIR + this.PDFFiles.SelectedItem.FileName + PDF_SUFFIX;
shell.ShellExecute(filePath);
}
else
{
//otherwise this must be a web deployment
//in order to make this work you must add a reference to System.Windows.Browser
//to the Client project of your LS solution
var uri = new Uri(WEB_SERVER_PDF_DIR + this.PDFFiles.SelectedItem.FileName + PDF_SUFFIX);
HtmlPage.Window.Navigate(uri, "_blank");
}
}
You will need to add the following imports to the top of your user code file to make this code compile:
using System.Runtime.InteropServices.Automation;
using System.Windows.Browser;
I should mention that you need a directory to server the PDFs up from. This example is flexible with respect to deployment, because it handles both desktop and web configurations. Since you'll need to set up the PDF directoy, you may want to just handle one configuration option to simply things (or you could expose the same PDF directory over http and as a local network share).
You may also want to present this as a true link instead of a button. In order to do this, you'll need a custom SilverLight control. In any case, I would recommend implementing the PDF link using a button first. You can then move this same code to a link event handler as a separate project if that is worth spending time on.