ABCpdf unicode character as? - abcpdf

I am using ABCPDF version 9.1.2.5
our process for creating PDF is like navigate URL in the background and get the full HTML as a string we are using AddImageHtml() method for creating a PDF, that would work perfectly with the English language but not works for another language like Chinese Japanese which is represented as a "?" mark
Dim PDFData() As Byte = Nothing
Dim HtmlPage As String
Dim PDFDoc As New Doc
PDFDoc.Font = PDFDoc.EmbedFont("Arial Unicode MS", LanguageType.Unicode, False, True)
HtmlPage = myclass.GetWebPageAsString(TargetURL, PostData)
If Orientation = Myclass.PDFOrientation.Landscape Then
Width = PDFDoc.MediaBox.Width
Height = PDFDoc.MediaBox.Height
Left = PDFDoc.MediaBox.Left
Bottom = PDFDoc.MediaBox.Bottom
PDFDoc.Transform.Rotate(90, Left, Bottom)
PDFDoc.Transform.Translate(Width, 0)
PDFDoc.Rect.Width = Height
PDFDoc.Rect.Height = Width
End If
PDFDoc.Rect.Inset(20, 20)
PDFDoc.HtmlOptions.Timeout = 3600000
PDFDocID = PDFDoc.AddImageHtml(HtmlPage)
PDFData = PDFDoc.GetData
PDFDoc.Clear()

The version of ABCpdf that you are using was discontinued early in 2015. The rendering of CJK characters for the default engine you are using is dependent on the version of Internet Explorer installed on the machine where you are running your application. From version 11, it is now possible to use the Chrome engine which is much less dependent on your operating system configuration. It is also faster and very much more standards compliant.

Related

Create a 1D barcode and return asd base64 string in .NET6 where it works on all platforms

I need to take a ticket id (only digits, but as a string), turn the string into a 1D barcode, then convert that to a image or bitmap or svg, then convert that into a base64 encoded string, where the base64 string can be returned as a response in a endpoint. It has be done in .NET6 and I'm doing it on a Mac (MacOS)
This is what I have so far (just put it in a console app for testing purposes):
using System.Drawing;
using BarcodeLib;
byte[] ImageToByteArray(Image image)
{
MemoryStream ms = new MemoryStream();
image.Save(ms,image.RawFormat);
return ms.ToArray();
}
var ticketId = "038000356216";
Barcode b = new Barcode();
Image img = b.Encode(TYPE.UPCA, ticketId, Color.Black, Color.White, 290, 120);
var barcodeAsString = Convert.ToBase64String(ImageToByteArray(img));
Console.WriteLine(barcodeAsString);
This does work because the Barcodelib uses Windows specific API's, which then causes a exception on the Mac. This code would properly work on a Windows machine. But since I'm on a Mac this is the the issue that I would like your help with.
How can I do this in a "platform neutral" way - something that will work on both MacOS and Windows?
I'm open for using any open source library/Nuget package that supports this - just as long as I don't have to pay for it, or there is going to be a waterwark on the image.
I have tried several libraries / Nuget packages - all with the same result as in the example.

Shell_NotifyIcon NIF_INFO not showing icons

