In Visual C++, using DDE to communicate with Adobe Acrobat - pdf

I'm using Visual C++ 2005. I would like to use DDE to communicate with Adobe Acrobat, but I'm getting DDE connection failed.
Here's what I have so far:
HINSTANCE hRet;
/*Start the DDE server*/
hRet = ShellExecute(0, "open", "test.pdf", 0, 0, SW_SHOWNORMAL);
ASSERT((int)hRet >= 33);
/*Connect to server*/
HSZ hszApp, hszTopic;
char szApp[] = "acroview";
char szTopic[] = "control";
hszApp = DdeCreateStringHandle(dwIdInst, szApp, 0);
hszTopic = DdeCreateStringHandle(dwIdInst, szTopic, 0);
hConv = DdeConnect(dwIdInst, hszApp, hszTopic, NULL);
Adobe opens the pdf file fine, but when I call DdeConnect, it return NULL for hConv, telling "DDE Connection failed." Am I missing something?

Related

Blazor WASM PDF Generation with iTextSharp

I want to generate a PDF Document in Blazor WASM. I found examples with iTexSharp, so I did a small example.
Now I have two problems:
I have trouble with the image path to add an image in the pdf:
`Image img = Image.GetInstance("images/test.png");
How need I set the image reference to my "wwwroot/images" folder?
I get some error when I want to close my document with the command "document.Close()"
The error is:
System.Security.Cryptography.Algorithms is not supported on this
platform.
System.PlatformNotSupportedException: System.Security.Cryptography.Algorithms is not supported on this platform.
at System.Security.Cryptography.MD5.Create()
at iTextSharp.text.pdf.PdfEncryption.CreateDocumentId()
at iTextSharp.text.pdf.PdfWriter.Close()
at iTextSharp.text.pdf.PdfDocument.Close()
at iTextSharp.text.Document.Close()
Here is the whole code:
_document = new Document(PageSize.A4, 10f, 10f, 20f, 30f);
_pdfPTable.WidthPercentage = 50;
_pdfPTable.HorizontalAlignment = Element.ALIGN_LEFT;
_fontStyle = FontFactory.GetFont("Tahoma", 8f, 1);
PdfWriter.GetInstance(_document, _memoryStream);
_document.Open();
float[] sizes = new float[_maxColumn];
for (int i = 0; i < _maxColumn; i++)
{
if (i == 0) sizes[i] = 50;
else sizes[i] = 100;
}
_pdfPTable.SetWidths(sizes);
this.ReportHeader();
this.ReporBody();
_pdfPTable.HeaderRows = 2;
_document.Add(_pdfPTable);
_document.Close();
return _memoryStream.ToArray();
I have the same problem as you. What I found out is that because of WebAssembly sandbox constraint it will not be able to run itextsharp on the client side. That is why you are getting an error at the .close()
Read more at:
https://learn.microsoft.com/en-us/dotnet/core/compatibility/cryptography/5.0/cryptography-apis-not-supported-on-blazor-webassembly
As for the problem with the image, if you have at the server side it will be able to be used. Otherwise you would need to make it an embedded resource and them stream it in.

Photoshop Script: Can't set "Save As PDF" options

I'm trying to save an Adobe Photoshop file as a PDF using extendscript. I want to set the PDF Compatibility to Acrobat 6 and encoding to zip. When I specify these settings, I am receiving errors as indicated in my script comments below. What am I doing wrong?
#target photoshop
if (documents.length > 0) {
var saveOptions = new PDFSaveOptions();
// This throws "PDFCompatibilityType is undefined"
saveOptions.PDFCompatibility = PDFCompatibilityType.PDF15; // Acrobat 6 or higher
// These throw "Undefined is not an object"
saveOptions.PDFCompatibility = PDFSaveOptions.PDFCompatibilityType.PDF15; // Acrobat 6 or higher
saveOptions.PDFCompatibility = saveOptions.PDFCompatibilityType.PDF15; // Acrobat 6 or higher
// This throws "Enumerated Value Expected"
saveOptions.PDFCompatibility = 3; // Acrobat 6 or higher
// Same problems with these settings
// saveOptions.PDFStandard = PDFStandardType.NONE;
// saveOptions.downSample = PDFResampleType.PDFBICUBIC;
// saveOptions.encoding = PDFEncodingType.PDFZIP;
// Save as PDF
var f = new File( "~/Desktop/SAVE_TEST.pdf" );
app.activeDocument.saveAs( f, saveOptions, true, Extension.LOWERCASE );
}

CreateFile2 returns access denied error in Windows 8

I have written the following lines of code to open a file under InstalledFolder directory:
Platform::String^ locationPath = Platform::String::Concat(Package::Current->InstalledLocation->Path, "\\Assets\\Logo.png");
CREATEFILE2_EXTENDED_PARAMETERS extendedParams = {0};
extendedParams.dwSize = sizeof(CREATEFILE2_EXTENDED_PARAMETERS);
extendedParams.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
extendedParams.dwFileFlags = FILE_FLAG_SEQUENTIAL_SCAN;
extendedParams.dwSecurityQosFlags = SECURITY_ANONYMOUS;
extendedParams.lpSecurityAttributes = nullptr;
extendedParams.hTemplateFile = nullptr;
Wrappers::FileHandle file(
CreateFile2(
locationPath->Data(),
GENERIC_READ,
0,
OPEN_EXISTING,
&extendedParams
)
);
DWORD e = GetLastError();
if (file.Get() == INVALID_HANDLE_VALUE)
{
throw ref new Platform::FailureException();
}
The CreateFile2 returns access denied error. Can anyone please help me out?
As suggested by JP Alioto, I have tried with WinRT File I/O as the following
create_task(StorageFile::GetFileFromApplicationUriAsync(ref new Windows::Foundation::Uri("ms-appx:///Assets/Logo.png")))
.then([=](StorageFile^ f)
{
auto p = create_task(f->OpenAsync(FileAccessMode::Read));
p.wait();
});
I still get the following error at p.wait():
An invalid parameter was passed to a function that considers invalid parameters fatal
Thanks,
You are passing 0 for dwShareMode. The documentation for CreateFile2 says that this value...
Prevents other processes from opening a file or device if they request delete, read, or write access. Exclusive access to a file or directory is only granted if the application has write access to the file.
You do not have write access to files within the package, which is why you get the access denied error. You need to set the share mode to FILE_SHARE_READ.

Uploading to an FTP server

I am working on a tiny tiny application that just uploads a file to the FTP server. I have reviewed my code, but I am quite unable to locate the problem. Here is the code,
#include "stdafx.h"
using namespace System;
#include "iostream"
#include <conio.h>
using namespace System;
void UploadFiles(String ^_FileName, String ^_UploadPath, String ^_FTPUser, String ^_FTPPass);
int main ()
{
// Upload file using FTP
UploadFiles("c:\\test.html", "ftp://playbabe.tk/public_html/test.html", "xxxxxx", "xxxxxx");
return 0;
}
void UploadFiles(System::String ^_FileName, System::String ^_UploadPath, System::String ^_FTPUser, System::String ^_FTPPass)
{
System::IO::FileInfo ^_FileInfo = gcnew System::IO::FileInfo(_FileName);
// Create FtpWebRequest object from the Uri provided
System::Net::FtpWebRequest ^_FtpWebRequest = safe_cast<System::Net::FtpWebRequest^>(System::Net::FtpWebRequest::Create(gcnew Uri(_UploadPath)));
// Provide the WebPermission Credintials
_FtpWebRequest->Credentials = gcnew System::Net::NetworkCredential(_FTPUser, _FTPPass);
// By default KeepAlive is true, where the control connection is not closed
// after a command is executed.
_FtpWebRequest->KeepAlive = false;
// set timeout for 20 seconds
_FtpWebRequest->Timeout = 20000;
// Specify the command to be executed.
_FtpWebRequest->Method =System::Net::WebRequestMethods::Ftp.UploadFile;
// Specify the data transfer type.
_FtpWebRequest->UseBinary = true;
// Notify the server about the size of the uploaded file
_FtpWebRequest->ContentLength = _FileInfo->Length;
// The buffer size is set to 2kb
int buffLength = 2048;
array<System::Byte> ^buff = gcnew array<System::Byte>(buffLength);
// Opens a file stream (System.IO.FileStream) to read the file to be uploaded
System::IO::FileStream ^_FileStream = _FileInfo->OpenRead();
try
{
// Stream to which the file to be upload is written
System::IO::Stream ^_Stream = _FtpWebRequest->GetRequestStream();
// Read from the file stream 2kb at a time
int contentLen = _FileStream->Read(buff, 0, buffLength);
// Till Stream content ends
while (contentLen != 0)
{
// Write Content from the file stream to the FTP Upload Stream
_Stream->Write(buff, 0, contentLen);
contentLen = _FileStream->Read(buff, 0, buffLength);
}
// Close the file stream and the Request Stream
_Stream->Close();
delete _Stream;
_FileStream->Close();
delete _FileStream;
}
catch (Exception ^ex)
{
//MessageBox::Show(ex->Message, "Upload Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
std::cout<<"error";
}
getch();
}
It gives two errors in Visual C++ 2010 Express,
Error 1 error C2275: 'System::Net::WebRequestMethods::Ftp' : illegal use of this type as an expression C:\Users\Me\documents\visual studio 2010\Projects\test1\test1\test1.cpp 70
Error 2 error C2228: left of '.UploadFile' must have class/struct/union C:\Users\Me\documents\visual studio 2010\Projects\test1\test1\test1.cpp 70
I am not sure what is going wrong here.
I don't know C++/CLI, but the following statement is certainly wrong:
_FtpWebRequest->Method = System::Net::WebRequestMethods::Ftp.UploadFile;
System::Net::WebRequestMethods::Ftp is a type and, as the error message indicates (you could have given us the line number!) you're trying to use it as an expression.
Are you trying to obtain a pointer to a static member function?
Did you thus mean the following?
_FtpWebRequest->Method = System::Net::WebRequestMethods::Ftp::UploadFile;

c++ Convert string to bytes to send over tcp

I'm trying to send a 28 character string to a remote ip address and port. I've done this successfully in vb.net using the following code snippets:
Dim swon As String = "A55A6B0550000000FFFBDE0030C8"
Dim sendBytes As [Byte]()
sendBytes = Encoding.ASCII.GetBytes(swon)
netStream.Write(sendBytes, 0, sendBytes.Length)
I now have to convert this across to c++ and have the following so far:
char *swon = "A55A6B0550000000FFFBDE0030C8";
array<Byte>^ sendBuffer = gcnew array<Byte>(bufferSize);
sendBuffer = BitConverter::GetBytes( swon );
tcpStream->Write(sendBuffer, 0, sendBuffer->Length);
but am getting stuck at this point. I'm sure I'm missing a simple syntax error but I can't figure it out!
To clarify, I'm not getting an error, but I don't think the string is being converted to bytes correctly as when I convert back, I just get a '01'
Cheers,
Chris
I don't understand why you are not just using the exact same .Net framework classes in your ++/CLI code. eg. System::String for swon, Encoding::ASCII to produce the array of bytes.
Anything you did in VB you can map directly over to C++/CLI without using different classes - that's the easest port for you. When you are in MSDN online, just select the C++ view to get examples of stuff you want to do. Try that on this page, for example: http://msdn.microsoft.com/en-us/library/system.text.encoding.ascii.aspx
Steve is correct that the same logic can be duplicated in C++. But the C++ char* already is ASCII, no conversion is necessary. Just a copy is all that's needed.
const char swon[] = { "A55A6B0550000000FFFBDE0030C8" };
array<Byte>^ sendBuffer = gcnew array<Byte>((sizeof swon) - 1);
pin_ptr<Byte> startBuffer = &sendBuffer[0];
memcpy(startBuffer, swon, sendBuffer->Length);
tcpStream->Write(sendBuffer, 0, sendBuffer->Length);