Autor Beitrag
DeTomaso33
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 52
Erhaltene Danke: 1

Windows10
C#,HTML,CSS3,Javascript
BeitragVerfasst: Mo 19.10.15 13:53 
Hi Profis,

ich brauche mal tatkräftige Unterstützung. Meine Aufgabe gestaltet sich wie folgt: Aus einem Code,der jeweils für ein ZPL-Etikett (Zebra Programming Language)mit Barcode und Anschrift erzeugt wird, soll eine .pdf Datei erzeugt werden. Ich brauche den Schritt Code zu pdf.Ich habe bisher fürs Dateieinlesen den Streamreader oder den XML-Reader verwendet bei anderen Aufgaben. Was verwende ich hier am besten? Wo bekomme ich den Algorithmus für die Kompremierung zum pdf her? Ich habe bisher nur ein halbes Jahr Programmiererfahrung und habe bei so einer Anforderung noch keine Erfahrung. Wer kann mir helfen? Bedanke mich im Voraus für die Zusendung von Tipps!

mfg DeTomaso33 :)


Moderiert von user profile iconChristian S.: Topic aus C# & .NET Tutorials verschoben am Mo 19.10.2015 um 13:59
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 19.10.15 15:37 
Hallo und :welcome:

dafür kannst du z.B. den Online-Service Labelary ZPL Web Service nutzen.
Empfohlen z.B. auch von
Print preview ZPL II commands using .NET WinForm before sending it to Zebra printer
Converting ZPL print stream into a PDF file

Interessant ist auch noch die PrintServer-Funktionalität (falls vorhanden) von Zebradruckern: How to Preview a ZPL Label with a Network Printer

Für diesen Beitrag haben gedankt: DeTomaso33
DeTomaso33 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 52
Erhaltene Danke: 1

Windows10
C#,HTML,CSS3,Javascript
BeitragVerfasst: Mo 19.10.15 15:59 
Hi,

habe das Ganze auf die Kette gekriegt und Datei wird erzeugt. Die nötigen using-Directiven (using System.IO;using System.Drawing; using System.Net; using System.Net.Sockets;) habe ich noch hinzugefügt....jetzt sieht das so aus für das Musteretikett...
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
static void Main(string[] args)
{
            string test = "^XA" +

                                "^FX Top section with company logo, name and address." +
                                "^CF0,60" +
                                "^FO50,50^GB100,100,100^FS" +
                                "^FO75,75^FR^GB100,100,100^FS" +
                                "^FO88,88^GB50,50,50^FS" +
                                "^FO220,50^FDInternational Shipping, Inc.^FS" +
                                "^CF0,40" +
                                "^FO220,100^FD1000 Shipping Lane^FS" +
                                "^FO220,135^FDOktanville TN 38102^FS" +
                                "^FO220,170^FDUnited States (USA)^FS" +
                                "^FO50,250^GB700,1,3^FS" +
                                "" +
                                "^FX Second section with recipient address and permit information." +
                                "^CFA,30" +
                                "^FO50,300^FDThomas Müller^FS" +
                                "^FO50,340^FD29 Am Stacchus^FS" +
                                "^FO50,380^FDMünchen TN 89021^FS" +
                                "^FO50,420^FDGermany (Ger)^FS" +
                                "^CFA,15" +
                                "^FO600,300^GB150,150,3^FS" +
                                "^FO638,340^FDPermit^FS" +
                                "^FO638,390^FD123456^FS" +
                                "^FO50,500^GB700,1,3^FS" +
                                "" +
                                "^FX Third section with barcode." +
                                "^BY5,2,270" +
                                "^FO175,550^BC^FD1234567890^FS" +
                                "" +
                                "^FX Fourth section (the two boxes on the bottom)." +
                                "^FO50,900^GB700,250,3^FS" +
                                "^FO400,900^GB1,250,3^FS" +
                                "^CF0,40" +
                                "^FO100,960^FDShipping Ctr. X34B-1^FS" +
                                "^FO100,1010^FDREF1 F00B47^FS" +
                                "^FO100,1060^FDREF2 BL4H8^FS" +
                                "^CF0,190" +
                                "^FO485,965^FDCA^FS" +
                                "" +
                                "^XZ";

            byte[] zpl = Encoding.UTF8.GetBytes(test);

            // adjust print density (8dpmm), label width (4 inches), label height (6 inches), and label index (0) as necessary
            var request = (HttpWebRequest)WebRequest.Create("http://api.labelary.com/v1/printers/8dpmm/labels/4x6/0/");
            request.Method = "POST";
            request.Accept = "application/pdf"// omit this line to get PNG images back
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = zpl.Length;

            var requestStream = request.GetRequestStream();
            requestStream.Write(zpl, 0, zpl.Length);
            requestStream.Close();

            try
            {
                var response = (HttpWebResponse)request.GetResponse();
                var responseStream = response.GetResponseStream();
                var fileStream = File.Create(@"C:\Users\XXX\Documents\labelone.pdf"); // change file name for PNG images
                responseStream.CopyTo(fileStream);
                responseStream.Close();
                fileStream.Close();
            }
            catch (WebException e)
            {
                Console.WriteLine("Error: {0}", e.Status);
            }         
        }


Moderiert von user profile iconChristian S.: C#-Tags hinzugefügt
Moderiert von user profile iconTh69: Full-Quotes entfernt.