Im having issues with balloons firstly they refused to show at all but having found this thread:
Why aren't Shell_NotifyIcon balloon tips working?
then changing cbSize to 504 the balloons show but without icons in them, all the standard icons won't show nor will a custom icon, structure looks like this:
cbSize = 504
hWnd = HDL
uID = 10
uFlags = NIF_INFO
szInfo = sBody
uTimeout = 20000
szInfoTitle = sTitle
dwInfoFlags = NIIF_ERROR
does anyone know of a reason why the icons will fail? (Have tried all the structure sizes and uVersion in the various combinations)
Edit:
S.cbSize = 504;
S.hWnd = HDL;
S.uID = 101;
S.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP;
S.uCallbackMessage = 0x4DE;
S.hIcon = iHDL;
S.szTip = sTooltip;
S.uVersion = 3;
S.dwInfoFlags = NIIF_NONE;
Shell32.Shell_NotifyIconA(NIM_ADD,S:GetPointer())
Shell32.Shell_NotifyIconA(NIM_SETVERSION,S:GetPointer())
That's used to create the tray icon and it does:
All the callback messages work with the change tooltip/change icon/set focus/delete tray icon functions also working as expected on XP and Win 8.1 all using cbSize = 504 and uVersion = 3 with Ansi NIM_SETVERSION and NOTIFYICONDATA, balloons will show its just no icons will show not even the default ones:
S.cbSize = 504;
S.hWnd = HDL
S.uID = 101
S.uFlags = NIF_INFO
S.szInfo = sBody
S.uTimeout = 20000
S.szInfoTitle = sTitle
S.dwInfoFlags = NIIF_ERROR
Shell32.Shell_NotifyIconA(NIM_MODIFY,S:GetPointer())
Using size of structure for cbSize works for everything but balloons, they wont even show, and that size reports as 688.
cbSize=504 is only meaningful if you are using the Ansi versions of Shell_NotifyIcon() and NOTIFYICONDATA, are using the XP (v3) version of NOTIFYICONDATA, and your compiler's alignment settings are actually aligning the NOTIFYICONDATA fields correctly so the XP fields line up to exactly 504 bytes. Without seeing your actual code, your compiler settings, or any context information at all, there is no way to troubleshoot your problem further.

Arabic font in Web UI and itextsharp

I'm not able to find a reason why my MVC 3 web site shows arabic font correctly and my pdf not.
I use a bliss font in my web site;
#font-face {
font-family: 'blissregular';
src: url('/Fonts/blissregular-webfont.eot');
src: url('/Fonts/blissregular-webfont.eot?#iefix') format('embedded-opentype'),
url('/Fonts/blissregular-webfont.ttf') format('truetype');
font-weight: normal;
font-style: normal;}
All working fine.
After that I want to create the pdf of the output but arabic fonts does not appears.
I've googled and understand that the font must have the arabic character to show up correctly. I've changed to arial font (that contains arabic character) and... pdf worked.
So... How is possible that with bliss font (that does NOT have arabic characters) I see arabic font in web site?
I'm really confused....
thanks a lot to everybody!
For every character your browser encounters it looks for a matching glyph in the current font. If the font doesn't have that glyph it looks for any fallback fonts to see if they have that glyph. Ultimately every browser has a core set of default fonts that are the ultimate fallback. When you specify the font Bliss but use Arabic characters you are probably just seeing your browser's fallback fonts.
PDFs don't work that way. If you say something is using font XYZ then it will try to render it using that font or fail.
The easiest way probably is to just add a font to your CSS that supports those characters.
.myclass{font-family: blissregular, Arial}
If that doesn't work you might need to inject the fonts manually. (Actually, I'm not 100% certain the iText support #font-face, either.) iText has a helper class that can figure things out for you that Bruno talks about it here but unfortunately the C# link isn't working anymore. It's very simple, you just create an instance of the FontSelector class, call AddFont in the order that you want characters to be looked up up in and then pass a string to the Process() method which spits back a Phrase that you can add. Below is basic sample code that shows this off. I apologize for my sample text, I'm English-native so I just searched for something to use, I hope I didn't mangle it or get it backwards.
You'll need to jump through a couple of extra hoops when processing the HTML but you should be able to work it out, hopefully.
//Sample string. I apologize, this is from a Google search so I hope it isn't backward
var testString = "يوم الاثنين \"monday\" in Arabic";
var outputFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Test.pdf");
//Standard PDF setup
using (var fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write, FileShare.None)) {
using (var doc = new Document()) {
using (var writer = PdfWriter.GetInstance(doc, fs)) {
doc.Open();
//This is a font that I know *does not* support Arabic characters, substitute with your own font if you don't have it
var gishaFontPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "gisha.ttf");
var gishaBaseFont = BaseFont.CreateFont(gishaFontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
var gishaFont = new iTextSharp.text.Font(gishaBaseFont, 20);
//Add our test string using just a normal font, this *will not* display the Arabic characters
doc.Add(new Phrase(testString, gishaFont));
//This is a font that I know *does* support Arabic characters
var arialFontPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");
var arialBaseFont = BaseFont.CreateFont(arialFontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
var arialFont = new iTextSharp.text.Font(arialBaseFont, 20);
//Create our font selector specifying our most specific font first
var Sel = new FontSelector();
Sel.AddFont(gishaFont);
Sel.AddFont(arialFont);
//Have the font selector process our text into a series of chunks wrapped in a phrase
var newPhrase = Sel.Process(testString);
//Add the phrase, this will display both characters
doc.Add(newPhrase);
//Clean up
doc.Close();
}
}
}

Photoshop javascript save error 8800

In my javascript, in Windows 7, Photoshop CS2 & Photoshop CS5, it throws an error:
Error 8800: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.
- Could not save a copy as "C:...\wcb-010B-11Y.jpg" because the file could not be found.
Line: 458
-> docRef.saveAs( saveFile, jpgSaveOptions, true, Extension.LOWERCASE );
here is a summary of the code to save the image:
var selectedSaveDir = "~/Desktop/";
var sFileNamePreFix = "wcb-";
var docRef = app.activeDocument;
var docName = app.activeDocument.name;
var docNewName = docName.substr( 0, docName.length - 4 ); // strip file extension
var sNewDocName = sFileNamePreFix + docNewName + ".jpg"
var sNewFileName = selectedSaveDir + sNewDocName;
//alert( "sNewFileName = " + sNewFileName ); // test to verify correct location
var saveFile = new File(sNewFileName);
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.quality = 12;
docRef.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
In Windows XP, this script works very well in CS2 with no problems.... just in Windows 7 is where this issue occurs using CS2 or CS5.
The problem seems to be similar to : Photoshop Javascript scripting saving and closing document
But I don't know his OS.
I've added the "alert(" and confirmed the save folder & name is correct and can be saved to, but same issue.
Could it be a UAC issue in Windows 7 ? and how do you Fix it ? I've turned off all UAC settings (I think I did it correctly), but it still occurs.
Any Help ?
You missed out " var docRef = app.activeDocument;" (which i've added); but apart from that, in CS2 the script saves out a jpeg to the desktop (wcb-text test.jpg). It's obvious, but have you made sure the image is flattened or doesn't contain any information that cannot be stored in a jpeg - like paths for example.
Try forcing a flatten before saving
//flatten the image
docRef.flatten();
Another thing to try is to save out the file to another directory. I know that long file names (especially with spaces in) can cause problems - I think there's a limit to 300 characters in the file path.
I just found that, in new versions of PS this particular path variable gives the error 8800:
var selectedSaveDir = "~/Desktop/";
Use full path instead and use apostrophes instead of quotes:
var selectedSaveDir = 'C:/Users/yourname/Desktop/';

Image Misalignment in Visual Studio application

I have a Visual Studio application with a splash screen image cut into "slices". The positions are specified in the Form Designer so they line up properly on the screen. However, the images are out of place when the application is run on the Chinese version of Windows XP. It looks as if the image slices were "exploded" apart.
What's going on here? Do international versions of Windows have a different meaning of the "top left" coordinate of the picture? How can I force the images to be precisely displayed where I want them?
We found a solution! Apparently the picture boxes stretched out on the Chinese XP PC, but the images they contained did not. The fix was to add code like the following:
Me.PictureBoxIcon.Width = Me.PictureBoxIcon.Image.Width
Me.PictureBoxIcon.Height = Me.PictureBoxIcon.Image.Height
Dim loc As New Point
loc.X = Me.PictureBoxIcon.Location.X
loc.Y = Me.PictureBoxIcon.Location.Y + Me.PictureBoxIcon.Height
Me.PictureBoxAbout.Location = loc
Me.PictureBoxAbout.Width = Me.PictureBoxAbout.Image.Width
Me.PictureBoxAbout.Height = Me.PictureBoxAbout.Image.Height
Hope this helps someone else!
In the OnLoad event of the form, you could always explicitly set the location of each section. If starting at the top left with the first and assuming an array with the images in order:
images[0].Location = new Point(0,0);
for (int i = 1; i < images.Length; i++)
{
images[i].Location = new Point(images[i - 1].Location.X + images[i - 1].Width, 0);
}
That will set the first image to the top left corner and all subsequent images to just after the last image.

Resources