-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44ad106
commit 8fd8fa1
Showing
6 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package pdfdoc | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/charmbracelet/lipgloss" | ||
"github.com/knipferrc/fm/strfmt" | ||
"github.com/ledongthuc/pdf" | ||
) | ||
|
||
// Model represents the properties of text. | ||
type Model struct { | ||
Content string | ||
Width int | ||
} | ||
|
||
// ReadPdf reads a PDF file given a name. | ||
func ReadPdf(name string) (string, error) { | ||
f, r, err := pdf.Open(name) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
defer f.Close() | ||
if err != nil { | ||
return "", err | ||
} | ||
var buf bytes.Buffer | ||
b, err := r.GetPlainText() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
_, err = buf.ReadFrom(b) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return buf.String(), nil | ||
} | ||
|
||
// SetSize sets the size of the pdfdoc. | ||
func (m *Model) SetSize(width int) { | ||
m.Width = width | ||
} | ||
|
||
// SetContent sets the content of the pdfdoc. | ||
func (m *Model) SetContent(content string) { | ||
m.Content = content | ||
} | ||
|
||
// GetContent returns the content of the pdfdoc. | ||
func (m Model) GetContent() string { | ||
return m.Content | ||
} | ||
|
||
// View returns a string representation of pdfdoc. | ||
func (m *Model) View() string { | ||
return lipgloss.NewStyle(). | ||
Width(m.Width). | ||
Render(strfmt.ConvertTabsToSpaces(m.Content)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters