2

I want to print pdf directly using wifi. Some printing programs send packages as follows.

enter image description here

Actually, the important part is here. PDF bytes are sent this way. (I did not copy them all)

.........!...*b8V}2.......*b16W....```....".tt..*b7V.?......*b0W.*b7V.?......*b0
W.*b7V.?......*b0W.*b8V}2.......*b39W....~~~.........    
.&&&...................*b10V.>.........*b37W....gg..aa...a..4..9.E...aa...abb.|...*b3Vx5..*b35W....

But when I split a pdf into bytes, something different happens.

enter image description here

How can I convert PDF to bytes like these programs?

NOTE: Worked on the same pdf. NOTE2: There is no problem with the parts starting with @PJL. I'm adding those already. The main problem is they split the PDF into bytes differently. I want to know how.

Pehr Sibusiso
  • 862
  • 1
  • 14
  • 27
  • Does this answer your question? [How to print with PCL](https://stackoverflow.com/questions/42395557/how-to-print-with-pcl) – David van Driessche Aug 26 '20 at 17:23
  • Even though the article I referenced doesn't talk about Android, I do think it contains the correct information. The PCL code you have at the top of your question doesn't send a PDF file, it sends PCL data. You would have to switch the language (using ENTER LANGUAGE) to PDF if you want to send PDF binary data. – David van Driessche Aug 26 '20 at 17:25

1 Answers1

0

Convert loading file to byte array

 //Converting loaded file to Byte array 

        byte[] dataBytes = File.ReadAllBytes("loaded.pdf"); 


        //Saving individual pages as  PdfDocument 

        List<PdfDocument> seperatePDF = SeperateAsPDF(dataBytes); 

Code snippet for saving each page to list as individual PdfDocument:

 public static List<PdfDocument> SeperateAsPDF(byte[] myFile) 
    { 
        //Load document. 

        PdfLoadedDocument loadedDocument = new PdfLoadedDocument(myFile); 

        List<PdfDocument> PdfList = new List<PdfDocument>(); 

        for(int i = 0; i < loadedDocument.Pages.Count; i++) 
        { 
            PdfDocument doc = new PdfDocument(); 
            doc.ImportPageRange(loadedDocument, i, i); 
            PdfList.Add(doc); 
            
        } 
        return PdfList; 

     } 

Essential PDF also allows to split the pages of an existing PDF document into multiple individual PDF documents. The following code snippet explains the same.

 //Load document. 

        PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Output.pdf"); 

        //Sets pattern. 

        const string destFilePattern = "Output" + "{0}.pdf"; 

        //Split the pages into separate documents. 

        loadedDocument.Split(destFilePattern); 

        //close the document 

        loadedDocument.Close(true); 

Note : This code is in C#. Please inform if it works.

l_b
  • 533
  • 5
  • 10
  • I could not find how to do this in an android environment. – Pehr Sibusiso Aug 26 '20 at 15:33
  • I think that this is only possible in C#, so if you want you can try it there. – l_b Aug 26 '20 at 16:40
  • How is this relevant to the question? If you split the PDF document in one document per page, you still have the same question - how to send each PDF document to the printer. This is not an answer to the question. – David van Driessche Aug 26 '20 at 17:26