PDF Writer

coskunor

Member
Licensed User
Longtime User
Hi,
Is there a simple way to create a PDF documents with a JPEG in each page,
without any text lines.

Thank you,
Refik
 

coskunor

Member
Licensed User
Longtime User
Have a look at the PDFWriter library.
- addImage
- addImage2

Best regards.

Thank you for your reply,
i was tried but not succeded, code was like as follows;

Sub Globals
Dim PDFWriter1 As PDFWriter
Dim PaperSize As PDFPaperSizes
Dim Font As PDFStandardFonts
Dim PDFContent As String
End Sub

Sub Activity_Create(FirstTime As Boolean)

If FirstTime Then
PDFWriter1.Initialize("PDFWriter1",PaperSize.A4_WIDTH,PaperSize.A4_HEIGHT)
End If
fotodir = File.DirRootExternal & "/" & "fotodir"

End Sub

Sub Camera1_PictureTaken (data() As Byte)
camera1.StartPreview
Dim out As OutputStream


mylist = File.ListFiles(fotodir)
pname=datetime & DateTime.Time(DateTime.Now) & ".jpg"
out = File.OpenOutput(fotodir, pname, False)
out.WriteBytes(data, 0, data.Length)
out.Close

End Sub

Sub btnemail_Click
Try
mylist = File.ListFiles(fotodir)
topsay=mylist.size
lbltopsay.Text= NumberFormat(topsay,0,0)
Catch
Msgbox(LastException.Message & " fotodir Not found","btnemail_Click")
Return
End Try
If topsay > 0 Then

SMTP.Initialize(myServer,myport,myadd,mypass,"SMTP")
SMTP.UseSSL=myssl
SMTP.To.Add("[email protected]")
SMTP.Subject=fotoname & "_" & NumberFormat(topsay,0,0)
SMTP.Body="Pdf Doc.Attached..."
Dim pdfvar As Boolean
pdfvar=False
For i = 0 To topsay-1
pname=mylist.Get(i)
If pname.EndsWith(".jpg") Then
Dim bmp,smaller As Bitmap
bmp.Initialize(fotodir, pname)
smaller.Initialize3(bmp)
smaller = ResizeRotateBitmap(bmp, 768, 768)
smaller=CreateScaledBitmap(smaller, 480, 640, True)
PDFWriter1.addImage(0,0,smaller)
PDFWriter1.newPage
Msgbox(pname & "<<== loaded to PDF ...","btnemail_Click")

(after get this message number of jpg s then broke with "Unexpected result...")
pdfvar=True
End If
Next
If pdfvar Then
ProgressDialogShow (" Sending...... ")
PDFWriter1.ConverseDocument
Dim pnamey As String
pnamey=pname.Replace(".jpg","") & ".pdf"
PDFWriter1.outputToFile(fotodir,pnamey,PDFContent,"ISO-8859-1")

SMTP.AddAttachment(fotodir,pnamey)
SMTP.Send
Else
Msgbox("PDF Doc Error...","btnemail_Click")
End If
Else
Msgbox("No photos...","btnemail_Click")
End If
End If
Catch
Msgbox(LastException.Message,"btnemail_Click")
Msgbox("Error Sending Mail !...","btnemail_Click")
End Try

End Sub

Best regards,
Refik
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
This line
B4X:
PDFWriter1.addImage(0,0,smaller)
must be something like this:
B4X:
PDFWriter1.addImage(60, 800,smaller)
The positions parameters are Left and TopFromBottom, the reference is the lower left corner.
The units are typographic points.
1 point = 1/72 inch = 0.353 mm
My tests on my printer give 1 unit = 0.343 mm.
You must also add this routine:
B4X:
Sub PDFWriter1_ConversionDone (Content As String)
    PDFContent = Content
End Sub
With huge bitmaps the program crashes.

Best regards.
 
Upvote 0

coskunor

Member
Licensed User
Longtime User
This line
B4X:
PDFWriter1.addImage(0,0,smaller)
must be something like this:
B4X:
PDFWriter1.addImage(60, 800,smaller)
The positions parameters are Left and TopFromBottom, the reference is the lower left corner.
The units are typographic points.
1 point = 1/72 inch = 0.353 mm
My tests on my printer give 1 unit = 0.343 mm.
You must also add this routine:
B4X:
Sub PDFWriter1_ConversionDone (Content As String)
    PDFContent = Content
End Sub
With huge bitmaps the program crashes.

Best regards.


Thank you very much again for your interest,
I tried many alternatives of
PDFWriter1.addImage(60, 800,smaller)
even with only one bitmap into one page,
Unfortunately could not pass load message,
not created pdf document.

got follows error message;

We are sorry,
Program ... stopped Unexpectedly, Please Try Again


Best regards
Refik
 
Upvote 0

coskunor

Member
Licensed User
Longtime User
I'm afraid that your bitmaps are too big.
I had got this too.
You need to reduce the size of the bitmaps.

Best regards.

Hi,

pname=mylist.Get(i)
If pname.EndsWith(".jpg") Then
Dim bmp,smaller As Bitmap
bmp.Initialize(fotodir, pname)

smaller.Initialize3( bmp)
smaller = ResizeRotateBitmap(bmp, 768, 768)
smaller=CreateScaledBitmap(smaller, 480, 640, True)

' out = File.OpenOutput(fotodir ,pname, False)
' smaller.WriteToStream(out, 80, "JPEG")
' out.Close

if i use above 3 lines instead of creating pdf document (below 2 lines)
i got jpeg file less than 40 KB in size

PDFWriter1.addImage(0,0,smaller)
PDFWriter1.newPage
Msgbox(pname & "<<== loaded to PDF ...","btnemail_Click")


Thanks and Best regards...
Refik
 
Upvote 0
Top